Re: Tree problems...

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Nov 10 1998 - 16:21:21 MET


Hi Henk,
You forgot to build the dictionary for your class Delay.
I have instrumented your class with the necessary ClassDef and ClassImp
macros. See my installation script, and your files.
I also suggest you look at our example with Makefile in
$ROOTSYS/test/Event

Rene Brun

___________makefile_______


rootcint -f DelayCint.cxx -c Delay.h DelayLinkDef.h
g++ -o Delay -fno-rtti -fno-exceptions -fPIC -I$ROOTSYS/include \
DelayCint.cxx FillDelay.cxx Delay.cxx -L$ROOTSYS/lib \
-lNew -lBase -lCint -lClib -lCont -lFunc -lGraf -lGraf3d -lHist -lMatrix
\
-lMeta -lMinuit -lNet -lProof -lPostscript -lTree -lUnix -lZip -lg++ -lm
\
-ldl -rdynamic

___________file FillDelay.cxx____________

#include "TROOT.h"
#include "TTree.h"
#include "TFile.h"
#include "TBranch.h"
#include "Delay.h"

main (int argc, char **argv) {
   TROOT simple ("Simple", "Example");
   Int_t split = 0;
   Int_t bsize = 64000;
   Delay *delay = 0;
   TFile *hfile = new TFile ("Test.root", "RECREATE");
   TTree *tree  = new TTree ("tree", "Example");
   delay = new Delay();
   tree->Branch ("delay", "Delay", &delay, bsize, split);
   for (Int_t i=0 ; i<10 ; i++) {
      delay = new Delay();
      delay->SetPacketId(i);
      tree->Fill();
      delete delay;
   }
   hfile->Write ();
   hfile->Close ();
   return 0;
} 

____________file Delay.h__________________________


#include "TObject.h"
#include "TClonesArray.h"
#include "TH1.h"
#include "TMath.h"

#include <iostream.h>

class Delay : public TObject {

private:
   UInt_t     PacketId;        // Identifier of the packet 
   Int_t      SourceId;        // ID# of the sending testbox
   Int_t      SourcePort;      // Port from which the packet was sent
   Int_t      TargetId;        // ID# of the receiving testbox 
   Int_t      TargetPort;      // Port to which the packet was sent 
   Int_t      PacketSize;      // Packet size in bytes 
   Double_t   ArrivalTime;     // -1.0 if undefined 
   Double_t   PacketDelay;     // Delay in ms, -1.0 if undefined 
   UInt_t     SourceClock;     // Sending and receiving clock status 
   UInt_t     TargetClock;
   Int_t      Nhops;            // Number of hops, -1 if unknown
   Int_t      Routeid;          // Routing vector number, -1 if unknown 
   Float_t    SourceNtp;       // NTP error estimates (empty at the
moment) 
   Float_t    TargetNtp;

public:
   Delay ();
   virtual ~Delay();
   void       SetPacketId (Int_t n) {PacketId = n;}
   ClassDef(Delay,1)
};

__________________file Delay.cxx______________________
#include "Delay.h"

   ClassImp(Delay)
   
Delay::Delay() {
   cout << "Contructor for Delay\n";
}

Delay::~Delay() {
}

___________file DelayLinkDef.h__________________


#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ class Delay;
#endif








Henk Uijterwaal wrote:
> 
> I'm completely new to Root, so this is probably something trivial or a
> FAQ
> but...
> 
> ... I'm trying to fill a Tree using this piece of code, derived from the
> examples
> in the 2.00/13 distribution:
> 
> [oak:520] cat FillDelay.C
> #include "TROOT.h"
> #include "TTree.h"
> #include "TFile.h"
> #include "TBranch.h"
> #include "Delay.h"
> 
> main (int argc, char **argv) {
>    TROOT simple ("Simple", "Example");
>    Int_t split = 0;
>    Int_t bsize = 64000;
>    Delay *delay = 0;
>    TFile *hfile = new TFile ("Test.root", "RECREATE");
>    TTree *tree  = new TTree ("tree", "Example");
>    delay = new Delay();
>    tree->Branch ("delay", "Delay", &delay, bsize, split);
>    for (Int_t i=0 ; i<10 ; i++) {
>       delay = new Delay();
>       delay->SetPacketId(i);
>       tree->Fill();
>       delete delay;
>    }
>    hfile->Write ();
>    hfile->Close ();
>    return 0;
> }
> 
> This compiles, but then core-dumps:
> 
> [oak:524] make
> g++ -O -Wall -fPIC -I/spool/henk/source/root/include -c  FillDelay.C
> FillDelay.C: In function `int main(int, char **)':
> FillDelay.C:9: warning: unused parameter `int argc'
> FillDelay.C:9: warning: unused parameter `char ** argv'
> g++ -O -Wall -fPIC -I/spool/henk/source/root/include -c  Delay.C
> g++ -o FillDelay -g FillDelay.o Delay.o -L/spool/henk/source/root/lib
> -lNew -lBase -lCint -lClib -lCont -lFunc -lGraf -lGraf3d -lHist -lMatrix
> -lMeta -lMinuit -lNet -lProof -lPostscript -lTree -lUnix -lZip -lg++ -lm
> -ldl -rdynamic
> [oak:525] FillDelay
> Contructor for Delay
> Contructor for Delay
> Error in <TFile::TFile>: file  does not exist
> 
>  *** Break *** segmentation violation
> Abort (core dumped)
> 
> As far as I can see, the core-dump occurs in the tree->Branch statement.
> 
> Any ideas what might be wrong here?
> 
> Henk
> 
> ps. I'm running Linux 2.0.35:
> 
> [oak:526] uname -a
> Linux oak.ripe.net 2.0.35 #1 Fri Sep 4 15:13:37 MET DST 1998 i586
> unknown
> 
> Delay.h and Delay.C are:
> 
> ---- Delay.h ----
> #include "TObject.h"
> #include "TClonesArray.h"
> #include "TH1.h"
> #include "TMath.h"
> 
> #include <iostream.h>
> 
> class Delay : public TObject {
> 
> private:
>    UInt_t     PacketId;        // Identifier of the packet
>    Int_t      SourceId;        // ID# of the sending testbox
>    Int_t      SourcePort;      // Port from which the packet was sent
>    Int_t      TargetId;        // ID# of the receiving testbox
>    Int_t      TargetPort;      // Port to which the packet was sent
>    Int_t      PacketSize;      // Packet size in bytes
>    Double_t   ArrivalTime;     // -1.0 if undefined
>    Double_t   PacketDelay;     // Delay in ms, -1.0 if undefined
>    UInt_t     SourceClock;     // Sending and receiving clock status
>    UInt_t     TargetClock;
>    Int_t      Nhops;            // Number of hops, -1 if unknown
>    Int_t      Routeid;          // Routing vector number, -1 if unknown
>    Float_t    SourceNtp;       // NTP error estimates (empty at the
> moment)
>    Float_t    TargetNtp;
> 
> public:
>    Delay ();
>    virtual ~Delay();
>    void       SetPacketId (Int_t n) {PacketId = n;}
> };
> 
> ---- Delay.C ----
> #include "Delay.h"
> 
> Delay::Delay() {
>    cout << "Contructor for Delay\n";
> }
> 
> Delay::~Delay() {
> }
> 
> --
> ------------------------------------------------------------------------------
> Henk Uijterwaal                    Email: henk.uijterwaal@ripe.net
> RIPE Network Coordination Centre     WWW: http://www.ripe.net/home/henk
> Singel 258                         Phone: +31.20.535-4414,  Fax -4445
> 1016 AB Amsterdam                   Home: +31.20.4195305
> The Netherlands                   Mobile: +31.6.55861746  NOTE NEW
> NUMBER!
> ------------------------------------------------------------------------------
> 
> %DCL-E-NOCFFE, unable to locate coffee - keyboard input suspended.



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:39 MET