Filling a tree with my own class

Dear All,

I built a class Waveform and a class Event. Both of them successfully compile and are shared libraries which I can use interactively with no errors.

One of the data members of the Event class is a pointer to an array of pointers to Waveform objects. Other members are just Double_t or Long64_t numbers.

[code]class T30Event : public TObject {

protected:
Waveform ** w;

public:
ULong_t unixtime;
[/code]

To add a Waveform object to the Event class there is a method who does the following:

Waveform* T30Event::AddWaveform(Waveform *waveform, UInt_t i){ if(!w) w = new Waveform*[6]; w[i] = waveform; return w[i]; }

It works perfectly interactively since I can use the Draw method and see the waveform that I added.

But when I try to fill a tree with an Event to which I added a Waveform I get this error:

*** Break *** segmentation violation #0 0x00206422 in __kernel_vsyscall () #1 0x04c6de53 in __waitpid_nocancel () from /lib/libc.so.6 #2 0x04c0a833 in do_system (line=<value optimized out>) at ../sysdeps/posix/system.c:149 #3 0x0017931d in system (line=0x879d6c0 "/etc/root/gdb-backtrace.sh 18668") at pt-system.c:29 #4 0x00b52e3d in TUnixSystem::Exec(char const*) () from /usr/local/lib/root/libCore.so #5 0x00b5869c in TUnixSystem::StackTrace() () from /usr/local/lib/root/libCore.so #6 0x00b599f5 in TUnixSystem::DispatchSignals(ESignals) () from /usr/local/lib/root/libCore.so #7 0x00b59afd in SigHandler(ESignals) () from /usr/local/lib/root/libCore.so #8 0x00b4fbf2 in sighandler(int) () from /usr/local/lib/root/libCore.so #9 <signal handler called> #10 0x00000000 in ?? () ....(etc. etc.)

That doesn’t happen if I fill the tree with an empty Event (or if I fill in any other data member of the Event object).

The smaller code which reproduces this is:

  gSystem->Load("libT30Event.so");

  TFile *f = new TFile("071109-19.root","RECREATE");
  TTree* tree = new TTree("071109-19","Incoming, reflected and transmitted waves measured on 071109");
  T30Event* e = new T30Event();
  TBranch* eventBranch = tree->Branch("events","T30Event", &e, 128000, 1);
  
  Double_t v[6][1000];

  for(UInt_t k=0; k<6; k++) {
    for(UInt_t j=0; j<1000; j++) {
      v[k][j]=j;
    }
  }
  
  for(UInt_t k=0; k<6; k++) {
    e->AddWaveform(v[k],1000,k);
  }

  tree->Fill();

A far as I understand there is some lost pointer or something like that but I really cannot understand where exactly the problem is.

Please help me! :cry:

Andrea
T30Event.cpp (11.5 KB)
T30Event.h (2.42 KB)
Waveform.cpp (8.38 KB)
Waveform.h (1.79 KB)

Hi,

You need to delete the I/O the length of your array:

protected: Waveform ** w; //[6] orprotected: Waveform *w[6];

Cheers,
Philippe.