27 |
|
fEvtObjNum(-1), |
28 |
|
fIsInit(kFALSE), |
29 |
|
fDoObjNumReset(doreset), |
30 |
+ |
fDoBranchRef(0), |
31 |
|
fFile(0), |
32 |
|
fTrees(0) |
33 |
|
{ |
41 |
|
{ |
42 |
|
// Destructor. |
43 |
|
|
44 |
< |
if (fIsInit) { |
44 |
< |
CloseFile(); |
45 |
< |
} |
46 |
< |
|
47 |
< |
TDirectory::TContext context(0); |
48 |
< |
fTrees.Clear(); |
44 |
> |
Terminate(); |
45 |
|
} |
46 |
|
|
47 |
|
//__________________________________________________________________________________________________ |
48 |
|
void TreeWriter::AddBranch(const char *name, const char *cname, |
49 |
|
void *obj, Int_t bsize, Int_t level) |
50 |
|
{ |
51 |
< |
// Add branch with name "name" into tree with name "tname" and set its address |
52 |
< |
// to object pointer for class name "cname" using a given buffer size and splitlevel. |
51 |
> |
// Add branch with name "name" into tree with name "tname" and set its address to object pointer |
52 |
> |
// for class name "cname" using a given buffer size and splitlevel. |
53 |
|
|
54 |
|
MyTree *t = AddOrGetMyTree(GetName()); |
55 |
|
TBranch *b = t->Bronch(name, cname, obj, bsize, level); |
56 |
|
b->SetCompressionLevel(GetCompressLevel()); |
57 |
|
} |
58 |
|
|
63 |
– |
|
59 |
|
//-------------------------------------------------------------------------------------------------- |
60 |
|
void TreeWriter::AddBranch(const char *name, void *obj, Int_t bsize, Int_t level) |
61 |
|
{ |
62 |
< |
// Add branch with name "name" into tree with name "tname" and set its address |
63 |
< |
// to object pointer using a given buffer size and splitlevel. |
62 |
> |
// Add branch with name "name" into tree with name "tname" and set its address to object pointer |
63 |
> |
// using a given buffer size and splitlevel. |
64 |
|
|
65 |
|
AddBranch(name, CName(obj), obj, bsize, level); |
66 |
|
} |
69 |
|
void TreeWriter::AddBranch(const char *name, const char *cname, |
70 |
|
void *obj, Int_t bsize) |
71 |
|
{ |
72 |
< |
// Add branch with name "name" into tree with name "tname" and set its address |
73 |
< |
// to object pointer for class name "cname" using a given buffer size and default splitlevel. |
72 |
> |
// Add branch with name "name" into tree with name "tname" and set its address to object pointer |
73 |
> |
// for class name "cname" using a given buffer size and default splitlevel. |
74 |
|
|
75 |
|
MyTree *t = AddOrGetMyTree(GetName()); |
76 |
|
TBranch *b = t->Bronch(name, cname, obj, bsize, fDefSL); |
173 |
|
} |
174 |
|
|
175 |
|
//-------------------------------------------------------------------------------------------------- |
176 |
+ |
void TreeWriter::AddTree(const char *tname) |
177 |
+ |
{ |
178 |
+ |
// Add tree with name "name" into tree with name "tname". |
179 |
+ |
|
180 |
+ |
AddOrGetMyTree(tname); |
181 |
+ |
} |
182 |
+ |
|
183 |
+ |
//-------------------------------------------------------------------------------------------------- |
184 |
|
MyTree *TreeWriter::AddOrGetMyTree(const char *tn) |
185 |
|
{ |
186 |
|
// Add new tree if not present in array of trees or return |
187 |
|
// present tree. |
188 |
|
|
189 |
< |
MyTree *tree = dynamic_cast<MyTree*>(fTrees.FindObject(tn)); |
189 |
> |
MyTree *tree = GetMyTree(tn); |
190 |
|
if (tree) |
191 |
|
return tree; |
192 |
|
|
193 |
|
TDirectory::TContext context(fFile); |
194 |
|
tree = new MyTree(tn, tn); |
195 |
|
tree->SetDirectory(fFile); |
196 |
< |
if (fDoObjNumReset) |
196 |
> |
if (fDoBranchRef) |
197 |
|
tree->BranchRef(); |
198 |
|
fTrees.AddLast(tree); |
199 |
|
return tree; |
231 |
|
|
232 |
|
for (Int_t i=0;i<fTrees.GetEntries();++i) { |
233 |
|
MyTree *mt = static_cast<MyTree*>(fTrees.At(i)); |
234 |
+ |
mt->FlushBaskets(); |
235 |
|
mt->Write(mt->GetName(),TObject::kOverwrite); |
236 |
< |
// Backup and restore list of branch pointers from TRefTable (needed for autoloading) |
236 |
> |
|
237 |
> |
// backup and restore list of branch pointers from TRefTable (needed for autoloading) |
238 |
|
if (mt->GetBranchRef()) { |
239 |
|
TObjArray *parents = mt->GetBranchRef()->GetRefTable()->GetParents(); |
240 |
|
TObjArray parentsBak(*parents); |
260 |
|
{ |
261 |
|
// Dereference void* pointer into TObject* pointer |
262 |
|
|
263 |
< |
TObject *tobj = dynamic_cast<TObject*>(*(TObject**)obj); |
263 |
> |
TObject **sobj = static_cast<TObject**>(obj); |
264 |
> |
TObject *tobj = dynamic_cast<TObject*>(*sobj); |
265 |
|
if (tobj==0) { |
266 |
< |
Fatal("ClassName", "Given void* ptr can not be dereferenced into TObject*"); |
266 |
> |
Fatal("CName", "Given void* ptr cannot be dereferenced into TObject*"); |
267 |
|
} |
268 |
|
return tobj->ClassName(); |
269 |
|
} |
270 |
|
|
271 |
|
//-------------------------------------------------------------------------------------------------- |
272 |
+ |
void TreeWriter::DoBranchRef(const char *tn) |
273 |
+ |
{ |
274 |
+ |
// Fill BranchRef for given tree. |
275 |
+ |
|
276 |
+ |
if (fTrees.GetEntries()==0) { |
277 |
+ |
Error("DoBranchRef", "Tree with name %s not found!", tn); |
278 |
+ |
return; |
279 |
+ |
} |
280 |
+ |
|
281 |
+ |
MyTree *mt = GetMyTree(tn); |
282 |
+ |
if (!mt) |
283 |
+ |
return; |
284 |
+ |
|
285 |
+ |
mt->BranchRef(); |
286 |
+ |
} |
287 |
+ |
|
288 |
+ |
//-------------------------------------------------------------------------------------------------- |
289 |
|
Bool_t TreeWriter::EndEvent(Bool_t doreset) |
290 |
|
{ |
291 |
|
// Store the event in the tree. If doreset or fDoObjNumReset is kTRUE |
507 |
|
//-------------------------------------------------------------------------------------------------- |
508 |
|
void TreeWriter::StoreObject(const TObject *obj) |
509 |
|
{ |
510 |
< |
// Store object next to tree in file. Used to store the |
488 |
< |
// settings of how the tree was created. |
510 |
> |
// Store object next to tree in file. Used to store the settings of how the tree was created. |
511 |
|
|
512 |
|
if (!fIsInit) { |
513 |
|
Fatal("StoreObject", "Tree is not created, call create first!"); |
521 |
|
|
522 |
|
fFile->WriteTObject(obj,obj->GetName(),"WriteDelete"); |
523 |
|
} |
524 |
+ |
|
525 |
+ |
//__________________________________________________________________________________________________ |
526 |
+ |
void TreeWriter::Terminate() |
527 |
+ |
{ |
528 |
+ |
// Terminate tree file writing. |
529 |
+ |
|
530 |
+ |
if (fIsInit) { |
531 |
+ |
CloseFile(); |
532 |
+ |
} |
533 |
+ |
|
534 |
+ |
TDirectory::TContext context(0); |
535 |
+ |
fTrees.Clear(); |
536 |
+ |
} |