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 |
|
//__________________________________________________________________________________________________ |
56 |
|
b->SetCompressionLevel(GetCompressLevel()); |
57 |
|
} |
58 |
|
|
63 |
– |
|
59 |
|
//-------------------------------------------------------------------------------------------------- |
60 |
|
void TreeWriter::AddBranch(const char *name, void *obj, Int_t bsize, Int_t level) |
61 |
|
{ |
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; |
232 |
|
for (Int_t i=0;i<fTrees.GetEntries();++i) { |
233 |
|
MyTree *mt = static_cast<MyTree*>(fTrees.At(i)); |
234 |
|
mt->Write(mt->GetName(),TObject::kOverwrite); |
235 |
< |
// Backup and restore list of branch pointers from TRefTable (needed for autoloading) |
235 |
> |
|
236 |
> |
// backup and restore list of branch pointers from TRefTable (needed for autoloading) |
237 |
|
if (mt->GetBranchRef()) { |
238 |
|
TObjArray *parents = mt->GetBranchRef()->GetRefTable()->GetParents(); |
239 |
|
TObjArray parentsBak(*parents); |
259 |
|
{ |
260 |
|
// Dereference void* pointer into TObject* pointer |
261 |
|
|
262 |
< |
TObject *tobj = dynamic_cast<TObject*>(*(TObject**)obj); |
262 |
> |
TObject **sobj = static_cast<TObject**>(obj); |
263 |
> |
TObject *tobj = dynamic_cast<TObject*>(*sobj); |
264 |
|
if (tobj==0) { |
265 |
< |
Fatal("ClassName", "Given void* ptr can not be dereferenced into TObject*"); |
265 |
> |
Fatal("CName", "Given void* ptr can not be dereferenced into TObject*"); |
266 |
|
} |
267 |
|
return tobj->ClassName(); |
268 |
|
} |
269 |
|
|
270 |
|
//-------------------------------------------------------------------------------------------------- |
271 |
+ |
void TreeWriter::DoBranchRef(const char *tn) |
272 |
+ |
{ |
273 |
+ |
// Fill BranchRef for given tree. |
274 |
+ |
|
275 |
+ |
if (fTrees.GetEntries()==0) { |
276 |
+ |
Error("DoBranchRef", "Tree with name %s not found!", tn); |
277 |
+ |
return; |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
MyTree *mt = GetMyTree(tn); |
281 |
+ |
if (!mt) |
282 |
+ |
return; |
283 |
+ |
|
284 |
+ |
mt->BranchRef(); |
285 |
+ |
} |
286 |
+ |
|
287 |
+ |
//-------------------------------------------------------------------------------------------------- |
288 |
|
Bool_t TreeWriter::EndEvent(Bool_t doreset) |
289 |
|
{ |
290 |
|
// Store the event in the tree. If doreset or fDoObjNumReset is kTRUE |
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 |
+ |
} |