[ROOT] using TClonesArray

From: Heather Kelly (heather@lheapop.gsfc.nasa.gov)
Date: Tue Jun 19 2001 - 20:00:30 MEST


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




******************************************************************** Heather Maria Theresa Arrighi Kelly Goddard Space Flight Center T2 Room 59 phone (301) 286-8359 fax (301) 286-1629



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:49 MET