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 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 833 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 gQwOptions
Definition QwOptions.h:31
#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
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 1136 of file QwRootFile.h.

1136 {
1137 Bool_t status = kTRUE;
1138 if (fMapFile) status &= fMapFile->cd(path);
1139 if (fRootFile) status &= fRootFile->cd(path);
1140 return status;
1141 }

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

1055 {
1056 if (!dir) return;
1057
1058 // First, collect subdirectory names
1059 std::vector<TString> subdirs;
1060 TIter next(dir->GetListOfKeys());
1061 TKey* key;
1062 while ((key = (TKey*)next())) {
1063 if (TString(key->GetClassName()) == "TDirectoryFile") {
1064 subdirs.push_back(key->GetName());
1065 }
1066 }
1067
1068 // Recursively clear subdirectories
1069 for (const auto& name : subdirs) {
1070 TDirectory* sub = dynamic_cast<TDirectory*>(dir->Get(name));
1071 if (sub) ClearInMemoryObjects(sub);
1072 }
1073
1074 // Clear this directory's in-memory object list
1075 // "nodelete" option: remove from list but don't delete the TKey entries
1076 TList* list = dir->GetList();
1077 if (list) {
1078 list->Clear("nodelete");
1079 }
1080 }
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 1083 of file QwRootFile.h.

1083 {
1084
1085 if (fRootFile) {
1086 // Step 1: Write all trees explicitly
1087 for (auto iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
1088 if (!iter->second.empty() && iter->second.front()) {
1089 TTree* tree = iter->second.front()->GetTree();
1090 if (tree && tree->GetEntries() > 0) {
1091 tree->Write();
1092 }
1093 }
1094 }
1095
1096 // Step 2: Write all in-memory objects (histograms, etc.) to disk
1097 // Use kOverwrite to avoid creating duplicate cycles
1098 fRootFile->Write(0, TObject::kOverwrite);
1099
1100 // Check if we should make the file permanent AFTER writing
1101 // This ensures histograms are on disk and detectable by HasAnyFilled()
1103
1104 // Step 3: CRITICAL FIX for RNTuple histogram duplication
1105 // Clear all in-memory objects from the TFile's directory structure.
1106 // This prevents RNTupleWriter::Close() from re-writing histograms,
1107 // which would create duplicate cycles. The histograms are already
1108 // safely written to disk in Step 2.
1109#ifdef HAS_RNTUPLE_SUPPORT
1110 if (!fNTupleByName.empty()) {
1112 }
1113#endif // HAS_RNTUPLE_SUPPORT
1114 }
1115
1116#ifdef HAS_RNTUPLE_SUPPORT
1117 // Step 4: Close all RNTuples
1118 // Now that in-memory histograms are cleared, the RNTupleWriter destructor
1119 // won't create duplicate histogram cycles when it internally writes to TFile
1120 for (auto& pair : fNTupleByName) {
1121 for (auto& ntuple : pair.second) {
1122 if (ntuple) ntuple->Close();
1123 }
1124 }
1125#endif // HAS_RNTUPLE_SUPPORT
1126
1127 // Step 5: Close the file
1128 if (fRootFile) {
1129 fRootFile->Close();
1130 }
1131
1132 if (fMapFile) fMapFile->Close();
1133 }

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

1596{
1597 // Return if we do not want this histogram information
1598 if (IsHistoDisabled(name)) return;
1599
1600 // Create the histograms in a directory
1601 if (fRootFile) {
1602 std::string type = typeid(object).name();
1603 fDirsByName[name] =
1604 fRootFile->GetDirectory(("/" + name).c_str()) ?
1605 fRootFile->GetDirectory(("/" + name).c_str()) :
1606 fRootFile->GetDirectory("/")->mkdir(name.c_str());
1607 fDirsByType[type].push_back(name);
1608
1609 object.ConstructHistograms(fDirsByName[name]);
1610 }
1611
1612 // No support for directories in a map file
1613 if (fMapFile) {
1614 QwMessage << "QwRootFile::ConstructHistograms::detectors address "
1615 << &object
1616 << " and its name " << name
1617 << QwLog::endl;
1618
1619 std::string type = typeid(object).name();
1620 fDirsByName[name] = fMapFile->GetDirectory()->mkdir(name.c_str());
1621 fDirsByType[type].push_back(name);
1622 //object.ConstructHistograms(fDirsByName[name]);
1623 object.ConstructHistograms();
1624 }
1625}
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 1327 of file QwRootFile.h.

1328{
1329 // Return if we do not want this tree information
1330 if (IsTreeDisabled(from)) return;
1331 if (IsTreeDisabled(to)) return;
1332
1333 // If the trees are defined
1334 if (fTreeByName.count(from) > 0 && fTreeByName.count(to) > 0) {
1335
1336 // Construct index from the first tree to the second tree
1337 fTreeByName[from].front()->ConstructIndexTo(fTreeByName[to].front());
1338
1339 // Construct index from the second tree back to the first tree
1340 if (reverse)
1341 fTreeByName[to].front()->ConstructIndexTo(fTreeByName[from].front());
1342 }
1343}
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 1561 of file QwRootFile.h.

1562{
1563 // Create the objects in a directory
1564 if (fRootFile) {
1565 std::string type = typeid(object).name();
1566 fDirsByName[name] =
1567 fRootFile->GetDirectory(("/" + name).c_str()) ?
1568 fRootFile->GetDirectory(("/" + name).c_str()) :
1569 fRootFile->GetDirectory("/")->mkdir(name.c_str());
1570 fDirsByType[type].push_back(name);
1571 object.ConstructObjects(fDirsByName[name]);
1572 }
1573
1574 // No support for directories in a map file
1575 if (fMapFile) {
1576 QwMessage << "QwRootFile::ConstructObjects::detectors address "
1577 << &object
1578 << " and its name " << name
1579 << QwLog::endl;
1580
1581 std::string type = typeid(object).name();
1582 fDirsByName[name] = fMapFile->GetDirectory()->mkdir(name.c_str());
1583 fDirsByType[type].push_back(name);
1584 object.ConstructObjects();
1585 }
1586}

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

1358{
1359 // Return if we do not want this tree information
1360 if (IsTreeDisabled(name)) return;
1361
1362 // Pointer to new tree
1363 QwRootTree* tree = 0;
1364
1365 // If the tree does not exist yet, create it
1366 if (fTreeByName.count(name) == 0) {
1367
1368 // Go to top level directory
1369
1370 this->cd();
1371
1372 // New tree with name, description, object, prefix
1373 tree = new QwRootTree(name, desc, object, prefix);
1374
1375 // Settings only relevant for new trees
1376 if (name == "evt")
1378 else if (name == "mul")
1380
1381 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,00)
1382 tree->SetAutoFlush(fAutoFlush);
1383 #endif
1384 tree->SetAutoSave(fAutoSave);
1387
1388 if (fCircularBufferSize > 0)
1390
1391 } else {
1392
1393 // New tree based on existing tree
1394 tree = new QwRootTree(fTreeByName[name].front(), object, prefix);
1395 }
1396
1397 // Add the branches to the list of trees by name, object, type
1398 const void* addr = static_cast<const void*>(&object);
1399 const std::type_index type = typeid(object);
1400 fTreeByName[name].push_back(tree);
1401 fTreeByAddr[addr].push_back(tree);
1402 fTreeByType[type].push_back(tree);
1403}
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}
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 1217 of file QwRootFile.h.

1217 {
1218 fDisabledHistos.push_back(regexp);
1219 }
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 1207 of file QwRootFile.h.

1207 {
1208 fDisabledTrees.push_back(regexp);
1209 }
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 901 of file QwRootFile.h.

901 {
902 // Update regularly
903 static Int_t update_count = 0;
904 update_count++;
905 if ((fUpdateInterval > 0) && ( update_count % fUpdateInterval == 0)) Update();
906
907 // Debug directory registration
908 std::string type = typeid(object).name();
909 bool hasDir = HasDirByType(object);
910
911 if (! hasDir) return;
912 // Fill histograms
913 object.FillHistograms();
914 }
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 955 of file QwRootFile.h.

955 {
956 if (! HasTreeByName(name)) return 0;
957 else return fTreeByName[name].front()->Fill();
958 }
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 1412 of file QwRootFile.h.

1415{
1416 // If this name has no registered trees
1417 if (! HasTreeByName(name)) return;
1418 // If this type has no registered trees
1419 if (! HasTreeByType(object)) return;
1420
1421 // Get the address of the object
1422 const void* addr = static_cast<const void*>(&object);
1423
1424 // Fill the trees with the correct address
1425 for (size_t tree = 0; tree < fTreeByAddr[addr].size(); tree++) {
1426 if (fTreeByAddr[addr].at(tree)->GetName() == name) {
1427 fTreeByAddr[addr].at(tree)->FillTreeBranches(object);
1428 }
1429 }
1430}
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 1438 of file QwRootFile.h.

1440{
1441 // If this address has no registered trees
1442 if (! HasTreeByAddr(object)) return;
1443
1444 // Get the address of the object
1445 const void* addr = static_cast<const void*>(&object);
1446
1447 // Fill the trees with the correct address
1448 for (size_t tree = 0; tree < fTreeByAddr[addr].size(); tree++) {
1449 fTreeByAddr[addr].at(tree)->FillTreeBranches(object);
1450 }
1451}
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 961 of file QwRootFile.h.

961 {
962 // Loop over all registered tree names
963 Int_t retval = 0;
964 std::map< const std::string, std::vector<QwRootTree*> >::iterator iter;
965 for (iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
966 retval += iter->second.front()->Fill();
967 }
968 return retval;
969 }

References fTreeByName.

◆ GetTree()

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

Get the tree with name.

Definition at line 949 of file QwRootFile.h.

949 {
950 if (! HasTreeByName(name)) return 0;
951 else return fTreeByName[name].front()->GetTree();
952 }

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 370 of file QwRootFile.cc.

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

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 367 of file QwRootFile.cc.

367 {
368 return this->HasAnyFilled(fRootFile);
369}

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

1293 {
1294 if (fDirsByName.count(name) == 0) return false;
1295 else return true;
1296 }

References fDirsByName.

◆ HasDirByType()

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

Is a directory registered for this type.

Definition at line 1299 of file QwRootFile.h.

1299 {
1300 std::string type = typeid(object).name();
1301 if (fDirsByType.count(type) == 0) return false;
1302 else return true;
1303 }

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

1260 {
1261 const void* addr = static_cast<const void*>(&object);
1262 if (fTreeByAddr.count(addr) == 0) return false;
1263 else return true;
1264 }

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

1247 {
1248 if (fTreeByName.count(name) == 0) return false;
1249 else return true;
1250 }

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

1253 {
1254 const std::type_index type = typeid(object);
1255 if (fTreeByType.count(type) == 0) return false;
1256 else return true;
1257 }

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

1221 {
1222 for (size_t i = 0; i < fDisabledHistos.size(); i++)
1223 if (fDisabledHistos.at(i).Match(name)) return true;
1224 return false;
1225 }

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

860{ return (fMapFile); };

References fMapFile.

◆ IsRootFile()

Bool_t QwRootFile::IsRootFile ( ) const
inline

Is the ROOT file active?

Definition at line 858 of file QwRootFile.h.

858{ 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 1211 of file QwRootFile.h.

1211 {
1212 for (size_t i = 0; i < fDisabledTrees.size(); i++)
1213 if (fDisabledTrees.at(i).Match(name)) return true;
1214 return false;
1215 }

References fDisabledTrees.

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

+ Here is the caller graph for this function:

◆ ls()

void QwRootFile::ls ( )
inline

Definition at line 1047 of file QwRootFile.h.

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

References fMapFile, and fRootFile.

◆ Map()

void QwRootFile::Map ( )
inline

Definition at line 1048 of file QwRootFile.h.

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

References fRootFile.

◆ mkdir()

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

Definition at line 1144 of file QwRootFile.h.

1144 {
1145 // TMapFile has no support for mkdir
1146 if (fRootFile) return fRootFile->mkdir(name, title);
1147 else return 0;
1148 }

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

918 {
919 if (IsTreeDisabled(name)) return;
920 this->cd();
921 QwRootTree *tree = 0;
922 if (! HasTreeByName(name)) {
923 tree = new QwRootTree(name,desc);
924 } else {
925 tree = new QwRootTree(fTreeByName[name].front());
926 }
927 fTreeByName[name].push_back(tree);
928 }

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

1046{ 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 1007 of file QwRootFile.h.

1007 {
1008 QwMessage << "Dirs: " << QwLog::endl;
1009 // Loop ove rall registered directories
1010 std::map< const std::string, TDirectory* >::const_iterator iter;
1011 for (iter = fDirsByName.begin(); iter != fDirsByName.end(); iter++) {
1012 QwMessage << iter->first << QwLog::endl;
1013 }
1014 }

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

992 {
993 QwMessage << "Trees: " << QwLog::endl;
994 // Loop over all registered tree names
995 std::map< const std::string, std::vector<QwRootTree*> >::const_iterator iter;
996 for (iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++) {
997 QwMessage << iter->first << ": " << iter->second.size()
998 << " objects registered" << QwLog::endl;
999 // Loop over all registered objects for this tree
1000 std::vector<QwRootTree*>::const_iterator tree;
1001 for (tree = iter->second.begin(); tree != iter->second.end(); tree++) {
1002 (*tree)->Print();
1003 }
1004 }
1005 }

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 294 of file QwRootFile.cc.

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

References DisableHisto(), DisableTree(), QwLog::endl(), fAutoFlush, fAutoSave, fBasketSize, fCircularBufferSize, fCompressionAlgorithm, fCompressionLevel, fEnableMapFile, fNumHelEventsToSave, fNumHelEventsToSkip, fNumMpsEventsToSave, fNumMpsEventsToSkip, 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 848 of file QwRootFile.h.

848 {
850 }

References fDefaultRootFileDir.

◆ SetDefaultRootFileStem()

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

Set default ROOT file stem.

Definition at line 852 of file QwRootFile.h.

852 {
854 }

References fDefaultRootFileStem.

◆ Update()

void QwRootFile::Update ( )
inline

Definition at line 1028 of file QwRootFile.h.

1028 {
1029 if (fMapFile) {
1030 QwMessage << "TMapFile memory resident size: "
1031 << ((int*)fMapFile->GetBreakval() - (int*)fMapFile->GetBaseAddr()) *
1032 4 / sizeof(int32_t) / 1024 / 1024 << " MiB"
1033 << QwLog::endl;
1034 fMapFile->Update();
1035 }else{
1036 // this option will allow for reading the tree during write
1037 Long64_t nBytes(0);
1038 for (auto iter = fTreeByName.begin(); iter != fTreeByName.end(); iter++)
1039 nBytes += iter->second.front()->AutoSave("SaveSelf");
1040
1041 QwMessage << "TFile saved: "
1042 << nBytes/1000000 << "MB (inaccurate number)" //FIXME this calculation is inaccurate
1043 << QwLog::endl;
1044 }
1045 }

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

1151 {
1152 Int_t retval = 0;
1153 // TMapFile has no support for Write
1154 if (fRootFile) retval = fRootFile->Write(name, option, bufsize);
1155 return retval;
1156 }

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

1019 {
1020 Int_t retval = 0;
1021 // TMapFile has no support for WriteObject
1022 if (fRootFile) retval = fRootFile->WriteObject(obj,name,option,bufsize);
1023 return retval;
1024 }

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

1630{
1631 Int_t retval = 0;
1632 if (fRootFile) {
1633 TList *param_list = (TList*) fRootFile->FindObjectAny(name);
1634 if (not param_list) {
1635 retval = fRootFile->WriteObject(object.GetParamFileNameList(name), name);
1636 }
1637 }
1638 return retval;
1639}

References fRootFile.

Referenced by main().

+ Here is the caller graph for this function:

Field Documentation

◆ fAutoFlush

Int_t QwRootFile::fAutoFlush
private

Definition at line 1195 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fAutoSave

Int_t QwRootFile::fAutoSave
private

Definition at line 1196 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fBasketSize

Int_t QwRootFile::fBasketSize
private

Definition at line 1194 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fCircularBufferSize

UInt_t QwRootFile::fCircularBufferSize
private

Definition at line 1313 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fCompressionAlgorithm

Int_t QwRootFile::fCompressionAlgorithm
private

Definition at line 1192 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fCompressionLevel

Int_t QwRootFile::fCompressionLevel
private

Definition at line 1193 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fCurrentEvent

UInt_t QwRootFile::fCurrentEvent
private

Definition at line 1314 of file QwRootFile.h.

◆ fDefaultRootFileDir

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

Default ROOT files dir.

Definition at line 1171 of file QwRootFile.h.

Referenced by DefineOptions(), and SetDefaultRootFileDir().

◆ fDefaultRootFileStem

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

Default ROOT file stem.

Definition at line 1176 of file QwRootFile.h.

Referenced by DefineOptions(), and SetDefaultRootFileStem().

◆ fDirsByName

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

Directories.

Definition at line 1289 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 1290 of file QwRootFile.h.

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

◆ fDisabledHistos

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

Definition at line 1204 of file QwRootFile.h.

Referenced by DisableHisto(), and IsHistoDisabled().

◆ fDisabledTrees

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

List of excluded trees.

Definition at line 1203 of file QwRootFile.h.

Referenced by DisableTree(), and IsTreeDisabled().

◆ fEnableMapFile

Bool_t QwRootFile::fEnableMapFile
private

Definition at line 1190 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fMakePermanent

Bool_t QwRootFile::fMakePermanent
private

Definition at line 1181 of file QwRootFile.h.

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

◆ fMapFile

TMapFile* QwRootFile::fMapFile
private

◆ fNumHelEventsToSave

UInt_t QwRootFile::fNumHelEventsToSave
private

Definition at line 1312 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fNumHelEventsToSkip

UInt_t QwRootFile::fNumHelEventsToSkip
private

Definition at line 1311 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fNumMpsEventsToSave

UInt_t QwRootFile::fNumMpsEventsToSave
private

Definition at line 1310 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and ProcessOptions().

◆ fNumMpsEventsToSkip

UInt_t QwRootFile::fNumMpsEventsToSkip
private

Prescaling of events written to tree.

Definition at line 1309 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 1180 of file QwRootFile.h.

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

◆ fRootFile

TFile* QwRootFile::fRootFile
private

◆ fRootFileDir

TString QwRootFile::fRootFileDir
private

ROOT files dir.

Definition at line 1169 of file QwRootFile.h.

Referenced by ProcessOptions(), and QwRootFile().

◆ fRootFileStem

TString QwRootFile::fRootFileStem
private

ROOT file stem.

Definition at line 1174 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 1233 of file QwRootFile.h.

Referenced by ConstructTreeBranches(), and HasTreeByType().

◆ fUpdateInterval

Int_t QwRootFile::fUpdateInterval
private

Definition at line 1191 of file QwRootFile.h.

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

◆ fUseTemporaryFile

Bool_t QwRootFile::fUseTemporaryFile
private

Definition at line 1182 of file QwRootFile.h.

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

◆ kMaxMapFileSize

const Int_t QwRootFile::kMaxMapFileSize = 0x3fffffff
staticprivate

Definition at line 1318 of file QwRootFile.h.

Referenced by QwRootFile().

◆ kMaxTreeSize

const Long64_t QwRootFile::kMaxTreeSize = 100000000000LL
staticprivate

Maximum tree size.

Definition at line 1317 of file QwRootFile.h.

Referenced by ConstructTreeBranches().


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