QwAnalysis
QwRootFile.h
Go to the documentation of this file.
1 #ifndef __QWROOTFILE__
2 #define __QWROOTFILE__
3 
4 // System headers
5 #include <typeinfo>
6 #include <unistd.h>
7 using std::type_info;
8 
9 // ROOT headers
10 #include "TFile.h"
11 #include "TTree.h"
12 #include "TPRegexp.h"
13 #include "TSystem.h"
14 
15 // Qweak headers
16 #include "QwOptions.h"
17 #include "TMapFile.h"
18 
19 
20 // If one defines more than this number of words in the full ntuple,
21 // the results are going to get very very crazy.
22 #define BRANCH_VECTOR_MAX_SIZE 13000
23 
24 
25 /**
26  * \class QwRootTree
27  * \ingroup QwAnalysis
28  * \brief A wrapper class for a ROOT tree
29  *
30  * This class provides the functionality to write to ROOT trees using a vector
31  * of doubles. The vector is part of this object, as well as a pointer to the
32  * tree that contains the branches. One ROOT tree can have multiple QwRootTree
33  * objects, for example in tracking mode both parity and tracking detectors
34  * can be stored in the same tree.
35  */
36 class QwRootTree {
37 
38  public:
39 
40  /// Constructor with name, and description
41  QwRootTree(const std::string& name, const std::string& desc, const std::string& prefix = "")
42  : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
44  // Construct tree
46  }
47 
48  /// Constructor with existing tree
49  QwRootTree(const QwRootTree* tree, const std::string& prefix = "")
50  : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
52  QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
53  fTree = tree->fTree;
54  }
55 
56  /// Constructor with name, description, and object
57  template < class T >
58  QwRootTree(const std::string& name, const std::string& desc, T& object, const std::string& prefix = "")
59  : fName(name),fDesc(desc),fPrefix(prefix),fType("type undefined"),
61  // Construct tree
63 
64  // Construct branches and vector
66  }
67 
68  /// Constructor with existing tree, and object
69  template < class T >
70  QwRootTree(const QwRootTree* tree, T& object, const std::string& prefix = "")
71  : fName(tree->GetName()),fDesc(tree->GetDesc()),fPrefix(prefix),fType("type undefined"),
73  QwMessage << "Existing tree: " << tree->GetName() << ", " << tree->GetDesc() << QwLog::endl;
74  fTree = tree->fTree;
75 
76  // Construct branches and vector
78  }
79 
80  /// Destructor
81  virtual ~QwRootTree() { }
82 
83 
84  private:
85 
86  /// Construct the tree
88  QwMessage << "New tree: " << fName << ", " << fDesc << QwLog::endl;
89  fTree = new TTree(fName.c_str(), fDesc.c_str());
90  }
91 
92  /// Construct index from this tree to another tree
94  std::string name = "previous_entry_in_" + to->fName;
95  fTree->Branch(name.c_str(), &(to->fCurrentEvent));
96  }
97 
98  /// Construct the branches and vector for generic objects
99  template < class T >
100  void ConstructBranchAndVector(T& object) {
101  // Reserve space for the branch vector
103  // Associate branches with vector
104  TString prefix = Form("%s",fPrefix.c_str());
105  object.ConstructBranchAndVector(fTree, prefix, fVector);
106 
107  // Store the type of object
108  fType = typeid(object).name();
109 
110  // Check memory reservation
111  if (fVector.size() > BRANCH_VECTOR_MAX_SIZE) {
112  QwError << "The branch vector is too large: " << fVector.size() << " leaves! "
113  << "The maximum size is " << BRANCH_VECTOR_MAX_SIZE << "."
114  << QwLog::endl;
115  exit(-1);
116  }
117  }
118 
119 
120  public:
121 
122  /// Fill the branches for generic objects
123  template < class T >
124  void FillTreeBranches(const T& object) {
125  if (typeid(object).name() == fType) {
126  // Fill the branch vector
127  object.FillTreeVector(fVector);
128  } else {
129  QwError << "Attempting to fill tree vector for type " << fType << " with "
130  << "object of type " << typeid(object).name() << QwLog::endl;
131  exit(-1);
132  }
133  }
134 
135  /// Fill the tree
136  Int_t Fill() {
137  fCurrentEvent++;
138 
139  // Tree prescaling
140  if (fNumEventsCycle > 0) {
143  return 0;
144  }
145 
146  // Fill the tree
147  Int_t retval = fTree->Fill();
148  // Check for errors
149  if (retval < 0) {
150  QwError << "Writing tree failed! Check disk space or quota." << QwLog::endl;
151  exit(retval);
152  }
153  return retval;
154  }
155 
156 
157  /// Print the tree name and description
158  void Print() const {
159  QwMessage << GetName() << ", " << GetType();
160  if (fPrefix != "")
161  QwMessage << " (prefix " << GetPrefix() << ")";
163  }
164 
165  /// Get the tree pointer for low level operations
166  TTree* GetTree() const { return fTree; };
167 
168 
169  friend class QwRootFile;
170 
171  private:
172 
173  /// Tree pointer
174  TTree* fTree;
175  /// Vector of leaves
176  std::vector<Double_t> fVector;
177 
178 
179  /// Name, description
180  const std::string fName;
181  const std::string fDesc;
182  const std::string fPrefix;
183 
184  /// Get the name of the tree
185  const std::string& GetName() const { return fName; };
186  /// Get the description of the tree
187  const std::string& GetDesc() const { return fDesc; };
188  /// Get the description of the tree
189  const std::string& GetPrefix() const { return fPrefix; };
190 
191 
192  /// Object type
193  std::string fType;
194 
195  /// Get the object type
196  std::string GetType() const { return fType; };
197 
198 
199  /// Tree prescaling parameters
200  UInt_t fCurrentEvent;
204 
205  /// Set tree prescaling parameters
206  void SetPrescaling(UInt_t num_to_save, UInt_t num_to_skip) {
207  fNumEventsToSave = num_to_save;
208  fNumEventsToSkip = num_to_skip;
210  }
211 
212 
213  /// Maximum tree size, autoflush and autosave
214  Long64_t fMaxTreeSize;
215  Long64_t fAutoFlush;
216  Long64_t fAutoSave;
217  Int_t fBasketSize;
218 
219  /// Set maximum tree size
220  void SetMaxTreeSize(Long64_t maxsize = 1900000000) {
221  fMaxTreeSize = maxsize;
222  if (fTree) fTree->SetMaxTreeSize(maxsize);
223  }
224 
225  /// Set autoflush size
226  void SetAutoFlush(Long64_t autoflush = 30000000) {
227  fAutoFlush = autoflush;
228  #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
229  if (fTree) fTree->SetAutoFlush(autoflush);
230  #endif
231  }
232 
233  /// Set autosave size
234  void SetAutoSave(Long64_t autosave = 300000000) {
235  fAutoSave = autosave;
236  if (fTree) fTree->SetAutoSave(autosave);
237  }
238 
239  /// Set basket size
240  void SetBasketSize(Int_t basketsize = 16000) {
241  fBasketSize = basketsize;
242  if (fTree) fTree->SetBasketSize("*",basketsize);
243  }
244 
245  //Set circular buffer size for the memory resident tree
246  void SetCircular(Long64_t buff = 100000) {
247  if (fTree) fTree->SetCircular(buff);
248  }
249 };
250 
251 
252 
253 /**
254  * \class QwRootFile
255  * \ingroup QwAnalysis
256  * \brief A wrapper class for a ROOT file or memory mapped file
257  *
258  * This class functions as a wrapper around a ROOT TFile or a TMapFile. The
259  * common inheritance of both is only TObject, so there is a lot that we have
260  * to wrap (rather than inherit). Theoretically you could have both a TFile
261  * and a TMapFile represented by an object of this class at the same time, but
262  * that is untested.
263  *
264  * The functionality of writing to the file is done by templated functions.
265  * The objects that are passed to these functions have to provide the following
266  * functions:
267  * <ul>
268  * <li>ConstructHistograms, FillHistograms
269  * <li>ConstructBranchAndVector, FillTreeVector
270  * </ul>
271  *
272  * The class keeps track of the registered tree names, and the types of objects
273  * that have branches constructed in those trees (via QwRootTree). In most
274  * cases it should be possible to just call FillTreeBranches with only the object,
275  * although in rare cases this could be ambiguous.
276  *
277  * The proper way to register a tree is by either calling ConstructTreeBranches
278  * of NewTree first. Then FillTreeBranches will fill the vector, and FillTree
279  * will actually fill the tree. FillTree should be called only once.
280  */
281 class QwRootFile {
282 
283  public:
284 
285  /// \brief Constructor with run label
286  QwRootFile(const TString& run_label);
287  /// \brief Destructor
288  virtual ~QwRootFile();
289 
290 
291  /// \brief Define the configuration options
292  static void DefineOptions(QwOptions &options);
293  /// \brief Process the configuration options
294  void ProcessOptions(QwOptions &options);
295  /// \brief Set default ROOT file stem
296  static void SetDefaultRootFileStem(const std::string& stem) {
297  fDefaultRootFileStem = stem;
298  }
299 
300 
301  /// Is the ROOT file active?
302  Bool_t IsRootFile() const { return (fRootFile); };
303  /// Is the map file active?
304  Bool_t IsMapFile() const { return (fMapFile); };
305 
306  /// \brief Construct indices from one tree to another tree
307  void ConstructIndices(const std::string& from, const std::string& to, bool reverse = true);
308 
309  /// \brief Construct the tree branches of a generic object
310  template < class T >
311  void ConstructTreeBranches(const std::string& name, const std::string& desc, T& object, const std::string& prefix = "");
312  /// \brief Fill the tree branches of a generic object by tree name
313  template < class T >
314  void FillTreeBranches(const std::string& name, const T& object);
315  /// \brief Fill the tree branches of a generic object by type only
316  template < class T >
317  void FillTreeBranches(const T& object);
318 
319 
320  template < class T >
321  Int_t WriteParamFileList(const TString& name, T& object);
322 
323 
324  /// \brief Construct the histograms of a generic object
325  template < class T >
326  void ConstructHistograms(const std::string& name, T& object);
327  /// Fill histograms of the subsystem array
328  template < class T >
329  void FillHistograms(T& object) {
330  // Update regularly
331  static Int_t update_count = 0;
332  update_count++;
333  if (update_count % fUpdateInterval == 0) Update();
334  if (! HasDirByType(object)) return;
335  // Fill histograms
336  object.FillHistograms();
337  }
338 
339 
340  /// Create a new tree with name and description
341  void NewTree(const std::string& name, const std::string& desc) {
342  this->cd();
343  QwRootTree *tree = 0;
344  if (! HasTreeByName(name)) {
345  tree = new QwRootTree(name,desc);
346  } else {
347  tree = new QwRootTree(fTreeByName[name].front());
348  }
349  fTreeByName[name].push_back(tree);
350  }
351 
352  /// Get the tree with name
353  TTree* GetTree(const std::string& name) {
354  if (! HasTreeByName(name)) return 0;
355  else return fTreeByName[name].front()->GetTree();
356  }
357 
358  /// Fill the tree with name
359  Int_t FillTree(const std::string& name) {
360  if (! HasTreeByName(name)) return 0;
361  else return fTreeByName[name].front()->Fill();
362  }
363 
364  /// Fill all registered trees
365  Int_t FillTrees() {
366  // Loop over all registered tree names
367  Int_t retval = 0;
368  std::map< const std::string, std::vector<QwRootTree*> >::iterator iter;
369  for (iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
370  retval += iter->second.front()->Fill();
371  }
372  return retval;
373  }
374 
375  /// Print registered trees
376  void PrintTrees() const {
377  QwMessage << "Trees: " << QwLog::endl;
378  // Loop over all registered tree names
379  std::map< const std::string, std::vector<QwRootTree*> >::const_iterator iter;
380  for (iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
381  QwMessage << iter->first << ": " << iter->second.size()
382  << " objects registered" << QwLog::endl;
383  // Loop over all registered objects for this tree
384  std::vector<QwRootTree*>::const_iterator tree;
385  for (tree = iter->second.begin(); tree != iter->second.end(); tree++) {
386  (*tree)->Print();
387  }
388  }
389  }
390  /// Print registered histogram directories
391  void PrintDirs() const {
392  QwMessage << "Dirs: " << QwLog::endl;
393  // Loop ove rall registered directories
394  std::map< const std::string, TDirectory* >::const_iterator iter;
395  for (iter = fDirsByName.begin(); iter != fDirsByName.end(); iter++) {
396  QwMessage << iter->first << QwLog::endl;
397  }
398  }
399 
400 
401  /// Write any object to the ROOT file (only valid for TFile)
402  template < class T >
403  Int_t WriteObject(const T* obj, const char* name, Option_t* option = "", Int_t bufsize = 0) {
404  Int_t retval = 0;
405  // TMapFile has no suport for WriteObject
406  if (fRootFile) retval = fRootFile->WriteObject(obj,name,option,bufsize);
407  return retval;
408  }
409 
410 
411  // Wrapped functionality
412  void Update() { if (fMapFile) fMapFile->Update(); } // not for TFile
413  void Print() { if (fMapFile) fMapFile->Print(); if (fRootFile) fRootFile->Print(); }
414  void ls() { if (fMapFile) fMapFile->ls(); if (fRootFile) fRootFile->ls(); }
415  void Map() { if (fRootFile) fRootFile->Map(); }
416  void Close() {
418  if (fMapFile) fMapFile->Close(); if (fRootFile) fRootFile->Close();
419  }
420 
421  // Wrapped functionality
422  Bool_t cd(const char* path = 0) {
423  Bool_t status = kTRUE;
424  if (fMapFile) status &= fMapFile->cd(path);
425  if (fRootFile) status &= fRootFile->cd(path);
426  return status;
427  }
428 
429  // Wrapped functionality
430  TDirectory* mkdir(const char* name, const char* title = "") {
431  // TMapFile has no suport for mkdir
432  if (fRootFile) return fRootFile->mkdir(name, title);
433  else return 0;
434  }
435 
436  // Wrapped functionality
437  Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) {
438  Int_t retval = 0;
439  // TMapFile has no suport for Write
440  if (fRootFile) retval = fRootFile->Write(name, option, bufsize);
441  return retval;
442  }
443 
444 
445  private:
446 
447  /// Private default constructor
448  QwRootFile();
449 
450 
451  /// ROOT file
452  TFile* fRootFile;
453 
454  /// ROOT file stem
455  TString fRootFileStem;
456  /// Default ROOT file stem
457  static std::string fDefaultRootFileStem;
458 
459  /// While the file is open, give it a temporary filename. Perhaps
460  /// change to a permanent name when closing the file.
461  TString fPermanentName;
463 
464  /// Search for non-empty trees or histograms in the file
465  Bool_t HasAnyFilled(void);
466  Bool_t HasAnyFilled(TDirectory* d);
467 
468  /// Map file
469  TMapFile* fMapFile;
473  Int_t fBasketSize;
474  Int_t fAutoFlush;
475  Int_t fAutoSave;
476 
477 
478 
479  private:
480 
481  /// List of excluded trees
482  std::vector< TPRegexp > fDisabledTrees;
483  std::vector< TPRegexp > fDisabledHistos;
484 
485  /// Add regexp to list of disabled trees names
486  void DisableTree(const TString& regexp) {
487  fDisabledTrees.push_back(regexp);
488  }
489  /// Does this tree name match a disabled tree name?
490  bool IsTreeDisabled(const std::string& name) {
491  for (size_t i = 0; i < fDisabledTrees.size(); i++)
492  if (fDisabledTrees.at(i).Match(name)) return true;
493  return false;
494  }
495  /// Add regexp to list of disabled histogram directories
496  void DisableHisto(const TString& regexp) {
497  fDisabledHistos.push_back(regexp);
498  }
499  /// Does this histogram directory match a disabled histogram directory?
500  bool IsHistoDisabled(const std::string& name) {
501  for (size_t i = 0; i < fDisabledHistos.size(); i++)
502  if (fDisabledHistos.at(i).Match(name)) return true;
503  return false;
504  }
505 
506 
507  private:
508 
509  /// Tree names, addresses, and types
510  std::map< const std::string, std::vector<QwRootTree*> > fTreeByName;
511  std::map< const void* , std::vector<QwRootTree*> > fTreeByAddr;
512  std::map< const type_info* , std::vector<QwRootTree*> > fTreeByType;
513  // ... Are type_info objects really unique? Let's hope so.
514 
515  /// Is a tree registered for this name
516  bool HasTreeByName(const std::string& name) {
517  if (fTreeByName.count(name) == 0) return false;
518  else return true;
519  }
520  /// Is a tree registered for this type
521  template < class T >
522  bool HasTreeByType(const T& object) {
523  const type_info* type = &typeid(object);
524  if (fTreeByType.count(type) == 0) return false;
525  else return true;
526  }
527  /// Is a tree registered for this object
528  template < class T >
529  bool HasTreeByAddr(const T& object) {
530  const void* addr = static_cast<const void*>(&object);
531  if (fTreeByAddr.count(addr) == 0) return false;
532  else return true;
533  }
534 
535  /// Directories
536  std::map< const std::string, TDirectory* > fDirsByName;
537  std::map< const std::string, std::vector<std::string> > fDirsByType;
538 
539  /// Is a tree registered for this name
540  bool HasDirByName(const std::string& name) {
541  if (fDirsByName.count(name) == 0) return false;
542  else return true;
543  }
544  /// Is a directory registered for this type
545  template < class T >
546  bool HasDirByType(const T& object) {
547  std::string type = typeid(object).name();
548  if (fDirsByType.count(type) == 0) return false;
549  else return true;
550  }
551 
552 
553  private:
554 
555  /// Prescaling of events written to tree
562 
563  /// Maximum tree size
564  static const Long64_t kMaxTreeSize;
565  static const Int_t kMaxMapFileSize;
566 };
567 
568 /**
569  * Construct the indices from one tree to another tree, and optionally in reverse as well.
570  * @param from Name of tree where index will be created
571  * @param to Name of tree to which index will point
572  * @param reverse Flag to create indices in both direction
573  */
574 inline void QwRootFile::ConstructIndices(const std::string& from, const std::string& to, bool reverse)
575 {
576  // Return if we do not want this tree information
577  if (IsTreeDisabled(from)) return;
578  if (IsTreeDisabled(to)) return;
579 
580  // If the trees are defined
581  if (fTreeByName.count(from) > 0 && fTreeByName.count(to) > 0) {
582 
583  // Construct index from the first tree to the second tree
584  fTreeByName[from].front()->ConstructIndexTo(fTreeByName[to].front());
585 
586  // Construct index from the second tree back to the first tree
587  if (reverse)
588  fTreeByName[to].front()->ConstructIndexTo(fTreeByName[from].front());
589  }
590 }
591 
592 /**
593  * Construct the tree branches of a generic object
594  * @param name Name for tree
595  * @param desc Description for tree
596  * @param object Subsystem array
597  * @param prefix Prefix for the tree
598  */
599 template < class T >
601  const std::string& name,
602  const std::string& desc,
603  T& object,
604  const std::string& prefix)
605 {
606  // Return if we do not want this tree information
607  if (IsTreeDisabled(name)) return;
608 
609  // Pointer to new tree
610  QwRootTree* tree = 0;
611 
612  // If the tree does not exist yet, create it
613  if (fTreeByName.count(name) == 0) {
614 
615  // Go to top level directory
616  this->cd();
617 
618  // New tree with name, description, object, prefix
619  tree = new QwRootTree(name, desc, object, prefix);
620 
621  // Settings only relevant for new trees
622  if (name == "Mps_Tree")
624  else if (name == "Hel_Tree")
626 
627  #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
628  tree->SetAutoFlush(fAutoFlush);
629  #endif
630  tree->SetAutoSave(fAutoSave);
631  tree->SetBasketSize(fBasketSize);
633 
636 
637  } else {
638 
639  // New tree based on existing tree
640  tree = new QwRootTree(fTreeByName[name].front(), object, prefix);
641  }
642 
643  // Add the branches to the list of trees by name, object, type
644  const void* addr = static_cast<const void*>(&object);
645  const type_info* type = &typeid(object);
646  fTreeByName[name].push_back(tree);
647  fTreeByAddr[addr].push_back(tree);
648  fTreeByType[type].push_back(tree);
649 }
650 
651 
652 /**
653  * Fill the tree branches of a generic object by name
654  * @param name Name for tree
655  * @param object Subsystem array
656  */
657 template < class T >
659  const std::string& name,
660  const T& object)
661 {
662  // If this name has no registered trees
663  if (! HasTreeByName(name)) return;
664  // If this type has no registered trees
665  if (! HasTreeByType(object)) return;
666 
667  // Get the address of the object
668  const void* addr = static_cast<const void*>(&object);
669 
670  // Fill the trees with the correct address
671  for (size_t tree = 0; tree < fTreeByAddr[addr].size(); tree++) {
672  if (fTreeByAddr[addr].at(tree)->GetName() == name) {
673  fTreeByAddr[addr].at(tree)->FillTreeBranches(object);
674  }
675  }
676 }
677 
678 
679 /**
680  * Fill the tree branches of a generic object by type only
681  * @param object Subsystem array
682  */
683 template < class T >
685  const T& object)
686 {
687  // If this address has no registered trees
688  if (! HasTreeByAddr(object)) return;
689 
690  // Get the address of the object
691  const void* addr = static_cast<const void*>(&object);
692 
693  // Fill the trees with the correct address
694  for (size_t tree = 0; tree < fTreeByAddr[addr].size(); tree++) {
695  fTreeByAddr[addr].at(tree)->FillTreeBranches(object);
696  }
697 }
698 
699 
700 /**
701  * Construct the histogram of a generic object
702  * @param name Name for histogram directory
703  * @param object Subsystem array
704  */
705 template < class T >
706 void QwRootFile::ConstructHistograms(const std::string& name, T& object)
707 {
708  // Return if we do not want this histogram information
709  if (IsHistoDisabled(name)) return;
710 
711  // Create the histograms in a directory
712  if (fRootFile) {
713  std::string type = typeid(object).name();
714  fDirsByName[name] = fRootFile->GetDirectory("/")->mkdir(name.c_str());
715  fDirsByType[type].push_back(name);
716  object.ConstructHistograms(fDirsByName[name]);
717  }
718 
719  // No support for directories in a map file
720  if (fMapFile) {
721  QwMessage << "QwRootFile::ConstructHistograms::detectors address "
722  << &object
723  << " and its name " << name
724  << QwLog::endl;
725 
726  std::string type = typeid(object).name();
727  fDirsByName[name] = fMapFile->GetDirectory()->mkdir(name.c_str());
728  fDirsByType[type].push_back(name);
729  //object.ConstructHistograms(fDirsByName[name]);
730  object.ConstructHistograms();
731  }
732 }
733 
734 
735 template < class T >
736 Int_t QwRootFile::WriteParamFileList(const TString &name, T& object)
737 {
738  Int_t retval = 0;
739  if (fRootFile) {
740  TList *param_list = (TList*) fRootFile->FindObjectAny(name);
741  if (not param_list) {
742  retval = fRootFile->WriteObject(object.GetParamFileNameList(name), name);
743  }
744  }
745  return retval;
746 }
747 
748 
749 #endif // __QWROOTFILE__
Int_t fBasketSize
Definition: QwRootFile.h:473
#define QwMessage
Predefined log drain for regular messages.
Definition: QwLog.h:50
void ConstructIndexTo(QwRootTree *to)
Construct index from this tree to another tree.
Definition: QwRootFile.h:93
UInt_t fNumMpsEventsToSave
Definition: QwRootFile.h:557
Int_t fAutoSave
Definition: QwRootFile.h:475
QwRootTree(const std::string &name, const std::string &desc, const std::string &prefix="")
Constructor with name, and description.
Definition: QwRootFile.h:41
TTree * fTree
Tree pointer.
Definition: QwRootFile.h:174
const std::string & GetName() const
Get the name of the tree.
Definition: QwRootFile.h:185
void ls()
Definition: QwRootFile.h:414
Int_t fAutoFlush
Definition: QwRootFile.h:474
UInt_t fCurrentEvent
Tree prescaling parameters.
Definition: QwRootFile.h:196
void Print() const
Print the tree name and description.
Definition: QwRootFile.h:158
Long64_t fAutoFlush
Definition: QwRootFile.h:215
A wrapper class for a ROOT tree.
Definition: QwRootFile.h:36
Bool_t fEnableMapFile
Definition: QwRootFile.h:470
Int_t WriteParamFileList(const TString &name, T &object)
Definition: QwRootFile.h:736
void SetMaxTreeSize(Long64_t maxsize=1900000000)
Set maximum tree size.
Definition: QwRootFile.h:220
UInt_t fNumHelEventsToSkip
Definition: QwRootFile.h:558
UInt_t fCurrentEvent
Definition: QwRootFile.h:561
void ConstructHistograms(const std::string &name, T &object)
Construct the histograms of a generic object.
Definition: QwRootFile.h:706
TTree * GetTree(const std::string &name)
Get the tree with name.
Definition: QwRootFile.h:353
An options class.
Definition: QwOptions.h:133
Int_t Fill()
Fill the tree.
Definition: QwRootFile.h:136
void SetAutoSave(Long64_t autosave=300000000)
Set autosave size.
Definition: QwRootFile.h:234
void SetAutoFlush(Long64_t autoflush=30000000)
Set autoflush size.
Definition: QwRootFile.h:226
const std::string fDesc
Definition: QwRootFile.h:181
bool HasTreeByName(const std::string &name)
Is a tree registered for this name.
Definition: QwRootFile.h:516
void ConstructIndices(const std::string &from, const std::string &to, bool reverse=true)
Construct indices from one tree to another tree.
Definition: QwRootFile.h:574
TMapFile * fMapFile
Map file.
Definition: QwRootFile.h:469
void DisableHisto(const TString &regexp)
Add regexp to list of disabled histogram directories.
Definition: QwRootFile.h:496
std::map< const void *, std::vector< QwRootTree * > > fTreeByAddr
Definition: QwRootFile.h:511
Int_t FillTrees()
Fill all registered trees.
Definition: QwRootFile.h:365
UInt_t fNumMpsEventsToSkip
Prescaling of events written to tree.
Definition: QwRootFile.h:556
void Close()
Definition: QwRootFile.h:416
Int_t fUpdateInterval
Definition: QwRootFile.h:471
UInt_t fNumEventsToSkip
Definition: QwRootFile.h:203
bool HasTreeByAddr(const T &object)
Is a tree registered for this object.
Definition: QwRootFile.h:529
Bool_t IsRootFile() const
Is the ROOT file active?
Definition: QwRootFile.h:302
QwRootFile()
Private default constructor.
std::vector< Double_t > fVector
Vector of leaves.
Definition: QwRootFile.h:176
UInt_t fNumHelEventsToSave
Definition: QwRootFile.h:559
Int_t FillTree(const std::string &name)
Fill the tree with name.
Definition: QwRootFile.h:359
std::vector< TPRegexp > fDisabledHistos
Definition: QwRootFile.h:483
void SetBasketSize(Int_t basketsize=16000)
Set basket size.
Definition: QwRootFile.h:240
TTree * GetTree() const
Get the tree pointer for low level operations.
Definition: QwRootFile.h:166
void SetPrescaling(UInt_t num_to_save, UInt_t num_to_skip)
Set tree prescaling parameters.
Definition: QwRootFile.h:206
TString fPermanentName
Definition: QwRootFile.h:461
TString fRootFileStem
ROOT file stem.
Definition: QwRootFile.h:455
virtual ~QwRootFile()
Destructor.
Definition: QwRootFile.cc:114
Bool_t cd(const char *path=0)
Definition: QwRootFile.h:422
Int_t fBasketSize
Definition: QwRootFile.h:217
bool IsTreeDisabled(const std::string &name)
Does this tree name match a disabled tree name?
Definition: QwRootFile.h:490
const std::string fName
Name, description.
Definition: QwRootFile.h:180
UInt_t fCircularBufferSize
Definition: QwRootFile.h:560
A wrapper class for a ROOT file or memory mapped file.
Definition: QwRootFile.h:281
const std::string & GetDesc() const
Get the description of the tree.
Definition: QwRootFile.h:187
Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: QwRootFile.h:437
static std::string fDefaultRootFileStem
Default ROOT file stem.
Definition: QwRootFile.h:457
Int_t WriteObject(const T *obj, const char *name, Option_t *option="", Int_t bufsize=0)
Write any object to the ROOT file (only valid for TFile)
Definition: QwRootFile.h:403
void ConstructBranchAndVector(T &object)
Construct the branches and vector for generic objects.
Definition: QwRootFile.h:100
void Map()
Definition: QwRootFile.h:415
UInt_t fNumEventsToSave
Definition: QwRootFile.h:202
QwRootTree(const QwRootTree *tree, const std::string &prefix="")
Constructor with existing tree.
Definition: QwRootFile.h:49
QwRootTree(const QwRootTree *tree, T &object, const std::string &prefix="")
Constructor with existing tree, and object.
Definition: QwRootFile.h:70
void Print()
Definition: QwRootFile.h:413
std::vector< TPRegexp > fDisabledTrees
List of excluded trees.
Definition: QwRootFile.h:482
void ConstructTreeBranches(const std::string &name, const std::string &desc, T &object, const std::string &prefix="")
Construct the tree branches of a generic object.
Definition: QwRootFile.h:600
virtual ~QwRootTree()
Destructor.
Definition: QwRootFile.h:81
#define BRANCH_VECTOR_MAX_SIZE
Definition: QwRootFile.h:22
std::map< const std::string, TDirectory * > fDirsByName
Directories.
Definition: QwRootFile.h:536
TFile * fRootFile
ROOT file.
Definition: QwRootFile.h:452
void NewTree(const std::string &name, const std::string &desc)
Create a new tree with name and description.
Definition: QwRootFile.h:341
Bool_t HasAnyFilled(void)
Search for non-empty trees or histograms in the file.
Definition: QwRootFile.cc:293
QwRootTree(const std::string &name, const std::string &desc, T &object, const std::string &prefix="")
Constructor with name, description, and object.
Definition: QwRootFile.h:58
static const double T
Magnetic field: base unit is T.
Definition: QwUnits.h:111
void ConstructNewTree()
Construct the tree.
Definition: QwRootFile.h:87
static void SetDefaultRootFileStem(const std::string &stem)
Set default ROOT file stem.
Definition: QwRootFile.h:296
const std::string & GetPrefix() const
Get the description of the tree.
Definition: QwRootFile.h:189
std::string GetType() const
Get the object type.
Definition: QwRootFile.h:196
std::map< const std::string, std::vector< QwRootTree * > > fTreeByName
Tree names, addresses, and types.
Definition: QwRootFile.h:510
const std::string fPrefix
Definition: QwRootFile.h:182
Long64_t fAutoSave
Definition: QwRootFile.h:216
static const Long64_t kMaxTreeSize
Maximum tree size.
Definition: QwRootFile.h:564
Int_t fCompressionLevel
Definition: QwRootFile.h:472
std::string fType
Object type.
Definition: QwRootFile.h:189
UInt_t fNumEventsCycle
Definition: QwRootFile.h:201
TDirectory * mkdir(const char *name, const char *title="")
Definition: QwRootFile.h:430
void Update()
Definition: QwRootFile.h:412
Bool_t IsMapFile() const
Is the map file active?
Definition: QwRootFile.h:304
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
static const Int_t kMaxMapFileSize
Definition: QwRootFile.h:565
void ProcessOptions(QwOptions &options)
Process the configuration options.
Definition: QwRootFile.cc:243
void FillTreeBranches(const std::string &name, const T &object)
Fill the tree branches of a generic object by tree name.
Definition: QwRootFile.h:658
void FillHistograms(T &object)
Fill histograms of the subsystem array.
Definition: QwRootFile.h:329
An options class which parses command line, config file and environment.
void DisableTree(const TString &regexp)
Add regexp to list of disabled trees names.
Definition: QwRootFile.h:486
bool HasDirByName(const std::string &name)
Is a tree registered for this name.
Definition: QwRootFile.h:540
bool HasDirByType(const T &object)
Is a directory registered for this type.
Definition: QwRootFile.h:546
void SetCircular(Long64_t buff=100000)
Definition: QwRootFile.h:246
bool HasTreeByType(const T &object)
Is a tree registered for this type.
Definition: QwRootFile.h:522
std::map< const std::string, std::vector< std::string > > fDirsByType
Definition: QwRootFile.h:537
bool IsHistoDisabled(const std::string &name)
Does this histogram directory match a disabled histogram directory?
Definition: QwRootFile.h:500
void PrintTrees() const
Print registered trees.
Definition: QwRootFile.h:376
Long64_t fMaxTreeSize
Maximum tree size, autoflush and autosave.
Definition: QwRootFile.h:214
void FillTreeBranches(const T &object)
Fill the branches for generic objects.
Definition: QwRootFile.h:124
std::map< const type_info *, std::vector< QwRootTree * > > fTreeByType
Definition: QwRootFile.h:512
void PrintDirs() const
Print registered histogram directories.
Definition: QwRootFile.h:391
static void DefineOptions(QwOptions &options)
Define the configuration options.
Definition: QwRootFile.cc:169
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
Bool_t fMakePermanent
Definition: QwRootFile.h:462