so I was reading up on the documentation of TClonesArray, where it refers to the implementation of Event.cxx/Event.h in the tutorials directories. And I was a bit confused of the motivation to have in the class Event and non-static TClonesArray and static TClonesArray:
TClonesArray *fTracks; //->array with all tracks
static TClonesArray *fgTracks;
where its usage is as follows:
In the ctor:
[code]Event::Event() : fIsValid(kFALSE)
// Create an Event object.
// When the constructor is invoked for the first time, the class static
// variable fgTracks is 0 and the TClonesArray fgTracks is created.
if (!fgTracks) fgTracks = new TClonesArray(“Track”, 1000);
fTracks = fgTracks;
fHighPt = new TRefArray;
fMuons = new TRefArray;
fNtrack = 0;
fH = 0;
[code]Track *Event::AddTrack(Float_t random, Float_t ptmin)
// Add a new track to the list of tracks for this event.
// To avoid calling the very time consuming operator new for each track,
// the standard but not well know C++ operator “new with placement”
// is called. If tracks[i] is 0, a new Track object will be created
// otherwise the previous Track[i] will be overwritten.
TClonesArray &tracks = *fTracks;
Track *track = new(tracks[fNtrack++]) Track(random);
//Save reference to last Track in the collection of Tracks
fLastTrack = track;
//Save reference in fHighPt if track is a high Pt track
if (track->GetPt() > ptmin) fHighPt->Add(track);
//Save reference in fMuons if track is a muon candidate
if (track->GetMass2() < 0.11) fMuons->Add(track);
Is it the case that this static fgTracks is only introduced for efficiency (avoid allocating every single Tracks)? I guess my concern here are when implementing the copy ctor or assigment operator (which wasn’t implemented at all in the example; though what if we had need of it), and when there could be threads involved? Or could we do without this fgTracks; always a sticky business when there’s a static data member in the class. If we could do without this fgTracks, how does the above code changes such that the TClonesArray makes no assumption on the max size of tracks?