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 |
|
//__________________________________________________________________________________________________ |
174 |
|
} |
175 |
|
|
176 |
|
//-------------------------------------------------------------------------------------------------- |
177 |
+ |
void TreeWriter::AddTree(const char *tname) |
178 |
+ |
{ |
179 |
+ |
// Add tree with name "name" into tree with name "tname". |
180 |
+ |
|
181 |
+ |
AddOrGetMyTree(tname); |
182 |
+ |
} |
183 |
+ |
|
184 |
+ |
//-------------------------------------------------------------------------------------------------- |
185 |
|
MyTree *TreeWriter::AddOrGetMyTree(const char *tn) |
186 |
|
{ |
187 |
|
// Add new tree if not present in array of trees or return |
188 |
|
// present tree. |
189 |
|
|
190 |
< |
MyTree *tree = dynamic_cast<MyTree*>(fTrees.FindObject(tn)); |
190 |
> |
MyTree *tree = GetMyTree(tn); |
191 |
|
if (tree) |
192 |
|
return tree; |
193 |
|
|
194 |
|
TDirectory::TContext context(fFile); |
195 |
|
tree = new MyTree(tn, tn); |
196 |
|
tree->SetDirectory(fFile); |
197 |
< |
if (fDoObjNumReset) |
197 |
> |
if (fDoBranchRef) |
198 |
|
tree->BranchRef(); |
199 |
|
fTrees.AddLast(tree); |
200 |
|
return tree; |
233 |
|
for (Int_t i=0;i<fTrees.GetEntries();++i) { |
234 |
|
MyTree *mt = static_cast<MyTree*>(fTrees.At(i)); |
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 can not 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 |
522 |
|
|
523 |
|
fFile->WriteTObject(obj,obj->GetName(),"WriteDelete"); |
524 |
|
} |
525 |
+ |
|
526 |
+ |
//__________________________________________________________________________________________________ |
527 |
+ |
void TreeWriter::Terminate() |
528 |
+ |
{ |
529 |
+ |
// Terminate tree file writing. |
530 |
+ |
|
531 |
+ |
if (fIsInit) { |
532 |
+ |
CloseFile(); |
533 |
+ |
} |
534 |
+ |
|
535 |
+ |
TDirectory::TContext context(0); |
536 |
+ |
fTrees.Clear(); |
537 |
+ |
} |