Hi,
I am trying to read and write an stl vector in a tree. I find that the
writing proccess seems to work ok, but reading the vector back in works in
a rather funny way. Perhaps someone can comment and enlighten me a
little.
Specifically, I find:
(1) The branch holding the vector does appear when I do a TTree::Print().
It is not empty.
(2) The Show command looks as follows:
root [3] CalTree->Show(1);
======> EVENT:1
fEventSummary.fTrigger = 4
fEventSummary.fSnarl = 2
fEventSummary.fTimeFrame = 1
fEventSummary.fFirstTimeStamp = 4606481
fEventSummary.fLastTimeStamp = 4606503
fEventSummary.fTimeSinceLastEvent = 4053579
fEventSummary.fNHits = 18
fEventSummary.fAdcSum = 6297
fEventSummary.fPlanesHit = 5
fEventSummary.fErrorFlags = 0
fCerenkovHit.fValid = 0
fCerenkovHit.fTimeStamp = 0
fCerenkovHit.fAdc = 0
fTofHit.fValid = 0
fTofHit.fTimeStamp = 0
fTofHit.fTdc0 = 0
fTofHit.fTdc1 = 0
fTofHit.fTdc2 = 0
fCosmicSummary.fNHits = 0
fCosmicSummary.fAdcSum = 0
fTriggerPmt.fAdc = 0
fHits = printing kStreamer case (500)
Here, fHits is vector<CalHit>. CalHit is a rootified class (eg,
ClassDef(CalHit, 1), and so on).
(3) If I do tree->MakeClass("TestClass") I find that the generated class
does not have an fHits member. It is completely omitted. I attempted to
add it in by hand:
eg..
vector<CalHit> fHits;
TBranch* b_fHits;
root [0] gSystem->Load("libMapping.so");
root [1] gSystem->Load("TestClass_C.so");
root [2] TFile f("ByEvent11267.root");
WARNING, class:CalEvent StreamerInfo read from file:ByEvent11267.root
has the same version:1 than the active class
but a different checksum.
You should update the version to ClassDef(CalEvent,2).
Do not try to write objects with the current class definition,
the files will not be readable.
(4) I then had a look at the TStreamerInfo for CalEvent:
root [5] TStreamerInfo* info = (CalEvent::Class())->GetStreamerInfo(1);
root [6] info->ls();
StreamerInfo for class: CalEvent, version=1
CalEventSummaryfEventSummary offset= 0 type=62
CalCerenkovHitfCerenkovHit offset= 44 type=62
CalTofHit fTofHit offset= 60 type=62
CalCosmicSummaryfCosmicSummary offset= 84 type=62
CalTriggerPmt fTriggerPmt offset= 96 type=62
vector<CalHit,__malloc_alloc_template<0> >fHits offset=104
type=500 ,stl=1, ctype=61, ||
i= 0, fEventSummary type= 62, offset= 0, len=1, method=1091183484
i= 1, fCerenkovHit type= 62, offset= 44, len=1, method=1091183528
i= 2, fTofHit type= 62, offset= 60, len=1, method=1091183572
i= 3, fCosmicSummary type= 62, offset= 84, len=1, method=1091183616
i= 4, fTriggerPmt type= 62, offset= 96, len=1, method=1091183660
i= 5, fHits type=500, offset=104, len=1, method=1091183704
root [7]
(5) This offers the solution:
I must declare:
vector<CalHit, __malloc_alloc_template<0> > fHits;
and so on..
(6) Question 1:
I do not explicitly use __malloc_alloc_template<0> anywhere. A look at
stl_vector.h on my system shows:
template <class T, class Alloc = alloc>
class vector {...}
I gather that ROOT inserts __malloc_alloc_template<0> at some point in the
dictionary making proccess. Must it do this? I would like to use the
standard allocator if possible (SGI claims it is faster, for one thing).
If it must do this, could someone tell me why? I am curious and am having
trouble finding comprehensive documentation.
(7) Question 2:
Any clue why fHits does not appear in the generated code?
Additional Info:
Root-v3.01.06, egcs 1.1.2, Linux 2.4.6, x86
Thanks for wading through this morass!
Mike Kordosky
--
Graduate Research Assistant // High Energy Physics Lab
kordosky@hep.utexas.edu // University of Texas at Austin
kordosky@fnal.gov //
ph: (512) 471-8426 (RLM Lab, Office)
(512) 475-8673 (ENS Lab)
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:03 MET