JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
QwRootFile Class Reference

A wrapper class for a ROOT file or memory mapped file. More...

#include <QwRootFile.h>

+ Collaboration diagram for QwRootFile:

Public Member Functions

 QwRootFile (const TString &run_label)
 Constructor with run label.
 
virtual ~QwRootFile ()
 Destructor.
 
void ProcessOptions (QwOptions &options)
 Process the configuration options.
 
Bool_t IsRootFile () const
 Is the ROOT file active?
 
Bool_t IsMapFile () const
 Is the map file active?
 
void ConstructIndices (const std::string &from, const std::string &to, bool reverse=true)
 Construct indices from one tree to another tree.
 
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.
 
template<class T>
void FillTreeBranches (const std::string &name, const T &object)
 Fill the tree branches of a generic object by tree name.
 
template<class T>
void FillTreeBranches (const T &object)
 Fill the tree branches of a generic object by type only.
 
template<class T>
Int_t WriteParamFileList (const TString &name, T &object)
 
template<class T>
void ConstructObjects (const std::string &name, T &object)
 Construct the histograms of a generic object.
 
template<class T>
void ConstructHistograms (const std::string &name, T &object)
 Construct the histograms of a generic object.
 
template<class T>
void FillHistograms (T &object)
 Fill histograms of the subsystem array.
 
void NewTree (const std::string &name, const std::string &desc)
 Create a new tree with name and description.
 
TTree * GetTree (const std::string &name)
 Get the tree with name.
 
Int_t FillTree (const std::string &name)
 Fill the tree with name.
 
Int_t FillTrees ()
 Fill all registered trees.
 
void PrintTrees () const
 Print registered trees.
 
void PrintDirs () const
 Print registered histogram directories.
 
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)
 
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.
 
static void SetDefaultRootFileDir (const std::string &dir)
 Set default ROOT files dir.
 
static void SetDefaultRootFileStem (const std::string &stem)
 Set default ROOT file stem.
 

Private Member Functions

void ClearInMemoryObjects (TDirectory *dir)
 
 QwRootFile ()
 Private default constructor.
 
Bool_t HasAnyFilled (void)
 Search for non-empty trees or histograms in the file.
 
Bool_t HasAnyFilled (TDirectory *d)
 
void DisableTree (const TString &regexp)
 Add regexp to list of disabled trees names.
 
bool IsTreeDisabled (const std::string &name)
 Does this tree name match a disabled tree name?
 
void DisableHisto (const TString &regexp)
 Add regexp to list of disabled histogram directories.
 
bool IsHistoDisabled (const std::string &name)
 Does this histogram directory match a disabled histogram directory?
 
bool HasTreeByName (const std::string &name)
 Is a tree registered for this name.
 
template<class T>
bool HasTreeByType (const T &object)
 Is a tree registered for this type.
 
template<class T>
bool HasTreeByAddr (const T &object)
 Is a tree registered for this object.
 
bool HasDirByName (const std::string &name)
 Is a tree registered for this name.
 
template<class T>
bool HasDirByType (const T &object)
 Is a directory registered for this type.
 

Private Attributes

TFile * fRootFile
 ROOT file.
 
TString fRootFileDir
 ROOT files dir.
 
TString fRootFileStem
 ROOT file stem.
 
TString fPermanentName
 
Bool_t fMakePermanent
 
Bool_t fUseTemporaryFile
 
TMapFile * fMapFile
 Map file.
 
Bool_t fEnableMapFile
 
Int_t fUpdateInterval
 
Int_t fCompressionAlgorithm
 
Int_t fCompressionLevel
 
Int_t fRNTupleCompressionAlgorithm
 
Int_t fRNTupleCompressionLevel
 
Int_t fBasketSize
 
Int_t fAutoFlush
 
Int_t fAutoSave
 
std::vector< TPRegexp > fDisabledTrees
 List of excluded trees.
 
std::vector< TPRegexp > fDisabledHistos
 
std::map< const std::string, std::vector< QwRootTree * > > fTreeByName
 Tree names, addresses, and types.
 
std::map< const void *, std::vector< QwRootTree * > > fTreeByAddr
 
std::map< const std::type_index, std::vector< QwRootTree * > > fTreeByType
 
std::map< const std::string, TDirectory * > fDirsByName
 Directories.
 
std::map< const std::string, std::vector< std::string > > fDirsByType
 
UInt_t fNumMpsEventsToSkip
 Prescaling of events written to tree.
 
UInt_t fNumMpsEventsToSave
 
UInt_t fNumHelEventsToSkip
 
UInt_t fNumHelEventsToSave
 
UInt_t fCircularBufferSize
 
UInt_t fCurrentEvent
 

Static Private Attributes

static std::string fDefaultRootFileDir = "."
 Default ROOT files dir.
 
static std::string fDefaultRootFileStem = "Qweak_"
 Default ROOT file stem.
 
static const Long64_t kMaxTreeSize = 100000000000LL
 Maximum tree size.
 
static const Int_t kMaxMapFileSize = 0x3fffffff
 

Detailed Description

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:

  • ConstructHistograms, FillHistograms
  • ConstructBranchAndVector, FillTreeVector

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 849 of file QwRootFile.h.

Constructor & Destructor Documentation

◆ QwRootFile() [1/2]

QwRootFile::QwRootFile ( const TString & run_label)

Constructor with run label.

Constructor with relative filename

Definition at line 25 of file QwRootFile.cc.

27 fMapFile(0), fEnableMapFile(kFALSE),
29#ifdef HAS_RNTUPLE_SUPPORT
30 , fEnableRNTuples(kFALSE)
31#endif // HAS_RNTUPLE_SUPPORT
32{
33 // Process the configuration options
35
36#ifdef QW_ENABLE_MAPFILE
37 // Check for the memory-mapped file flag
38 if (fEnableMapFile) {
39
40 TString mapfilename = "/dev/shm/";
41
42 mapfilename += "/QwMemMapFile.map";
43
44 fMapFile = TMapFile::Create(mapfilename,"UPDATE", kMaxMapFileSize, "RealTime Producer File");
45
46 if (not fMapFile) {
47 QwError << "Memory-mapped file " << mapfilename
48 << " could not be opened!" << QwLog::endl;
49 return;
50 }
51
52 QwMessage << "================== RealTime Producer Memory Map File =================" << QwLog::endl;
53 fMapFile->Print();
54 QwMessage << "======================================================================" << QwLog::endl;
55 } else
56#endif
57 {
58
59 TString rootfilename = fRootFileDir;
60 TString hostname = gSystem -> HostName();
61
62 // Use a probably-unique temporary file name.
63 pid_t pid = getpid();
64
65 fPermanentName = rootfilename
66 + Form("/%s%s.root", fRootFileStem.Data(), run_label.Data());
68 rootfilename += Form("/%s%s.%s.%d.root",
69 fRootFileStem.Data(), run_label.Data(),
70 hostname.Data(), pid);
71 // Delete permanent file if it exists to prevent accumulation across segments
72 if (gSystem->AccessPathName(fPermanentName.Data()) == 0) {
73 QwVerbose << "Removing existing permanent file: " << fPermanentName << QwLog::endl;
74 gSystem->Unlink(fPermanentName.Data());
75 }
76 // CRITICAL: Also delete the temporary file if it exists!
77 // RECREATE mode doesn't properly clear files that contain RNTuples,
78 // so we must manually delete before opening
79 if (gSystem->AccessPathName(rootfilename.Data()) == 0) {
80 QwVerbose << "Removing existing temporary file before RECREATE: " << rootfilename << QwLog::endl;
81 gSystem->Unlink(rootfilename.Data());
82 }
83 } else {
84 rootfilename = fPermanentName;
85 // Delete permanent file if it exists to ensure RECREATE truly starts fresh
86 // This is especially important for RNTuple files where RECREATE doesn't properly clear
87 if (gSystem->AccessPathName(rootfilename.Data()) == 0) {
88 QwMessage << "File exists before RECREATE, deleting: " << rootfilename << QwLog::endl;
89 int unlink_result = gSystem->Unlink(rootfilename.Data());
90 if (unlink_result == 0) {
91 QwMessage << "Successfully deleted file" << QwLog::endl;
92 } else {
93 QwError << "Failed to delete file! Error code: " << unlink_result << QwLog::endl;
94 }
95 } else {
96 QwMessage << "File does not exist before RECREATE: " << rootfilename << QwLog::endl;
97 }
98 }
99 QwMessage << "Opening file with RECREATE mode: " << rootfilename << QwLog::endl;
100 QwMessage << "QwRootFile constructor called for: " << rootfilename << QwLog::endl;
101 fRootFile = new TFile(rootfilename.Data(), "RECREATE", "myfile1");
102 if (! fRootFile) {
103 QwError << "ROOT file " << rootfilename
104 << " could not be opened!" << QwLog::endl;
105 return;
106 } else {
107 QwMessage << "Opened "<< (fUseTemporaryFile?"temporary ":"")
108 <<"rootfile " << rootfilename << QwLog::endl;
109 }
110
111 TString run_condition_name = Form("condition_%s", run_label.Data());
112 TList *run_cond_list = (TList*) fRootFile -> FindObjectAny(run_condition_name);
113 if (not run_cond_list) {
114 QwRunCondition run_condition(
115 gQwOptions.GetArgc(),
116 gQwOptions.GetArgv(),
117 run_condition_name
118 );
119
121 run_condition.Get(),
122 run_condition.GetName()
123 );
124 }
125
126 fRootFile->SetCompressionAlgorithm(fCompressionAlgorithm);
127 fRootFile->SetCompressionLevel(fCompressionLevel);
128 }
129}
#define QwVerbose
Predefined log drain for verbose messages.
Definition QwLog.h:54
#define QwError
Predefined log drain for errors.
Definition QwLog.h:39
#define QwMessage
Predefined log drain for regular messages.
Definition QwLog.h:49
#define gQwOptions
Definition QwOptions.h:31
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
TString fRootFileStem
ROOT file stem.
TFile * fRootFile
ROOT file.
TString fRootFileDir
ROOT files dir.
Int_t fCompressionAlgorithm
static const Int_t kMaxMapFileSize
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)
void ProcessOptions(QwOptions &options)
Process the configuration options.
Int_t fCompressionLevel
Bool_t fUseTemporaryFile
TString fPermanentName
TMapFile * fMapFile
Map file.
Int_t fUpdateInterval
Bool_t fMakePermanent
Bool_t fEnableMapFile

References QwLog::endl(), fCompressionAlgorithm, fCompressionLevel, fEnableMapFile, fMakePermanent, fMapFile, fPermanentName, fRootFile, fRootFileDir, fRootFileStem, fUpdateInterval, fUseTemporaryFile, QwRunCondition::Get(), QwRunCondition::GetName(), gQwOptions, kMaxMapFileSize, ProcessOptions(), QwError, QwMessage, QwVerbose, and WriteObject().

+ Here is the call graph for this function:

◆ ~QwRootFile()

QwRootFile::~QwRootFile ( )
virtual

Destructor.

Destructor

Definition at line 135 of file QwRootFile.cc.

136{
137 // Keep the file on disk if any trees or histograms have been filled.
138 // Also respect any other requests to keep the file around.
140
141 // Close the map file
142 if (fMapFile) {
143 fMapFile->Close();
144 // TMapFiles may not be deleted
145 fMapFile = 0;
146 }
147
148 // Close the ROOT file.
149 // Rename if permanence is requested, remove otherwise
150 if (fRootFile) {
151 TString rootfilename = fRootFile->GetName();
152
153 fRootFile->Close();
154 delete fRootFile;
155 fRootFile = 0;
156
157 int err;
158 const char* action;
160 if (fMakePermanent) {
161 // Delete existing permanent file first to avoid accumulation
162 if (gSystem->AccessPathName(fPermanentName.Data()) == 0) {
163 remove(fPermanentName.Data());
164 }
165 action = " rename ";
166 err = rename( rootfilename.Data(), fPermanentName.Data() );
167 } else {
168 action = " remove ";
169 err = remove( rootfilename.Data() );
170 }
171 // It'd be proper to "extern int errno" and strerror() here,
172 // but that doesn't seem very C++-ish.
173 if (err) {
174 QwWarning << "Couldn't" << action << rootfilename << QwLog::endl;
175 } else {
176 QwMessage << "Was able to" << action << rootfilename << QwLog::endl;
177 QwMessage << "Root file is " << fPermanentName << QwLog::endl;
178 }
179 }
180 }
181
182 // Delete Qweak ROOT trees
183 std::map< const std::string, std::vector<QwRootTree*> >::iterator map_iter;
184 std::vector<QwRootTree*>::iterator vec_iter;
185 for (map_iter = fTreeByName.begin(); map_iter != fTreeByName.end(); map_iter++) {
186 for (vec_iter = map_iter->second.begin(); vec_iter != map_iter->second.end(); vec_iter++) {
187 delete *vec_iter;
188 }
189 }
190}
#define QwWarning
Predefined log drain for warnings.
Definition QwLog.h:44
Bool_t HasAnyFilled(void)
Search for non-empty trees or histograms in the file.
std::map< const std::string, std::vector< QwRootTree * > > fTreeByName
Tree names, addresses, and types.

References QwLog::endl(), fMakePermanent, fMapFile, fPermanentName, fRootFile, fTreeByName, fUseTemporaryFile, HasAnyFilled(), QwMessage, and QwWarning.

+ Here is the call graph for this function:

◆ QwRootFile() [2/2]

QwRootFile::QwRootFile ( )
private

Private default constructor.

Member Function Documentation

◆ cd()

Bool_t QwRootFile::cd ( const char * path = 0)
inline

Definition at line 1155 of file QwRootFile.h.

1155 {
1156 Bool_t status = kTRUE;
1157 if (fMapFile) status &= fMapFile->cd(path);
1158 if (fRootFile) status &= fRootFile->cd(path);
1159 return status;
1160 }

References fMapFile, and fRootFile.

Referenced by ConstructTreeBranches(), and NewTree().

+ Here is the caller graph for this function:

◆ ClearInMemoryObjects()

void QwRootFile::ClearInMemoryObjects ( TDirectory * dir)
inlineprivate

Recursively clear in-memory objects from a directory tree. This removes objects from the TDirectory's in-memory list without deleting their on-disk representation (keys). Used to prevent RNTupleWriter::Close() from creating duplicate histogram cycles when it internally calls TFile::Write().

Definition at line 1074 of file QwRootFile.h.

1074 {
1075 if (!dir) return;
1076
1077 // First, collect subdirectory names
1078 std::vector<TString> subdirs;
1079 TIter next(dir->GetListOfKeys());
1080 TKey* key;
1081 while ((key = (TKey*)next())) {
1082 if (TString(key->GetClassName()) == "TDirectoryFile") {
1083 subdirs.push_back(key->GetName());
1084 }
1085 }
1086
1087 // Recursively clear subdirectories
1088 for (const auto& name : subdirs) {
1089 TDirectory* sub = dynamic_cast<TDirectory*>(dir->Get(name));
1090 if (sub) ClearInMemoryObjects(sub);
1091 }
1092
1093 // Clear this directory's in-memory object list
1094 // "nodelete" option: remove from list but don't delete the TKey entries
1095 TList* list = dir->GetList();
1096 if (list) {
1097 list->Clear("nodelete");
1098 }
1099 }
void ClearInMemoryObjects(TDirectory *dir)

References ClearInMemoryObjects().

Referenced by ClearInMemoryObjects(), and Close().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Close()

void QwRootFile::Close ( )
inline

Definition at line 1102 of file QwRootFile.h.

1102 {
1103
1104 if (fRootFile) {
1105 // Step 1: Write all trees explicitly
1106 for (auto iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
1107 if (!iter->second.empty() && iter->second.front()) {
1108 TTree* tree = iter->second.front()->GetTree();
1109 if (tree && tree->GetEntries() > 0) {
1110 tree->Write();
1111 }
1112 }
1113 }
1114
1115 // Step 2: Write all in-memory objects (histograms, etc.) to disk
1116 // Use kOverwrite to avoid creating duplicate cycles
1117 fRootFile->Write(0, TObject::kOverwrite);
1118
1119 // Check if we should make the file permanent AFTER writing
1120 // This ensures histograms are on disk and detectable by HasAnyFilled()
1122
1123 // Step 3: CRITICAL FIX for RNTuple histogram duplication
1124 // Clear all in-memory objects from the TFile's directory structure.
1125 // This prevents RNTupleWriter::Close() from re-writing histograms,
1126 // which would create duplicate cycles. The histograms are already
1127 // safely written to disk in Step 2.
1128#ifdef HAS_RNTUPLE_SUPPORT
1129 if (!fNTupleByName.empty()) {
1131 }
1132#endif // HAS_RNTUPLE_SUPPORT
1133 }
1134
1135#ifdef HAS_RNTUPLE_SUPPORT
1136 // Step 4: Close all RNTuples
1137 // Now that in-memory histograms are cleared, the RNTupleWriter destructor
1138 // won't create duplicate histogram cycles when it internally writes to TFile
1139 for (auto& pair : fNTupleByName) {
1140 for (auto& ntuple : pair.second) {
1141 if (ntuple) ntuple->Close();
1142 }
1143 }
1144#endif // HAS_RNTUPLE_SUPPORT
1145
1146 // Step 5: Close the file
1147 if (fRootFile) {
1148 fRootFile->Close();
1149 }
1150
1151 if (fMapFile) fMapFile->Close();
1152 }

References ClearInMemoryObjects(), fMakePermanent, fMapFile, fRootFile, fTreeByName, and HasAnyFilled().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConstructHistograms()

template<class T>
void QwRootFile::ConstructHistograms ( const std::string & name,
T & object )

Construct the histograms of a generic object.

Construct the histogram of a generic object

Parameters
nameName for histogram directory
objectSubsystem array

Definition at line 1620 of file QwRootFile.h.

1621{
1622 // Return if we do not want this histogram information
1623 if (IsHistoDisabled(name)) return;
1624
1625 // Create the histograms in a directory
1626 if (fRootFile) {
1627 std::string type = typeid(object).name();
1628 fDirsByName[name] =
1629 fRootFile->GetDirectory(("/" + name).c_str()) ?
1630 fRootFile->GetDirectory(("/" + name).c_str()) :
1631 fRootFile->GetDirectory("/")->mkdir(name.c_str());
1632 fDirsByType[type].push_back(name);
1633
1634 object.ConstructHistograms(fDirsByName[name]);
1635 }
1636
1637 // No support for directories in a map file
1638 if (fMapFile) {
1639 QwMessage << "QwRootFile::ConstructHistograms::detectors address "
1640 << &object
1641 << " and its name " << name
1642 << QwLog::endl;
1643
1644 std::string type = typeid(object).name();
1645 fDirsByName[name] = fMapFile->GetDirectory()->mkdir(name.c_str());
1646 fDirsByType[type].push_back(name);
1647 //object.ConstructHistograms(fDirsByName[name]);
1648 object.ConstructHistograms();
1649 }
1650}
std::map< const std::string, std::vector< std::string > > fDirsByType
std::map< const std::string, TDirectory * > fDirsByName
Directories.
bool IsHistoDisabled(const std::string &name)
Does this histogram directory match a disabled histogram directory?

References QwLog::endl(), fDirsByName, fDirsByType, fMapFile, fRootFile, IsHistoDisabled(), and QwMessage.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConstructIndices()

void QwRootFile::ConstructIndices ( const std::string & from,
const std::string & to,
bool reverse = true )
inline

Construct indices from one tree to another tree.

Construct the indices from one tree to another tree, and optionally in reverse as well.

Parameters
fromName of tree where index will be created
toName of tree to which index will point
reverseFlag to create indices in both direction

Definition at line 1348 of file QwRootFile.h.

1349{
1350 // Return if we do not want this tree information
1351 if (IsTreeDisabled(from)) return;
1352 if (IsTreeDisabled(to)) return;
1353
1354 // If the trees are defined
1355 if (fTreeByName.count(from) > 0 && fTreeByName.count(to) > 0) {
1356
1357 // Construct index from the first tree to the second tree
1358 fTreeByName[from].front()->ConstructIndexTo(fTreeByName[to].front());
1359
1360 // Construct index from the second tree back to the first tree
1361 if (reverse)
1362 fTreeByName[to].front()->ConstructIndexTo(fTreeByName[from].front());
1363 }
1364}
bool IsTreeDisabled(const std::string &name)
Does this tree name match a disabled tree name?

References fTreeByName, and IsTreeDisabled().

+ Here is the call graph for this function:

◆ ConstructObjects()

template<class T>
void QwRootFile::ConstructObjects ( const std::string & name,
T & object )

Construct the histograms of a generic object.

Construct the objects directory of a generic object

Parameters
nameName for objects directory
objectSubsystem array

Definition at line 1586 of file QwRootFile.h.

1587{
1588 // Create the objects in a directory
1589 if (fRootFile) {
1590 std::string type = typeid(object).name();
1591 fDirsByName[name] =
1592 fRootFile->GetDirectory(("/" + name).c_str()) ?
1593 fRootFile->GetDirectory(("/" + name).c_str()) :
1594 fRootFile->GetDirectory("/")->mkdir(name.c_str());
1595 fDirsByType[type].push_back(name);
1596 object.ConstructObjects(fDirsByName[name]);
1597 }
1598
1599 // No support for directories in a map file
1600 if (fMapFile) {
1601 QwMessage << "QwRootFile::ConstructObjects::detectors address "
1602 << &object
1603 << " and its name " << name
1604 << QwLog::endl;
1605
1606 std::string type = typeid(object).name();
1607 fDirsByName[name] = fMapFile->GetDirectory()->mkdir(name.c_str());
1608 fDirsByType[type].push_back(name);
1609 object.ConstructObjects();
1610 }
1611}

References QwLog::endl(), fDirsByName, fDirsByType, fMapFile, fRootFile, and QwMessage.

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConstructTreeBranches()

template<class T>
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

Parameters
nameName for tree
descDescription for tree
objectSubsystem array
prefixPrefix for the tree

Definition at line 1374 of file QwRootFile.h.

1379{
1380 // Return if we do not want this tree information
1381 if (IsTreeDisabled(name)) return;
1382
1383 // Pointer to new tree
1384 QwRootTree* tree = 0;
1385
1386 // If the tree does not exist yet, create it
1387 if (fTreeByName.count(name) == 0) {
1388
1389 // Go to top level directory
1390
1391 this->cd();
1392
1393 // New tree with name, description, object, prefix
1394 tree = new QwRootTree(name, desc, object, prefix);
1395
1396 // Settings only relevant for new trees
1397 if (name == "evt")
1399 else if (name == "mul")
1401
1402 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
1403 tree->SetAutoFlush(fAutoFlush);
1404 #endif
1405 tree->SetAutoSave(fAutoSave);
1408
1409 if (fCircularBufferSize > 0)
1411
1412 } else {
1413
1414 // New tree based on existing tree
1415 tree = new QwRootTree(fTreeByName[name].front(), object, prefix);
1416 }
1417
1418 // Add the branches to the list of trees by name, object, type
1419 const void* addr = static_cast<const void*>(&object);
1420 const std::type_index type = typeid(object);
1421 fTreeByName[name].push_back(tree);
1422 fTreeByAddr[addr].push_back(tree);
1423 fTreeByType[type].push_back(tree);
1424}
void SetAutoFlush(Long64_t autoflush=30000000)
Set autoflush size.
Definition QwRootFile.h:583
void SetCircular(Long64_t buff=100000)
Definition QwRootFile.h:603
void SetMaxTreeSize(Long64_t maxsize=1900000000)
Set maximum tree size.
Definition QwRootFile.h:577
void SetAutoSave(Long64_t autosave=300000000)
Set autosave size.
Definition QwRootFile.h:591
void SetBasketSize(Int_t basketsize=16000)
Set basket size.
Definition QwRootFile.h:597
void SetPrescaling(UInt_t num_to_save, UInt_t num_to_skip)
Set tree prescaling parameters.
Definition QwRootFile.h:563
Int_t fBasketSize
Bool_t cd(const char *path=0)
UInt_t fNumHelEventsToSkip
Int_t fAutoSave
UInt_t fNumMpsEventsToSave
std::map< const std::type_index, std::vector< QwRootTree * > > fTreeByType
UInt_t fNumHelEventsToSave
Int_t fAutoFlush
UInt_t fCircularBufferSize
std::map< const void *, std::vector< QwRootTree * > > fTreeByAddr
static const Long64_t kMaxTreeSize
Maximum tree size.
UInt_t fNumMpsEventsToSkip
Prescaling of events written to tree.

References cd(), fAutoFlush, fAutoSave, fBasketSize, fCircularBufferSize, fNumHelEventsToSave, fNumHelEventsToSkip, fNumMpsEventsToSave, fNumMpsEventsToSkip, fTreeByAddr, fTreeByName, fTreeByType, IsTreeDisabled(), kMaxTreeSize, QwRootTree::SetAutoFlush(), QwRootTree::SetAutoSave(), QwRootTree::SetBasketSize(), QwRootTree::SetCircular(), QwRootTree::SetMaxTreeSize(), and QwRootTree::SetPrescaling().

Referenced by QwExtractor::ConstructTreeBranches(), VQwDataHandler::ConstructTreeBranches(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DefineOptions()

void QwRootFile::DefineOptions ( QwOptions & options)
static

Define the configuration options.

Defines configuration options using QwOptions functionality.

Parameters
optionsOptions object

Definition at line 196 of file QwRootFile.cc.

197{
198 // Define the ROOT files directory
199 options.AddOptions("Default options")
200 ("rootfiles", po::value<std::string>()->default_value(fDefaultRootFileDir),
201 "directory of the output ROOT files");
202
203 // Define the ROOT filename stem
204 options.AddOptions("Default options")
205 ("rootfile-stem", po::value<std::string>()->default_value(fDefaultRootFileStem),
206 "stem of the output ROOT filename");
207
208 // Define the memory map option
209 options.AddOptions()
210 ("enable-mapfile", po::value<bool>()->default_bool_value(false),
211 "enable output to memory-mapped file\n(likely requires circular-buffer too)");
212 options.AddOptions()
213 ("write-temporary-rootfiles", po::value<bool>()->default_bool_value(true),
214 "When writing ROOT files, use the PID to create a temporary filename");
215
216 // Define the histogram and tree options
217 options.AddOptions("ROOT output options")
218 ("disable-tree", po::value<std::vector<std::string>>()->composing(),
219 "disable output to tree regex");
220 options.AddOptions("ROOT output options")
221 ("disable-trees", po::value<bool>()->default_bool_value(false),
222 "disable output to all trees");
223 options.AddOptions("ROOT output options")
224 ("disable-histos", po::value<bool>()->default_bool_value(false),
225 "disable output to all histograms");
226
227 // Define the helicity window versus helicity pattern options
228 options.AddOptions("ROOT output options")
229 ("disable-mps-tree", po::value<bool>()->default_bool_value(false),
230 "disable helicity window output");
231 options.AddOptions("ROOT output options")
232 ("disable-pair-tree", po::value<bool>()->default_bool_value(false),
233 "disable helicity pairs output");
234 options.AddOptions("ROOT output options")
235 ("disable-hel-tree", po::value<bool>()->default_bool_value(false),
236 "disable helicity pattern output");
237 options.AddOptions("ROOT output options")
238 ("disable-burst-tree", po::value<bool>()->default_bool_value(false),
239 "disable burst tree");
240 options.AddOptions("ROOT output options")
241 ("disable-slow-tree", po::value<bool>()->default_bool_value(false),
242 "disable slow control tree");
243
244#ifdef HAS_RNTUPLE_SUPPORT
245 // Define the RNTuple options
246 options.AddOptions("ROOT output options")
247 ("enable-rntuples", po::value<bool>()->default_bool_value(false),
248 "enable RNTuple output");
249#endif // HAS_RNTUPLE_SUPPORT
250
251 // Define the tree output prescaling options
252 options.AddOptions("ROOT output options")
253 ("num-mps-accepted-events", po::value<int>()->default_value(0),
254 "number of accepted consecutive MPS events");
255 options.AddOptions("ROOT output options")
256 ("num-mps-discarded-events", po::value<int>()->default_value(0),
257 "number of discarded consecutive MPS events");
258 options.AddOptions("ROOT output options")
259 ("num-hel-accepted-events", po::value<int>()->default_value(0),
260 "number of accepted consecutive pattern events");
261 options.AddOptions("ROOT output options")
262 ("num-hel-discarded-events", po::value<int>()->default_value(0),
263 "number of discarded consecutive pattern events");
264 options.AddOptions("ROOT output options")
265 ("mapfile-update-interval", po::value<int>()->default_value(-1),
266 "Events between a map file update");
267
268 // Define the autoflush and autosave option (default values by ROOT)
269 options.AddOptions("ROOT performance options")
270 ("autoflush", po::value<int>()->default_value(0),
271 "TTree autoflush");
272 options.AddOptions("ROOT performance options")
273 ("autosave", po::value<int>()->default_value(300000000),
274 "TTree autosave");
275 options.AddOptions("ROOT performance options")
276 ("basket-size", po::value<int>()->default_value(16000),
277 "TTree basket size");
278 options.AddOptions("ROOT performance options")
279 ("circular-buffer", po::value<int>()->default_value(0),
280 "TTree circular buffer");
281 options.AddOptions("ROOT performance options")
282 ("compression-algorithm", po::value<int>()->default_value(1),
283 "TFile compression algorithm (1=ZLIB, 2=LZMA, 4=LZ4, 5=ZSTD, default=1 ZLIB)");
284 options.AddOptions("ROOT performance options")
285 ("compression-level", po::value<int>()->default_value(1),
286 "TFile compression level (default = 1, no compression = 0)");
287 options.AddOptions("ROOT performance options")
288 ("rntuple-compression-algorithm", po::value<int>()->default_value(4),
289 "RNTuple compression algorithm (1=ZLIB, 2=LZMA, 4=LZ4, 5=ZSTD, default=4 LZ4)");
290 options.AddOptions("ROOT performance options")
291 ("rntuple-compression-level", po::value<int>()->default_value(0),
292 "RNTuple compression level (0-12, default=0 for maximum performance)");
293}
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
Definition QwOptions.h:170
static std::string fDefaultRootFileDir
Default ROOT files dir.
static std::string fDefaultRootFileStem
Default ROOT file stem.

References QwOptions::AddOptions(), fDefaultRootFileDir, and fDefaultRootFileStem.

Referenced by QwOptions::DefineOptions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DisableHisto()

void QwRootFile::DisableHisto ( const TString & regexp)
inlineprivate

Add regexp to list of disabled histogram directories.

Definition at line 1238 of file QwRootFile.h.

1238 {
1239 fDisabledHistos.push_back(regexp);
1240 }
std::vector< TPRegexp > fDisabledHistos

References fDisabledHistos.

Referenced by ProcessOptions().

+ Here is the caller graph for this function:

◆ DisableTree()

void QwRootFile::DisableTree ( const TString & regexp)
inlineprivate

Add regexp to list of disabled trees names.

Definition at line 1228 of file QwRootFile.h.

1228 {
1229 fDisabledTrees.push_back(regexp);
1230 }
std::vector< TPRegexp > fDisabledTrees
List of excluded trees.

References fDisabledTrees.

Referenced by ProcessOptions().

+ Here is the caller graph for this function:

◆ FillHistograms()

template<class T>
void QwRootFile::FillHistograms ( T & object)
inline

Fill histograms of the subsystem array.

Definition at line 917 of file QwRootFile.h.

917 {
918 // Update regularly
919 static Int_t update_count = 0;
920 update_count++;
921 if ((fUpdateInterval > 0) && ( update_count % fUpdateInterval == 0)) Update();
922
923 // Debug directory registration
924 std::string type = typeid(object).name();
925 bool hasDir = HasDirByType(object);
926
927 if (! hasDir) return;
928 // Fill histograms
929 object.FillHistograms();
930 }
bool HasDirByType(const T &object)
Is a directory registered for this type.
void Update()

References fUpdateInterval, HasDirByType(), and Update().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillTree()

Int_t QwRootFile::FillTree ( const std::string & name)
inline

Fill the tree with name.

Definition at line 974 of file QwRootFile.h.

974 {
975 if (! HasTreeByName(name)) return 0;
976 else return fTreeByName[name].front()->Fill();
977 }
bool HasTreeByName(const std::string &name)
Is a tree registered for this name.

References fTreeByName, and HasTreeByName().

Referenced by QwExtractor::FillTreeBranches(), VQwDataHandler::FillTreeBranches(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillTreeBranches() [1/2]

template<class T>
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

Parameters
nameName for tree
objectSubsystem array

Definition at line 1433 of file QwRootFile.h.

1436{
1437 // If this name has no registered trees
1438 if (! HasTreeByName(name)) return;
1439 // If this type has no registered trees
1440 if (! HasTreeByType(object)) return;
1441
1442 // Get the address of the object
1443 const void* addr = static_cast<const void*>(&object);
1444
1445 // Fill the trees with the correct address
1446 for (size_t tree = 0; tree < fTreeByAddr[addr].size(); tree++) {
1447 if (fTreeByAddr[addr].at(tree)->GetName() == name) {
1448 fTreeByAddr[addr].at(tree)->FillTreeBranches(object);
1449 }
1450 }
1451}
bool HasTreeByType(const T &object)
Is a tree registered for this type.

References fTreeByAddr, HasTreeByName(), and HasTreeByType().

Referenced by QwExtractor::FillTreeBranches(), VQwDataHandler::FillTreeBranches(), and main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillTreeBranches() [2/2]

template<class T>
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

Parameters
objectSubsystem array

Definition at line 1459 of file QwRootFile.h.

1461{
1462 // If this address has no registered trees
1463 if (! HasTreeByAddr(object)) return;
1464
1465 // Get the address of the object
1466 const void* addr = static_cast<const void*>(&object);
1467
1468 // Fill the trees with the correct address
1469 for (size_t tree = 0; tree < fTreeByAddr[addr].size(); tree++) {
1470 fTreeByAddr[addr].at(tree)->FillTreeBranches(object);
1471 }
1472}
bool HasTreeByAddr(const T &object)
Is a tree registered for this object.

References fTreeByAddr, and HasTreeByAddr().

+ Here is the call graph for this function:

◆ FillTrees()

Int_t QwRootFile::FillTrees ( )
inline

Fill all registered trees.

Definition at line 980 of file QwRootFile.h.

980 {
981 // Loop over all registered tree names
982 Int_t retval = 0;
983 std::map< const std::string, std::vector<QwRootTree*> >::iterator iter;
984 for (iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
985 retval += iter->second.front()->Fill();
986 }
987 return retval;
988 }

References fTreeByName.

◆ GetTree()

TTree * QwRootFile::GetTree ( const std::string & name)
inline

Get the tree with name.

Definition at line 968 of file QwRootFile.h.

968 {
969 if (! HasTreeByName(name)) return 0;
970 else return fTreeByName[name].front()->GetTree();
971 }

References fTreeByName, and HasTreeByName().

Referenced by QwCorrelator::ConstructTreeBranches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasAnyFilled() [1/2]

Bool_t QwRootFile::HasAnyFilled ( TDirectory * d)
private

Definition at line 378 of file QwRootFile.cc.

378 {
379 if (!d) {
380
381 return false;
382 }
383
384 // First check if any in-memory trees have been filled
385 for (auto& pair : fTreeByName) {
386 for (auto& tree : pair.second) {
387 if (tree && tree->GetTree()) {
388 Long64_t entries = tree->GetTree()->GetEntries();
389 if (entries > 0) {
390
391 return true;
392 }
393 }
394 }
395 }
396
397#ifdef HAS_RNTUPLE_SUPPORT
398 // Then check if any RNTuples have been filled
399 for (auto& pair : fNTupleByName) {
400 for (auto& ntuple : pair.second) {
401 if (ntuple && ntuple->fCurrentEvent > 0) {
402
403 return true;
404 }
405 }
406 }
407#endif // HAS_RNTUPLE_SUPPORT
408
409 TList* l = d->GetListOfKeys();
410
411
412 for( int i=0; i < l->GetEntries(); ++i) {
413 const char* name = l->At(i)->GetName();
414 TObject* obj = d->FindObjectAny(name);
415
416
417
418 // Objects which can't be found don't count.
419 if (!obj) {
420
421 continue;
422 }
423
424 // Lists of parameter files, map files, and job conditions don't count.
425 if ( TString(name).Contains("parameter_file") ) {
426
427 continue;
428 }
429 if ( TString(name).Contains("mapfile") ) {
430 continue;
431 }
432 if ( TString(name).Contains("_condition") ) {
433 continue;
434 }
435 // The EPICS tree doesn't count
436 if ( TString(name).Contains("slow") ) {
437 continue;
438 }
439
440 // Recursively check subdirectories.
441 if (obj->IsA()->InheritsFrom( "TDirectory" )) {
442 if (this->HasAnyFilled( (TDirectory*)obj )) return true;
443 }
444
445 if (obj->IsA()->InheritsFrom( "TTree" )) {
446 Long64_t entries = ((TTree*) obj)->GetEntries();
447 if ( entries ) return true;
448 }
449
450 if (obj->IsA()->InheritsFrom( "TH1" )) {
451 Double_t entries = ((TH1*) obj)->GetEntries();
452 if ( entries ) return true;
453 }
454 }
455 return false;
456}

References fTreeByName, and HasAnyFilled().

+ Here is the call graph for this function:

◆ HasAnyFilled() [2/2]

Bool_t QwRootFile::HasAnyFilled ( void )
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 375 of file QwRootFile.cc.

375 {
376 return this->HasAnyFilled(fRootFile);
377}

References fRootFile, and HasAnyFilled().

Referenced by Close(), HasAnyFilled(), HasAnyFilled(), and ~QwRootFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasDirByName()

bool QwRootFile::HasDirByName ( const std::string & name)
inlineprivate

Is a tree registered for this name.

Definition at line 1314 of file QwRootFile.h.

1314 {
1315 if (fDirsByName.count(name) == 0) return false;
1316 else return true;
1317 }

References fDirsByName.

◆ HasDirByType()

template<class T>
bool QwRootFile::HasDirByType ( const T & object)
inlineprivate

Is a directory registered for this type.

Definition at line 1320 of file QwRootFile.h.

1320 {
1321 std::string type = typeid(object).name();
1322 if (fDirsByType.count(type) == 0) return false;
1323 else return true;
1324 }

References fDirsByType.

Referenced by FillHistograms().

+ Here is the caller graph for this function:

◆ HasTreeByAddr()

template<class T>
bool QwRootFile::HasTreeByAddr ( const T & object)
inlineprivate

Is a tree registered for this object.

Definition at line 1281 of file QwRootFile.h.

1281 {
1282 const void* addr = static_cast<const void*>(&object);
1283 if (fTreeByAddr.count(addr) == 0) return false;
1284 else return true;
1285 }

References fTreeByAddr.

Referenced by FillTreeBranches().

+ Here is the caller graph for this function:

◆ HasTreeByName()

bool QwRootFile::HasTreeByName ( const std::string & name)
inlineprivate

Is a tree registered for this name.

Definition at line 1268 of file QwRootFile.h.

1268 {
1269 if (fTreeByName.count(name) == 0) return false;
1270 else return true;
1271 }

References fTreeByName.

Referenced by FillTree(), FillTreeBranches(), GetTree(), and NewTree().

+ Here is the caller graph for this function:

◆ HasTreeByType()

template<class T>
bool QwRootFile::HasTreeByType ( const T & object)
inlineprivate

Is a tree registered for this type.

Definition at line 1274 of file QwRootFile.h.

1274 {
1275 const std::type_index type = typeid(object);
1276 if (fTreeByType.count(type) == 0) return false;
1277 else return true;
1278 }

References fTreeByType.

Referenced by FillTreeBranches().

+ Here is the caller graph for this function:

◆ IsHistoDisabled()

bool QwRootFile::IsHistoDisabled ( const std::string & name)
inlineprivate

Does this histogram directory match a disabled histogram directory?

Definition at line 1242 of file QwRootFile.h.

1242 {
1243 for (size_t i = 0; i < fDisabledHistos.size(); i++)
1244 if (fDisabledHistos.at(i).Match(name)) return true;
1245 return false;
1246 }

References fDisabledHistos.

Referenced by ConstructHistograms().

+ Here is the caller graph for this function:

◆ IsMapFile()

Bool_t QwRootFile::IsMapFile ( ) const
inline

Is the map file active?

Definition at line 876 of file QwRootFile.h.

876{ return (fMapFile); };

References fMapFile.

◆ IsRootFile()

Bool_t QwRootFile::IsRootFile ( ) const
inline

Is the ROOT file active?

Definition at line 874 of file QwRootFile.h.

874{ return (fRootFile); };

References fRootFile.

◆ IsTreeDisabled()

bool QwRootFile::IsTreeDisabled ( const std::string & name)
inlineprivate

Does this tree name match a disabled tree name?

Definition at line 1232 of file QwRootFile.h.

1232 {
1233 for (size_t i = 0; i < fDisabledTrees.size(); i++)
1234 if (fDisabledTrees.at(i).Match(name)) return true;
1235 return false;
1236 }

References fDisabledTrees.

Referenced by ConstructIndices(), ConstructTreeBranches(), and NewTree().

+ Here is the caller graph for this function:

◆ ls()

void QwRootFile::ls ( )
inline

Definition at line 1066 of file QwRootFile.h.

1066{ if (fMapFile) fMapFile->ls(); if (fRootFile) fRootFile->ls(); }

References fMapFile, and fRootFile.

◆ Map()

void QwRootFile::Map ( )
inline

Definition at line 1067 of file QwRootFile.h.

1067{ if (fRootFile) fRootFile->Map(); }

References fRootFile.

◆ mkdir()

TDirectory * QwRootFile::mkdir ( const char * name,
const char * title = "" )
inline

Definition at line 1163 of file QwRootFile.h.

1163 {
1164 // TMapFile has no support for mkdir
1165 if (fRootFile) return fRootFile->mkdir(name, title);
1166 else return 0;
1167 }

References fRootFile.

◆ NewTree()

void QwRootFile::NewTree ( const std::string & name,
const std::string & desc )
inline

Create a new tree with name and description.

Definition at line 934 of file QwRootFile.h.

934 {
935 if (IsTreeDisabled(name)) return;
936 this->cd();
937 QwRootTree *tree = 0;
938 if (! HasTreeByName(name)) {
939 tree = new QwRootTree(name,desc);
940 } else {
941 tree = new QwRootTree(fTreeByName[name].front());
942 }
943 fTreeByName[name].push_back(tree);
944 }

References cd(), fTreeByName, HasTreeByName(), and IsTreeDisabled().

Referenced by QwCorrelator::ConstructTreeBranches().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Print()

void QwRootFile::Print ( )
inline

Definition at line 1065 of file QwRootFile.h.

1065{ if (fMapFile) fMapFile->Print(); if (fRootFile) fRootFile->Print(); }

References fMapFile, and fRootFile.

◆ PrintDirs()

void QwRootFile::PrintDirs ( ) const
inline

Print registered histogram directories.

Definition at line 1026 of file QwRootFile.h.

1026 {
1027 QwMessage << "Dirs: " << QwLog::endl;
1028 // Loop ove rall registered directories
1029 std::map< const std::string, TDirectory* >::const_iterator iter;
1030 for (iter = fDirsByName.begin(); iter != fDirsByName.end(); iter++) {
1031 QwMessage << iter->first << QwLog::endl;
1032 }
1033 }

References QwLog::endl(), fDirsByName, and QwMessage.

+ Here is the call graph for this function:

◆ PrintTrees()

void QwRootFile::PrintTrees ( ) const
inline

Print registered trees.

Definition at line 1011 of file QwRootFile.h.

1011 {
1012 QwMessage << "Trees: " << QwLog::endl;
1013 // Loop over all registered tree names
1014 std::map< const std::string, std::vector<QwRootTree*> >::const_iterator iter;
1015 for (iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
1016 QwMessage << iter->first << ": " << iter->second.size()
1017 << " objects registered" << QwLog::endl;
1018 // Loop over all registered objects for this tree
1019 std::vector<QwRootTree*>::const_iterator tree;
1020 for (tree = iter->second.begin(); tree != iter->second.end(); tree++) {
1021 (*tree)->Print();
1022 }
1023 }
1024 }

References QwLog::endl(), fTreeByName, and QwMessage.

+ Here is the call graph for this function:

◆ ProcessOptions()

void QwRootFile::ProcessOptions ( QwOptions & options)

Process the configuration options.

Parse the configuration options and store in class fields

Parameters
optionsOptions object

Definition at line 300 of file QwRootFile.cc.

301{
302 // Option 'rootfiles' to specify ROOT files dir
303 fRootFileDir = TString(options.GetValue<std::string>("rootfiles"));
304
305 // Option 'root-stem' to specify ROOT file stem
306 fRootFileStem = TString(options.GetValue<std::string>("rootfile-stem"));
307
308 // Option 'mapfile' to enable memory-mapped ROOT file
309 fEnableMapFile = options.GetValue<bool>("enable-mapfile");
310#ifndef QW_ENABLE_MAPFILE
311 if( fEnableMapFile ) {
313 QwWarning << "QwRootFile::ProcessOptions: "
314 << "The 'enable-mapfile' flag is not supported by the ROOT "
315 "version with which this app is built. Disabling it."
316 << QwLog::endl;
317 fEnableMapFile = false;
318 }
319#endif
320 fUseTemporaryFile = options.GetValue<bool>("write-temporary-rootfiles");
321
322#ifdef HAS_RNTUPLE_SUPPORT
323 // Option 'enable-rntuples' to enable RNTuple output
324 fEnableRNTuples = options.GetValue<bool>("enable-rntuples");
325#endif // HAS_RNTUPLE_SUPPORT
326
327 // Options 'disable-trees' and 'disable-histos' for disabling
328 // tree and histogram output
329 auto v = options.GetValueVector<std::string>("disable-tree");
330 std::for_each(v.begin(), v.end(), [&](const std::string& s){ this->DisableTree(s); });
331 if (options.GetValue<bool>("disable-trees")) DisableTree(".*");
332 if (options.GetValue<bool>("disable-histos")) DisableHisto(".*");
333
334 // Options 'disable-mps' and 'disable-hel' for disabling
335 // helicity window and helicity pattern output
336 if (options.GetValue<bool>("disable-mps-tree")) DisableTree("^evt$");
337 if (options.GetValue<bool>("disable-pair-tree")) DisableTree("^pr$");
338 if (options.GetValue<bool>("disable-hel-tree")) DisableTree("^mul$");
339 if (options.GetValue<bool>("disable-burst-tree")) DisableTree("^burst$");
340 if (options.GetValue<bool>("disable-slow-tree")) DisableTree("^slow$");
341
342 // Options 'num-accepted-events' and 'num-discarded-events' for
343 // prescaling of the tree output
344 fNumMpsEventsToSave = options.GetValue<int>("num-mps-accepted-events");
345 fNumMpsEventsToSkip = options.GetValue<int>("num-mps-discarded-events");
346 fNumHelEventsToSave = options.GetValue<int>("num-mps-accepted-events");
347 fNumHelEventsToSkip = options.GetValue<int>("num-mps-discarded-events");
348
349 // Update interval for the map file
350 fCircularBufferSize = options.GetValue<int>("circular-buffer");
351 fUpdateInterval = options.GetValue<int>("mapfile-update-interval");
352 fCompressionAlgorithm = options.GetValue<int>("compression-algorithm");
353 fCompressionLevel = options.GetValue<int>("compression-level");
354 fRNTupleCompressionAlgorithm = options.GetValue<int>("rntuple-compression-algorithm");
355 fRNTupleCompressionLevel = options.GetValue<int>("rntuple-compression-level");
356 fBasketSize = options.GetValue<int>("basket-size");
357
358 // Autoflush and autosave
359 fAutoFlush = options.GetValue<int>("autoflush");
360 if ((ROOT_VERSION_CODE < ROOT_VERSION(5,26,00)) && fAutoFlush != -30000000){
362 QwWarning << "QwRootFile::ProcessOptions: "
363 << "The 'autoflush' flag is not supported by ROOT version "
364 << ROOT_RELEASE
365 << QwLog::endl;
366 }
367 fAutoSave = options.GetValue<int>("autosave");
368 return;
369}
std::vector< T > GetValueVector(const std::string &key)
Get a list of templated values.
Definition QwOptions.h:249
T GetValue(const std::string &key)
Get a templated value.
Definition QwOptions.h:236
void DisableTree(const TString &regexp)
Add regexp to list of disabled trees names.
void DisableHisto(const TString &regexp)
Add regexp to list of disabled histogram directories.
Int_t fRNTupleCompressionLevel
Int_t fRNTupleCompressionAlgorithm

References DisableHisto(), DisableTree(), QwLog::endl(), fAutoFlush, fAutoSave, fBasketSize, fCircularBufferSize, fCompressionAlgorithm, fCompressionLevel, fEnableMapFile, fNumHelEventsToSave, fNumHelEventsToSkip, fNumMpsEventsToSave, fNumMpsEventsToSkip, fRNTupleCompressionAlgorithm, fRNTupleCompressionLevel, fRootFileDir, fRootFileStem, fUpdateInterval, fUseTemporaryFile, QwOptions::GetValue(), QwOptions::GetValueVector(), QwMessage, and QwWarning.

Referenced by QwRootFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetDefaultRootFileDir()

static void QwRootFile::SetDefaultRootFileDir ( const std::string & dir)
inlinestatic

Set default ROOT files dir.

Definition at line 864 of file QwRootFile.h.

864 {
866 }

References fDefaultRootFileDir.

◆ SetDefaultRootFileStem()

static void QwRootFile::SetDefaultRootFileStem ( const std::string & stem)
inlinestatic

Set default ROOT file stem.

Definition at line 868 of file QwRootFile.h.

868 {
870 }

References fDefaultRootFileStem.

◆ Update()

void QwRootFile::Update ( )
inline

Definition at line 1047 of file QwRootFile.h.

1047 {
1048 if (fMapFile) {
1049 QwMessage << "TMapFile memory resident size: "
1050 << ((int*)fMapFile->GetBreakval() - (int*)fMapFile->GetBaseAddr()) *
1051 4 / sizeof(int32_t) / 1024 / 1024 << " MiB"
1052 << QwLog::endl;
1053 fMapFile->Update();
1054 }else{
1055 // this option will allow for reading the tree during write
1056 Long64_t nBytes(0);
1057 for (auto iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++)
1058 nBytes += iter->second.front()->AutoSave("SaveSelf");
1059
1060 QwMessage << "TFile saved: "
1061 << nBytes/1000000 << "MB (inaccurate number)" //FIXME this calculation is inaccurate
1062 << QwLog::endl;
1063 }
1064 }

References QwLog::endl(), fMapFile, fTreeByName, and QwMessage.

Referenced by FillHistograms().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Write()

Int_t QwRootFile::Write ( const char * name = 0,
Int_t option = 0,
Int_t bufsize = 0 )
inline

Definition at line 1170 of file QwRootFile.h.

1170 {
1171 Int_t retval = 0;
1172 // TMapFile has no support for Write
1173 if (fRootFile) retval = fRootFile->Write(name, option, bufsize);
1174 return retval;
1175 }

References fRootFile.

Referenced by main().

+ Here is the caller graph for this function:

◆ WriteObject()

template<class T>
Int_t QwRootFile::WriteObject ( const T * obj,
const char * name,
Option_t * option = "",
Int_t bufsize = 0 )
inline

Write any object to the ROOT file (only valid for TFile)

Definition at line 1038 of file QwRootFile.h.

1038 {
1039 Int_t retval = 0;
1040 // TMapFile has no support for WriteObject
1041 if (fRootFile) retval = fRootFile->WriteObject(obj,name,option,bufsize);
1042 return retval;
1043 }

References fRootFile.

Referenced by QwRootFile().

+ Here is the caller graph for this function:

◆ WriteParamFileList()

template<class T>
Int_t QwRootFile::WriteParamFileList ( const TString & name,
T & object )

Definition at line 1654 of file QwRootFile.h.

1655{
1656 Int_t retval = 0;
1657 if (fRootFile) {
1658 TList *param_list = (TList*) fRootFile->FindObjectAny(name);
1659 if (not param_list) {
1660 retval = fRootFile->WriteObject(object.GetParamFileNameList(name), name);
1661 }
1662 }
1663 return retval;
1664}

References fRootFile.

Referenced by main().

+ Here is the caller graph for this function:

Field Documentation

◆ fAutoFlush

Int_t QwRootFile::fAutoFlush
private

Definition at line 1216 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fAutoSave

Int_t QwRootFile::fAutoSave
private

Definition at line 1217 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fBasketSize

Int_t QwRootFile::fBasketSize
private

Definition at line 1215 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fCircularBufferSize

UInt_t QwRootFile::fCircularBufferSize
private

Definition at line 1334 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fCompressionAlgorithm

Int_t QwRootFile::fCompressionAlgorithm
private

Definition at line 1211 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fCompressionLevel

Int_t QwRootFile::fCompressionLevel
private

Definition at line 1212 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fCurrentEvent

UInt_t QwRootFile::fCurrentEvent
private

Definition at line 1335 of file QwRootFile.h.

◆ fDefaultRootFileDir

std::string QwRootFile::fDefaultRootFileDir = "."
staticprivate

Default ROOT files dir.

Definition at line 1190 of file QwRootFile.h.

Referenced by DefineOptions(), and SetDefaultRootFileDir().

◆ fDefaultRootFileStem

std::string QwRootFile::fDefaultRootFileStem = "Qweak_"
staticprivate

Default ROOT file stem.

Definition at line 1195 of file QwRootFile.h.

Referenced by DefineOptions(), and SetDefaultRootFileStem().

◆ fDirsByName

std::map< const std::string, TDirectory* > QwRootFile::fDirsByName
private

Directories.

Definition at line 1310 of file QwRootFile.h.

Referenced by ConstructHistograms(), ConstructObjects(), HasDirByName(), and PrintDirs().

◆ fDirsByType

std::map< const std::string, std::vector<std::string> > QwRootFile::fDirsByType
private

Definition at line 1311 of file QwRootFile.h.

Referenced by ConstructHistograms(), ConstructObjects(), and HasDirByType().

◆ fDisabledHistos

std::vector< TPRegexp > QwRootFile::fDisabledHistos
private

Definition at line 1225 of file QwRootFile.h.

Referenced by DisableHisto(), and IsHistoDisabled().

◆ fDisabledTrees

std::vector< TPRegexp > QwRootFile::fDisabledTrees
private

List of excluded trees.

Definition at line 1224 of file QwRootFile.h.

Referenced by DisableTree(), and IsTreeDisabled().

◆ fEnableMapFile

Bool_t QwRootFile::fEnableMapFile
private

Definition at line 1209 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fMakePermanent

Bool_t QwRootFile::fMakePermanent
private

Definition at line 1200 of file QwRootFile.h.

Referenced by Close(), QwRootFile(), and ~QwRootFile().

◆ fMapFile

TMapFile* QwRootFile::fMapFile
private

◆ fNumHelEventsToSave

UInt_t QwRootFile::fNumHelEventsToSave
private

Definition at line 1333 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fNumHelEventsToSkip

UInt_t QwRootFile::fNumHelEventsToSkip
private

Definition at line 1332 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fNumMpsEventsToSave

UInt_t QwRootFile::fNumMpsEventsToSave
private

Definition at line 1331 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fNumMpsEventsToSkip

UInt_t QwRootFile::fNumMpsEventsToSkip
private

Prescaling of events written to tree.

Definition at line 1330 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fPermanentName

TString QwRootFile::fPermanentName
private

While the file is open, give it a temporary filename. Perhaps change to a permanent name when closing the file.

Definition at line 1199 of file QwRootFile.h.

Referenced by QwRootFile(), and ~QwRootFile().

◆ fRNTupleCompressionAlgorithm

Int_t QwRootFile::fRNTupleCompressionAlgorithm
private

Definition at line 1213 of file QwRootFile.h.

Referenced by ProcessOptions().

◆ fRNTupleCompressionLevel

Int_t QwRootFile::fRNTupleCompressionLevel
private

Definition at line 1214 of file QwRootFile.h.

Referenced by ProcessOptions().

◆ fRootFile

TFile* QwRootFile::fRootFile
private

◆ fRootFileDir

TString QwRootFile::fRootFileDir
private

ROOT files dir.

Definition at line 1188 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fRootFileStem

TString QwRootFile::fRootFileStem
private

ROOT file stem.

Definition at line 1193 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fTreeByAddr

std::map< const void* , std::vector<QwRootTree*> > QwRootFile::fTreeByAddr
private

◆ fTreeByName

std::map< const std::string, std::vector<QwRootTree*> > QwRootFile::fTreeByName
private

◆ fTreeByType

std::map< const std::type_index , std::vector<QwRootTree*> > QwRootFile::fTreeByType
private

Definition at line 1254 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and HasTreeByType().

◆ fUpdateInterval

Int_t QwRootFile::fUpdateInterval
private

Definition at line 1210 of file QwRootFile.h.

Referenced by FillHistograms(), ProcessOptions(), and QwRootFile().

◆ fUseTemporaryFile

Bool_t QwRootFile::fUseTemporaryFile
private

Definition at line 1201 of file QwRootFile.h.

Referenced by ProcessOptions(), QwRootFile(), and ~QwRootFile().

◆ kMaxMapFileSize

const Int_t QwRootFile::kMaxMapFileSize = 0x3fffffff
staticprivate

Definition at line 1339 of file QwRootFile.h.

Referenced by QwRootFile().

◆ kMaxTreeSize

const Long64_t QwRootFile::kMaxTreeSize = 100000000000LL
staticprivate

Maximum tree size.

Definition at line 1338 of file QwRootFile.h.

Referenced by ConstructTreeBranches().


The documentation for this class was generated from the following files: