Hi Heather, In $ROOTSYS/test/Event.h we have an example close to what you want to do. You need a static pointer AND the real pointer. The static pointer is not sufficient (cannot be persistent). I suggest you run this Event example (main program is MainEvent.cxx). Rene Brun On Tue, 19 Jun 2001, Heather Kelly wrote: > Hi, > > I am using Root 3.00.06 on Windows NT/2000. > I am trying to update some existing Root classes to use TClonesArray rather > than TObjArray. > > There is an Event class which contains a pointer to an object (called > AcdDigi) that contains a TClonesArray. Attached are the header files for > AcdDigi and Event clases, as well as the source for AcdDigi that defines a > method called Add(TileID *). I am having some problems with the Add > routine, where I am trying to use the new with placement as is necessary > for a TClonesArray. > > I have tried to test the class by running the following macro in Root: > > { > gSystem->Load("digiRootData.dll"); > TFile *f = new TFile("digiroot.root", "RECREATE"); > TTree *t = new TTree("T", "T"); > Event *ev = new Event(); > t->Branch("EventBranch", "Event", &ev, 32000, 1); > > Int_t i; > for (i = 0; i<1; i++) { > TileID *id = new TileID(10); > ev->getACD()->Add(id); > ev->Clear(); > } > > delete ev; > f->Close(); > delete f; > } > > Here is the error message due to the ev->getACD()->Add(id) call: > root [0] .x testdigi.c > Error in <TList::AddFirst>: argument is a null pointer > > I find that if I remove the static data members in the Event class - and > explicitly create/delete AcdDigi objects with each iteration, things work > just fine. I was hoping to use static data members in the Event class to > avoid new/delete for each iteration. Is this the cause of my problem - or > a symptom? The default constructor for the Event class looks like this: > > AcdDigi *Event::m_staticAcd=0; > CalDigi *Event::m_staticCal=0; > TkrDigi *Event::m_staticTkr=0; > L1T *Event::m_staticL1T=0; > > Event::Event() { > if (!m_staticAcd) m_staticAcd = new AcdDigi(); > m_ACD = m_staticAcd; > if (!m_staticCal) m_staticCal = new CalDigi(); > m_CAL = m_staticCal; > if (!m_staticTkr) m_staticTkr = new TkrDigi(); > m_TKR = m_staticTkr; > if (!m_staticL1T) m_staticL1T = new L1T(); > m_L1Trigger = m_staticL1T; > } > > What am I doing incorrectly? > > Thanks, > Heather
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:49 MET