QwAnalysis
|
A wrapper class for a ROOT file or memory mapped file. More...
#include <QwRootFile.h>
Public Member Functions | |
QwRootFile (const TString &run_label) | |
Constructor with run label. More... | |
virtual | ~QwRootFile () |
Destructor. More... | |
void | ProcessOptions (QwOptions &options) |
Process the configuration options. More... | |
Bool_t | IsRootFile () const |
Is the ROOT file active? More... | |
Bool_t | IsMapFile () const |
Is the map file active? More... | |
void | ConstructIndices (const std::string &from, const std::string &to, bool reverse=true) |
Construct indices from one tree to another tree. More... | |
template<class T > | |
void | ConstructTreeBranches (const std::string &name, const std::string &desc, T &object, const std::string &prefix="") |
Construct the tree branches of a generic object. More... | |
template<class T > | |
void | FillTreeBranches (const std::string &name, const T &object) |
Fill the tree branches of a generic object by tree name. More... | |
template<class T > | |
void | FillTreeBranches (const T &object) |
Fill the tree branches of a generic object by type only. More... | |
template<class T > | |
Int_t | WriteParamFileList (const TString &name, T &object) |
template<class T > | |
void | ConstructHistograms (const std::string &name, T &object) |
Construct the histograms of a generic object. More... | |
template<class T > | |
void | FillHistograms (T &object) |
Fill histograms of the subsystem array. More... | |
void | NewTree (const std::string &name, const std::string &desc) |
Create a new tree with name and description. More... | |
TTree * | GetTree (const std::string &name) |
Get the tree with name. More... | |
Int_t | FillTree (const std::string &name) |
Fill the tree with name. More... | |
Int_t | FillTrees () |
Fill all registered trees. More... | |
void | PrintTrees () const |
Print registered trees. More... | |
void | PrintDirs () const |
Print registered histogram directories. More... | |
template<class T > | |
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) More... | |
void | Update () |
void | Print () |
void | ls () |
void | Map () |
void | Close () |
Bool_t | cd (const char *path=0) |
TDirectory * | mkdir (const char *name, const char *title="") |
Int_t | Write (const char *name=0, Int_t option=0, Int_t bufsize=0) |
Static Public Member Functions | |
static void | DefineOptions (QwOptions &options) |
Define the configuration options. More... | |
static void | SetDefaultRootFileStem (const std::string &stem) |
Set default ROOT file stem. More... | |
Private Member Functions | |
QwRootFile () | |
Private default constructor. More... | |
Bool_t | HasAnyFilled (void) |
Search for non-empty trees or histograms in the file. More... | |
Bool_t | HasAnyFilled (TDirectory *d) |
void | DisableTree (const TString ®exp) |
Add regexp to list of disabled trees names. More... | |
bool | IsTreeDisabled (const std::string &name) |
Does this tree name match a disabled tree name? More... | |
void | DisableHisto (const TString ®exp) |
Add regexp to list of disabled histogram directories. More... | |
bool | IsHistoDisabled (const std::string &name) |
Does this histogram directory match a disabled histogram directory? More... | |
bool | HasTreeByName (const std::string &name) |
Is a tree registered for this name. More... | |
template<class T > | |
bool | HasTreeByType (const T &object) |
Is a tree registered for this type. More... | |
template<class T > | |
bool | HasTreeByAddr (const T &object) |
Is a tree registered for this object. More... | |
bool | HasDirByName (const std::string &name) |
Is a tree registered for this name. More... | |
template<class T > | |
bool | HasDirByType (const T &object) |
Is a directory registered for this type. More... | |
Private Attributes | |
TFile * | fRootFile |
ROOT file. More... | |
TString | fRootFileStem |
ROOT file stem. More... | |
TString | fPermanentName |
Bool_t | fMakePermanent |
TMapFile * | fMapFile |
Map file. More... | |
Bool_t | fEnableMapFile |
Int_t | fUpdateInterval |
Int_t | fCompressionLevel |
Int_t | fBasketSize |
Int_t | fAutoFlush |
Int_t | fAutoSave |
std::vector< TPRegexp > | fDisabledTrees |
List of excluded trees. More... | |
std::vector< TPRegexp > | fDisabledHistos |
std::map< const std::string, std::vector< QwRootTree * > > | fTreeByName |
Tree names, addresses, and types. More... | |
std::map< const void *, std::vector< QwRootTree * > > | fTreeByAddr |
std::map< const type_info *, std::vector< QwRootTree * > > | fTreeByType |
std::map< const std::string, TDirectory * > | fDirsByName |
Directories. More... | |
std::map< const std::string, std::vector< std::string > > | fDirsByType |
UInt_t | fNumMpsEventsToSkip |
Prescaling of events written to tree. More... | |
UInt_t | fNumMpsEventsToSave |
UInt_t | fNumHelEventsToSkip |
UInt_t | fNumHelEventsToSave |
UInt_t | fCircularBufferSize |
UInt_t | fCurrentEvent |
Static Private Attributes | |
static std::string | fDefaultRootFileStem = "Qweak_" |
Default ROOT file stem. More... | |
static const Long64_t | kMaxTreeSize = 100000000000LL |
Maximum tree size. More... | |
static const Int_t | kMaxMapFileSize = 0x10000000 |
A wrapper class for a ROOT file or memory mapped file.
This class functions as a wrapper around a ROOT TFile or a TMapFile. The common inheritance of both is only TObject, so there is a lot that we have to wrap (rather than inherit). Theoretically you could have both a TFile and a TMapFile represented by an object of this class at the same time, but that is untested.
The functionality of writing to the file is done by templated functions. The objects that are passed to these functions have to provide the following functions:
The class keeps track of the registered tree names, and the types of objects that have branches constructed in those trees (via QwRootTree). In most cases it should be possible to just call FillTreeBranches with only the object, although in rare cases this could be ambiguous.
The proper way to register a tree is by either calling ConstructTreeBranches of NewTree first. Then FillTreeBranches will fill the vector, and FillTree will actually fill the tree. FillTree should be called only once.
Definition at line 281 of file QwRootFile.h.
QwRootFile::QwRootFile | ( | const TString & | run_label | ) |
Constructor with run label.
Constructor with relative filename
Definition at line 17 of file QwRootFile.cc.
References QwLog::endl(), fCompressionLevel, fEnableMapFile, fMapFile, fPermanentName, fRootFile, fRootFileStem, QwOptions::GetArgc(), QwOptions::GetArgv(), getenv_safe_TString(), gQwOptions, kMaxMapFileSize, ProcessOptions(), QwError, QwMessage, and WriteObject().
|
virtual |
Destructor.
Destructor
Definition at line 114 of file QwRootFile.cc.
References QwLog::endl(), fMakePermanent, fMapFile, fPermanentName, fRootFile, fTreeByName, HasAnyFilled(), QwMessage, and QwWarning.
|
private |
Private default constructor.
|
inline |
Definition at line 422 of file QwRootFile.h.
References fMapFile, and fRootFile.
Referenced by ConstructTreeBranches(), and NewTree().
|
inline |
Definition at line 416 of file QwRootFile.h.
References fMakePermanent, fMapFile, fRootFile, and HasAnyFilled().
Referenced by main().
void QwRootFile::ConstructHistograms | ( | const std::string & | name, |
T & | object | ||
) |
Construct the histograms of a generic object.
Construct the histogram of a generic object
name | Name for histogram directory |
object | Subsystem array |
Definition at line 706 of file QwRootFile.h.
References QwLog::endl(), fDirsByName, fDirsByType, fMapFile, fRootFile, IsHistoDisabled(), and QwMessage.
Referenced by main().
|
inline |
Construct indices from one tree to another tree.
Construct the indices from one tree to another tree, and optionally in reverse as well.
from | Name of tree where index will be created |
to | Name of tree to which index will point |
reverse | Flag to create indices in both direction |
Definition at line 574 of file QwRootFile.h.
References fTreeByName, and IsTreeDisabled().
Referenced by main().
void QwRootFile::ConstructTreeBranches | ( | const std::string & | name, |
const std::string & | desc, | ||
T & | object, | ||
const std::string & | prefix = "" |
||
) |
Construct the tree branches of a generic object.
Construct the tree branches of a generic object
name | Name for tree |
desc | Description for tree |
object | Subsystem array |
prefix | Prefix for the tree |
Definition at line 600 of file QwRootFile.h.
References cd(), fAutoFlush, fAutoSave, fBasketSize, fCircularBufferSize, fEnableMapFile, fNumHelEventsToSave, fNumHelEventsToSkip, fNumMpsEventsToSave, fNumMpsEventsToSkip, fTreeByAddr, fTreeByName, fTreeByType, IsTreeDisabled(), kMaxTreeSize, QwRootTree::SetAutoFlush(), QwRootTree::SetAutoSave(), QwRootTree::SetBasketSize(), QwRootTree::SetCircular(), QwRootTree::SetMaxTreeSize(), and QwRootTree::SetPrescaling().
Referenced by main().
|
static |
Define the configuration options.
Defines configuration options using QwOptions functionality.
options | Options object |
Definition at line 169 of file QwRootFile.cc.
References QwOptions::AddOptions(), default_bool_value, and fDefaultRootFileStem.
Referenced by QwOptions::DefineOptions().
|
inlineprivate |
Add regexp to list of disabled histogram directories.
Definition at line 496 of file QwRootFile.h.
References fDisabledHistos.
Referenced by ProcessOptions().
|
inlineprivate |
Add regexp to list of disabled trees names.
Definition at line 486 of file QwRootFile.h.
References fDisabledTrees.
Referenced by ProcessOptions().
|
inline |
Fill histograms of the subsystem array.
Definition at line 329 of file QwRootFile.h.
References fUpdateInterval, HasDirByType(), and Update().
Referenced by main().
|
inline |
Fill the tree with name.
Definition at line 359 of file QwRootFile.h.
References fTreeByName, and HasTreeByName().
Referenced by main().
void QwRootFile::FillTreeBranches | ( | const std::string & | name, |
const T & | object | ||
) |
Fill the tree branches of a generic object by tree name.
Fill the tree branches of a generic object by name
name | Name for tree |
object | Subsystem array |
Definition at line 658 of file QwRootFile.h.
References fTreeByAddr, HasTreeByName(), and HasTreeByType().
Referenced by main().
void QwRootFile::FillTreeBranches | ( | const T & | object | ) |
Fill the tree branches of a generic object by type only.
Fill the tree branches of a generic object by type only
object | Subsystem array |
Definition at line 684 of file QwRootFile.h.
References fTreeByAddr, and HasTreeByAddr().
|
inline |
Fill all registered trees.
Definition at line 365 of file QwRootFile.h.
References fTreeByName.
|
inline |
Get the tree with name.
Definition at line 353 of file QwRootFile.h.
References fTreeByName, and HasTreeByName().
Referenced by main().
|
private |
Search for non-empty trees or histograms in the file.
Determine whether the rootfile object has any non-empty trees or histograms.
Definition at line 293 of file QwRootFile.cc.
References fRootFile.
Referenced by Close(), HasAnyFilled(), and ~QwRootFile().
|
private |
Definition at line 296 of file QwRootFile.cc.
References HasAnyFilled().
|
inlineprivate |
Is a tree registered for this name.
Definition at line 540 of file QwRootFile.h.
References fDirsByName.
|
inlineprivate |
Is a directory registered for this type.
Definition at line 546 of file QwRootFile.h.
References fDirsByType.
Referenced by FillHistograms().
|
inlineprivate |
Is a tree registered for this object.
Definition at line 529 of file QwRootFile.h.
References fTreeByAddr.
Referenced by FillTreeBranches().
|
inlineprivate |
Is a tree registered for this name.
Definition at line 516 of file QwRootFile.h.
References fTreeByName.
Referenced by FillTree(), FillTreeBranches(), GetTree(), and NewTree().
|
inlineprivate |
Is a tree registered for this type.
Definition at line 522 of file QwRootFile.h.
References fTreeByType.
Referenced by FillTreeBranches().
|
inlineprivate |
Does this histogram directory match a disabled histogram directory?
Definition at line 500 of file QwRootFile.h.
References fDisabledHistos.
Referenced by ConstructHistograms().
|
inline |
|
inline |
|
inlineprivate |
Does this tree name match a disabled tree name?
Definition at line 490 of file QwRootFile.h.
References fDisabledTrees.
Referenced by ConstructIndices(), and ConstructTreeBranches().
|
inline |
|
inline |
|
inline |
|
inline |
Create a new tree with name and description.
Definition at line 341 of file QwRootFile.h.
References cd(), fTreeByName, and HasTreeByName().
Referenced by main().
|
inline |
|
inline |
Print registered histogram directories.
Definition at line 391 of file QwRootFile.h.
References QwLog::endl(), fDirsByName, and QwMessage.
Referenced by main().
|
inline |
Print registered trees.
Definition at line 376 of file QwRootFile.h.
References QwLog::endl(), fTreeByName, and QwMessage.
Referenced by main().
void QwRootFile::ProcessOptions | ( | QwOptions & | options | ) |
Process the configuration options.
Parse the configuration options and store in class fields
options | Options object |
Definition at line 243 of file QwRootFile.cc.
References DisableHisto(), DisableTree(), QwLog::endl(), fAutoFlush, fAutoSave, fBasketSize, fCircularBufferSize, fCompressionLevel, fEnableMapFile, fNumHelEventsToSave, fNumHelEventsToSkip, fNumMpsEventsToSave, fNumMpsEventsToSkip, fRootFileStem, fUpdateInterval, QwOptions::GetValue(), QwMessage, and QwWarning.
Referenced by QwRootFile().
|
inlinestatic |
Set default ROOT file stem.
Definition at line 296 of file QwRootFile.h.
References fDefaultRootFileStem.
Referenced by main().
|
inline |
Definition at line 412 of file QwRootFile.h.
References fMapFile.
Referenced by FillHistograms().
|
inline |
Definition at line 437 of file QwRootFile.h.
References fRootFile.
Referenced by main().
|
inline |
Write any object to the ROOT file (only valid for TFile)
Definition at line 403 of file QwRootFile.h.
References fRootFile.
Referenced by QwRootFile().
Int_t QwRootFile::WriteParamFileList | ( | const TString & | name, |
T & | object | ||
) |
Definition at line 736 of file QwRootFile.h.
References fRootFile.
Referenced by main().
|
private |
Definition at line 474 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Definition at line 475 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Definition at line 473 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Definition at line 560 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Definition at line 472 of file QwRootFile.h.
Referenced by ProcessOptions(), and QwRootFile().
|
private |
Definition at line 561 of file QwRootFile.h.
|
staticprivate |
Default ROOT file stem.
Definition at line 457 of file QwRootFile.h.
Referenced by DefineOptions(), and SetDefaultRootFileStem().
|
private |
Directories.
Definition at line 536 of file QwRootFile.h.
Referenced by ConstructHistograms(), HasDirByName(), and PrintDirs().
|
private |
Definition at line 537 of file QwRootFile.h.
Referenced by ConstructHistograms(), and HasDirByType().
|
private |
Definition at line 483 of file QwRootFile.h.
Referenced by DisableHisto(), and IsHistoDisabled().
|
private |
List of excluded trees.
Definition at line 482 of file QwRootFile.h.
Referenced by DisableTree(), and IsTreeDisabled().
|
private |
Definition at line 470 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), ProcessOptions(), and QwRootFile().
|
private |
Definition at line 462 of file QwRootFile.h.
Referenced by Close(), and ~QwRootFile().
|
private |
Map file.
Definition at line 469 of file QwRootFile.h.
Referenced by cd(), Close(), ConstructHistograms(), IsMapFile(), ls(), Print(), QwRootFile(), Update(), and ~QwRootFile().
|
private |
Definition at line 559 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Definition at line 558 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Definition at line 557 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
Prescaling of events written to tree.
Definition at line 556 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and ProcessOptions().
|
private |
While the file is open, give it a temporary filename. Perhaps change to a permanent name when closing the file.
Definition at line 461 of file QwRootFile.h.
Referenced by QwRootFile(), and ~QwRootFile().
|
private |
ROOT file.
Definition at line 452 of file QwRootFile.h.
Referenced by cd(), Close(), ConstructHistograms(), HasAnyFilled(), IsRootFile(), ls(), Map(), mkdir(), Print(), QwRootFile(), Write(), WriteObject(), WriteParamFileList(), and ~QwRootFile().
|
private |
ROOT file stem.
Definition at line 455 of file QwRootFile.h.
Referenced by ProcessOptions(), and QwRootFile().
|
private |
Definition at line 511 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), FillTreeBranches(), and HasTreeByAddr().
|
private |
Tree names, addresses, and types.
Definition at line 510 of file QwRootFile.h.
Referenced by ConstructIndices(), ConstructTreeBranches(), FillTree(), FillTrees(), GetTree(), HasTreeByName(), NewTree(), PrintTrees(), and ~QwRootFile().
|
private |
Definition at line 512 of file QwRootFile.h.
Referenced by ConstructTreeBranches(), and HasTreeByType().
|
private |
Definition at line 471 of file QwRootFile.h.
Referenced by FillHistograms(), and ProcessOptions().
|
staticprivate |
Definition at line 565 of file QwRootFile.h.
Referenced by QwRootFile().
|
staticprivate |
Maximum tree size.
Definition at line 564 of file QwRootFile.h.
Referenced by ConstructTreeBranches().