Belle II Software development
RootOutputModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <boost/python.hpp>
10
11#include <framework/modules/rootio/RootOutputModule.h>
12
13#include <framework/io/RootIOUtilities.h>
14#include <framework/core/FileCatalog.h>
15#include <framework/core/MetadataService.h>
16#include <framework/core/RandomNumbers.h>
17#include <framework/database/Database.h>
18// needed for complex module parameter
19#include <framework/core/ModuleParam.templateDetails.h>
20#include <framework/utilities/EnvironmentVariables.h>
21
22#include <boost/format.hpp>
23#include <boost/algorithm/string.hpp>
24
25#include <TClonesArray.h>
26
27#include <nlohmann/json.hpp>
28
29#include <memory>
30#include <regex>
31#include <filesystem>
32
33using namespace std;
34using namespace Belle2;
35using namespace RootIOUtilities;
36
37//-----------------------------------------------------------------
38// Register the Module
39//-----------------------------------------------------------------
40REG_MODULE(RootOutput);
41
42//-----------------------------------------------------------------
43// Implementation
44//-----------------------------------------------------------------
45
46RootOutputModule::RootOutputModule() : Module(), m_file(nullptr), m_tree{0}, m_experimentLow(1), m_runLow(0),
47 m_eventLow(0), m_experimentHigh(0), m_runHigh(0), m_eventHigh(0)
48{
49 //Set module properties
50 setDescription("Writes DataStore objects into a .root file. Data is stored in a TTree 'tree' for event-dependent and in 'persistent' for peristent data. You can use RootInput to read the files back into basf2.");
52
53 //Parameter definition
54 addParam("outputFileName", m_outputFileName, "Name of the output file. Can be overridden using the -o argument to basf2.",
55 string("RootOutput.root"));
56 addParam("ignoreCommandLineOverride", m_ignoreCommandLineOverride,
57 "Ignore override of file name via command line argument -o. Useful if you have multiple output modules in one path.", false);
58 addParam("compressionLevel", m_compressionLevel,
59 "0 for no, 1 for low, 9 for high compression. Level 1 usually reduces size by >50%, higher levels have no noticeable effect. On typical hard disks, disabling compression reduces write time by 10-20 %, but almost doubles read time, so you probably should leave this turned on.",
61 addParam("compressionAlgorithm", m_compressionAlgorithm,
62 "Set the Compression algorithm. Recommended values are 0 for default, 1 for zlib and 4 for lz4\n\n"
63 ".. versionadded:: release-03-00-00", m_compressionAlgorithm);
64 addParam("splitLevel", m_splitLevel,
65 "Branch split level: determines up to which depth object members will be saved in separate sub-branches in the tree. For arrays or objects with custom streamers, -1 is used instead to ensure the streamers are used. The default (99) usually gives the highest read performance with RootInput.",
66 99);
67 addParam("updateFileCatalog", m_updateFileCatalog, R"DOC(
68Flag that specifies whether the file metadata catalog is updated or created.
69This is only necessary in special cases and can always be done afterwards using
70``b2file-catalog-add filename.root``"
71
72(You can also set the ``BELLE2_FILECATALOG`` environment variable to NONE to get
73the same effect as setting this to false))DOC", false);
74
75 vector<string> emptyvector;
77 "Names of event durability branches to be saved. Empty means all branches. Objects with c_DontWriteOut flag added here will also be saved. (EventMetaData is always saved)",
78 emptyvector);
80 "Names of persistent durability branches to be saved. Empty means all branches. Objects with c_DontWriteOut flag added here will also be saved. (FileMetaData is always saved)",
81 emptyvector);
83 "Add additional event branch names without the need to specify all branchnames.",
84 emptyvector);
86 "Add additional persistent branch names without the need to specify all branchnames.",
87 emptyvector);
89 "Names of event durability branches NOT to be saved. Branches also in branchNames are not saved.", emptyvector);
91 "Names of persistent durability branches NOT to be saved. Branches also in branchNamesPersistent are not saved.", emptyvector);
92 addParam("autoFlushSize", m_autoflush,
93 "Value for TTree SetAutoFlush(): a positive value tells ROOT to flush all baskets to disk after n entries, a negative value to flush after -n bytes",
94 -10000000);
95 addParam("autoSaveSize", m_autosave,
96 "Value for TTree SetAutoSave(): a positive value tells ROOT to write the TTree metadata after n entries, a negative value to write the metadata after -n bytes",
97 -10000000);
98 addParam("basketSize", m_basketsize, "Basketsize for Branches in the Tree in bytes", 32000);
99 addParam("additionalDataDescription", m_additionalDataDescription, "Additional dictionary of "
100 "name->value pairs to be added to the file metadata to describe the data",
102 addParam("buildIndex", m_buildIndex, "Build Event Index for faster finding of events by exp/run/event number", m_buildIndex);
103 addParam("keepParents", m_keepParents, "Keep parents files of input files, input files will not be added as output file's parents",
105 addParam("outputSplitSize", m_outputSplitSize, R"DOC(
106If given split the output file once the file has reached the given size in MB.
107If set the filename will end in ``.f{index:05d}.root``. So if for example
108``outputFileName`` is set to "RootOutput.root" then the files will be named
109``RootOutput.f00000.root``, ``RootOutput.f00001.root``,
110``RootOutput.f00002.root``, ...
111
112All created output files are complete and independent files and can
113subsequently processed completely independent.
114
115Note:
116 The output files will be approximately of the size given by
117 ``outputSplitSize`` but they will be slightly larger since
118 additional information has to be written at the end of the file. If necessary
119 please account for this. Also, using ``buildIndex=False`` might be beneficial
120 to reduce the overshoot.
121
122Warning:
123 This will set the amount of generated events stored in the file metadata to
124 zero as it is not possible to determine which fraction ends up in which
125 output file.
126
127.. versionadded:: release-03-00-00
128)DOC", m_outputSplitSize);
129
131}
132
133
135{
137}
138
140{
141 //ROOT has a default maximum size of 100GB for trees??? For larger trees it creates a new file and does other things that finally produce crashes.
142 //Let's set this to 100PB, that should last a bit longer.
143 TTree::SetMaxTreeSize(1000 * 1000 * 100000000000LL);
144
145 //make sure we have event meta data
146 m_eventMetaData.isRequired();
147
148 //check outputSplitSize
149 if (m_outputSplitSize) {
150 if (*m_outputSplitSize == 0) B2ERROR("outputSplitSize must be set to a positive value");
151 // Warn is splitsize is >= 1TB ... because this seems weirdly like size was given in bytes
152 if (*m_outputSplitSize >= 1024*1024) B2WARNING("outputSplitSize set to " << *m_outputSplitSize << " MB, please make sure the units are correct");
153 // convert to bytes
154 *m_outputSplitSize *= 1024 * 1024;
155 }
156
157 getFileNames();
158
159 // Now check if the file has a protocol like file:// or http:// in front
160 std::regex protocol("^([A-Za-z]*)://");
161 if(std::smatch m; std::regex_search(m_outputFileName, m, protocol)) {
162 if(m[1] == "file") {
163 // file protocol: treat as local and just remove it from the filename
164 m_outputFileName = std::regex_replace(m_outputFileName, protocol, "");
165 } else {
166 // any other protocol: not local, don't create directories
167 m_regularFile = false;
168 }
169 }
170 openFile();
171}
172
174{
175 // Since we open a new file, we also have to reset the number of full events
176 m_nFullEvents = 0;
177 // Continue with opening the file
178 TDirectory* dir = gDirectory;
179 std::filesystem::path out{m_outputFileName};
180 if (m_outputSplitSize) {
181 // Mangle the filename to add the fNNNNN part. However we need to be
182 // careful since the file name could be non-local and have some options or
183 // anchor information attached (like
184 // http://mydomain.org/filename.root?foo=bar#baz). So use "TUrl" *sigh* to
185 // do the parsing and only replace the extension of the file part.
186 TUrl fileUrl(m_outputFileName.c_str(), m_regularFile);
187 std::filesystem::path file{fileUrl.GetFile()};
188 file.replace_extension((boost::format("f%05d.root") % m_fileIndex).str());
189 fileUrl.SetFile(file.c_str());
190 // In case of regular files we don't want the protocol or anything, just the file
191 out = m_regularFile? fileUrl.GetFileAndOptions() : fileUrl.GetUrl();
192 }
193 m_file = TFile::Open(out.c_str(), "RECREATE", "basf2 Event File");
194 if ((!m_file || m_file->IsZombie()) && m_regularFile) {
195 //try creating necessary directories since this is a local file
196 auto dirpath = out.parent_path();
197
198 if (std::filesystem::create_directories(dirpath)) {
199 B2INFO("Created missing directory " << dirpath << ".");
200 //try again
201 m_file = TFile::Open(out.c_str(), "RECREATE", "basf2 Event File");
202 }
203
204 }
205 if (!m_file || m_file->IsZombie()) {
206 B2FATAL("Couldn't open file " << out << " for writing!");
207 }
208 m_file->SetCompressionAlgorithm(m_compressionAlgorithm);
209 m_file->SetCompressionLevel(m_compressionLevel);
210
211 for (int durability = 0; durability < DataStore::c_NDurabilityTypes; durability++) {
213 set<string> branchList;
214 for (const auto& pair : map)
215 branchList.insert(pair.first);
216 //skip branches the user doesn't want
217 branchList = filterBranches(branchList, m_branchNames[durability], m_excludeBranchNames[durability], durability);
218
219 //create the tree and branches
220 m_tree[durability] = new TTree(c_treeNames[durability].c_str(), c_treeNames[durability].c_str());
221 m_tree[durability]->SetAutoFlush(m_autoflush);
222 m_tree[durability]->SetAutoSave(m_autosave);
223 for (auto & iter : map) {
224 const std::string& branchName = iter.first;
225 //skip transient entries (allow overriding via branchNames)
226 if (iter.second.dontWriteOut
227 && find(m_branchNames[durability].begin(), m_branchNames[durability].end(), branchName) == m_branchNames[durability].end()
228 && find(m_additionalBranchNames[durability].begin(), m_additionalBranchNames[durability].end(),
229 branchName) == m_additionalBranchNames[durability].end())
230 continue;
231 //skip branches the user doesn't want
232 if (branchList.count(branchName) == 0) {
233 //make sure FileMetaData and EventMetaData are always included in the output
234 if (((branchName != "FileMetaData") || (durability == DataStore::c_Event)) &&
235 ((branchName != "EventMetaData") || (durability == DataStore::c_Persistent))) {
236 continue;
237 }
238 }
239
240 // Warn for anything other than FileMetaData and ProcessStatistics ...
241 if(durability == DataStore::c_Persistent and m_outputSplitSize and m_fileIndex==0 and
242 (branchName != "FileMetaData" and branchName != "ProcessStatistics")) {
243 B2WARNING("Persistent branches might not be stored as expected when splitting the output by size" << LogVar("branch", branchName));
244 }
245
246 TClass* entryClass = iter.second.objClass;
247
248 //I want to do this in the input module, but I apparently I cannot disable reading those branches.
249 //isabling reading the branch by not calling SetBranchAddress() for it results in the following crashes. Calling SetBranchStatus(..., 0) doesn't help, either.
250 //reported to ROOT devs, let's see if it gets fixed.
251 //
252 //HasDictionary() is a new function in root 6
253 //using it instead of GetClassInfo() avoids having to parse header files (and
254 //the associated memory cost)
255 if (!entryClass->HasDictionary()) {
256 if (m_fileIndex == 0) {
257 B2WARNING("No dictionary found, object will not be saved (This is probably an obsolete class that is still present in the input file.)"
258 << LogVar("class", entryClass->GetName()) << LogVar("branch", branchName));
259 }
260 continue;
261 }
262
263 if (!hasStreamer(entryClass)) {
264 B2ERROR("The version number in the ClassDef() macro must be at least 1 to enable I/O!" << LogVar("class", entryClass->GetName()));
265 }
266
267 int splitLevel = m_splitLevel;
268 if (hasCustomStreamer(entryClass)) {
269 B2DEBUG(38, "Class has custom streamer, setting split level -1 for this branch." << LogVar("class", entryClass->GetName()));
270
271 splitLevel = -1;
272 if (iter.second.isArray) {
273 //for arrays, we also don't want TClonesArray to go around our streamer
274 static_cast<TClonesArray*>(iter.second.object)->BypassStreamer(kFALSE);
275 }
276 }
277 m_tree[durability]->Branch(branchName.c_str(), &iter.second.object, m_basketsize, splitLevel);
278 m_entries[durability].push_back(&iter.second);
279 B2DEBUG(39, "The branch " << branchName << " was created.");
280
281 //Tell DataStore that we are using this entry
282 if (m_fileIndex == 0) {
284 iter.second.isArray));
285 }
286 }
287 }
288
289 // set the address of the FileMetaData branch for the output to a separate one from the input
290 TBranch* fileMetaDataBranch = m_tree[DataStore::c_Persistent]->GetBranch("FileMetaData");
291 if (fileMetaDataBranch) {
292 fileMetaDataBranch->SetAddress(&m_outputFileMetaData);
293 } else {
295 }
296
297 dir->cd();
298 if (m_outputSplitSize) {
299 B2INFO(getName() << ": Opened " << (m_fileIndex > 0 ? "new " : "") << "file for writing" << LogVar("filename", out));
300 }
301}
302
303
305{
306 // if we closed after last event ... make a new one
307 if (!m_file)
308 openFile();
309
310 if (!m_keepParents) {
311 if (m_fileMetaData) {
312 m_eventMetaData->setParentLfn(m_fileMetaData->getLfn());
313 }
314 }
315
316 //fill Event data
318
319 if (m_fileMetaData) {
320 if (m_keepParents) {
321 for (int iparent = 0; iparent < m_fileMetaData->getNParents(); iparent++) {
322 string lfn = m_fileMetaData->getParent(iparent);
323 if (!lfn.empty() && (m_parentLfns.empty() || (m_parentLfns.back() != lfn))) {
324 m_parentLfns.push_back(lfn);
325 }
326 }
327 } else {
328 string lfn = m_fileMetaData->getLfn();
329 if (!lfn.empty() && (m_parentLfns.empty() || (m_parentLfns.back() != lfn))) {
330 m_parentLfns.push_back(lfn);
331 }
332 }
333 }
334
335 // keep track of file level metadata
336 unsigned long experiment = m_eventMetaData->getExperiment();
337 unsigned long run = m_eventMetaData->getRun();
338 unsigned long event = m_eventMetaData->getEvent();
339 if (m_experimentLow > m_experimentHigh) { //starting condition
340 m_experimentLow = m_experimentHigh = experiment;
341 m_runLow = m_runHigh = run;
343 } else {
344 if ((experiment < m_experimentLow) || ((experiment == m_experimentLow) && ((run < m_runLow) || ((run == m_runLow)
345 && (event < m_eventLow))))) {
346 m_experimentLow = experiment;
347 m_runLow = run;
349 }
350 if ((experiment > m_experimentHigh) || ((experiment == m_experimentHigh) && ((run > m_runHigh) || ((run == m_runHigh)
351 && (event > m_eventHigh))))) {
352 m_experimentHigh = experiment;
353 m_runHigh = run;
355 }
356 }
357
358 // check if the event is a full event or not: if yes, increase the counter
359 if (m_eventMetaData->getErrorFlag() == 0) // no error flag -> this is a full event
361
362 // check if we need to split the file
363 if (m_outputSplitSize and (uint64_t)m_file->GetEND() > *m_outputSplitSize) {
364 // close file and open new one
365 B2INFO(getName() << ": Output size limit reached, closing file ...");
366 closeFile();
367 }
368}
369
371{
372 bool isMC = (m_fileMetaData) ? m_fileMetaData->isMC() : true;
375
377 //create an index for the event tree
378 TTree* tree = m_tree[DataStore::c_Event];
379 unsigned long numEntries = tree->GetEntries();
381 if (m_buildIndex && numEntries > 0) {
382 if (numEntries > 10000000) {
383 //10M events correspond to about 240MB for the TTreeIndex object. for more than ~45M entries this causes crashes, broken files :(
384 B2WARNING("Not building TTree index because of large number of events. The index object would conflict with ROOT limits on object size and cause problems.");
385 } else if (tree->GetBranch("EventMetaData")) {
386 tree->SetBranchAddress("EventMetaData", nullptr);
388 }
389 }
390
391 m_outputFileMetaData->setNEvents(numEntries);
393 //starting condition so apparently no events at all
394 m_outputFileMetaData->setLow(-1, -1, 0);
395 m_outputFileMetaData->setHigh(-1, -1, 0);
396 } else {
399 }
400 }
401
402 //fill more file level metadata
407 auto mcEvents = Environment::Instance().getNumberOfMCEvents();
408 if(m_outputSplitSize and mcEvents > 0) {
409 if(m_fileIndex == 0) B2WARNING("Number of MC Events cannot be saved when splitting output files by size, setting to 0");
410 mcEvents = 0;
411 }
414 for (const auto& item : m_additionalDataDescription) {
415 m_outputFileMetaData->setDataDescription(item.first, item.second);
416 }
417 // Set the LFN to the filename: if it's a URL to directly, otherwise make sure it's absolute
418 std::string lfn = m_file->GetName();
419 if(m_regularFile) {
420 lfn = std::filesystem::absolute(lfn).string();
421 }
422 // Format LFN if BELLE2_LFN_FORMATSTRING is set
423 std::string format = EnvironmentVariables::get("BELLE2_LFN_FORMATSTRING", "");
424 if (!format.empty()) {
425 auto format_filename = boost::python::import("B2Tools.format").attr("format_filename");
426 lfn = boost::python::extract<std::string>(format_filename(format, m_outputFileName, m_outputFileMetaData->getJsonStr()));
427 }
429 //register the file in the catalog
432 }
433}
434
435
437{
438 closeFile();
439}
440
442{
443 if(!m_file) return;
444
446
447 //fill Persistent data
449
450 //write the trees
451 TDirectory* dir = gDirectory;
452 m_file->cd();
453 for (int durability = 0; durability < DataStore::c_NDurabilityTypes; ++durability) {
454 if (m_tree[durability]) {
455 B2DEBUG(30, "Write TTree " << c_treeNames[durability]);
456 m_tree[durability]->Write(c_treeNames[durability].c_str(), TObject::kWriteDelete);
457 delete m_tree[durability];
458 }
459 m_tree[durability] = nullptr;
460 }
461 dir->cd();
462
463 const std::string filename = m_file->GetName();
464 if (m_outputSplitSize) {
465 B2INFO(getName() << ": Finished writing file." << LogVar("filename", filename));
466 }
467 delete m_file;
468 m_file = nullptr;
469
470 // and now add it to the metadata service as it's fully written
472
473 // reset some variables
474 for (auto & entry : m_entries) {
475 entry.clear();
476 }
477 m_parentLfns.clear();
478 m_experimentLow = 1;
480 m_runLow = 0;
481 m_runHigh = 0;
482 m_eventLow = 0;
483 m_eventHigh = 0;
484 // and increase index of next file
485 ++m_fileIndex;
486}
487
488
490{
491 if (!m_tree[durability]) return;
492
493 TTree& tree = *m_tree[durability];
494 for(auto* entry: m_entries[durability]) {
495 // Check for entries whose object was not created and mark them as invalid.
496 // We still have to write them in the file due to the structure we have. This could be done better
497 if (!entry->ptr) {
498 entry->object->SetBit(kInvalidObject);
499 }
500 //FIXME: Do we need this? in theory no but it crashes in parallel processing otherwise ¯\_(ツ)_/¯
501 if (entry->name == "FileMetaData") {
502 tree.SetBranchAddress(entry->name.c_str(), &m_outputFileMetaData);
503 } else {
504 tree.SetBranchAddress(entry->name.c_str(), &entry->object);
505 }
506 }
507 tree.Fill();
508 for (auto* entry: m_entries[durability]) {
509 entry->object->ResetBit(kInvalidObject);
510 }
511
512 const bool writeError = m_file->TestBit(TFile::kWriteError);
513 if (writeError) {
514 //m_file deleted first so we have a chance of closing it (though that will probably fail)
515 const std::string filename = m_file->GetName();
516 delete m_file;
517 B2FATAL("A write error occured while saving '" << filename << "', please check if enough disk space is available.");
518 }
519}
StoreEntryMap & getStoreEntryMap(EDurability durability)
Get a reference to the object/array map.
Definition: DataStore.h:325
static const int c_NDurabilityTypes
Number of Durability Types.
Definition: DataStore.h:63
EDurability
Durability types.
Definition: DataStore.h:58
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:60
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition: DataStore.h:59
static DataStore & Instance()
Instance of singleton Store.
Definition: DataStore.cc:54
bool optionalInput(const StoreAccessorBase &accessor)
Register the given object/array as an optional input.
Definition: DataStore.cc:739
std::map< std::string, StoreEntry > StoreEntryMap
Map for StoreEntries.
Definition: DataStore.h:87
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
Definition: Environment.h:106
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
static FileCatalog & Instance()
Static method to get a reference to the FileCatalog instance.
Definition: FileCatalog.cc:23
virtual bool registerFile(const std::string &fileName, FileMetaData &metaData, const std::string &oldLFN="")
Register a file in the (local) file catalog.
Definition: FileCatalog.cc:90
Metadata information about a file.
Definition: FileMetaData.h:29
void setLow(int experiment, int run, unsigned int event)
Lowest experiment, run and event number setter.
Definition: FileMetaData.h:159
void setHigh(int experiment, int run, unsigned int event)
Highest experiment, run and event number setter.
Definition: FileMetaData.h:167
void setRandomSeed(const std::string &seed)
Random seed setter.
Definition: FileMetaData.h:189
void setSteering(const std::string &steering)
Steering file content setter.
Definition: FileMetaData.h:195
void declareRealData()
Declare that this is not generated, but real data.
Definition: FileMetaData.h:294
void setNFullEvents(unsigned int nEvents)
Number of full events setter.
Definition: FileMetaData.h:151
std::string getJsonStr() const
Get a json representation.
void setDatabaseGlobalTag(const std::string &globalTag)
Set the database global tag used when creating this file.
Definition: FileMetaData.h:208
void setLfn(const std::string &lfn)
Setter for LFN.
Definition: FileMetaData.h:139
void setDataDescription(const std::string &key, const std::string &value)
describe the data, if the key exists contents will be overwritten.
Definition: FileMetaData.h:214
void setNEvents(unsigned int nEvents)
Number of events setter.
Definition: FileMetaData.h:145
void setMcEvents(unsigned int nEvents)
Number of generated events setter.
Definition: FileMetaData.h:201
void setParents(const std::vector< std::string > &parents)
Parents setter.
Definition: FileMetaData.h:173
void addRootOutputFile(const std::string &fileName, const FileMetaData *metaData=nullptr)
Add the metadata of a root output file.
static MetadataService & Instance()
Static method to get a reference to the MetadataService instance.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
const std::string & getName() const
Returns the name of the module.
Definition: Module.h:187
@ c_Output
This module is an output module (writes data).
Definition: Module.h:79
static std::string getSeed()
Get the random number generator seed.
Definition: RandomNumbers.h:92
unsigned long m_experimentLow
Lowest experiment number.
std::vector< DataStore::StoreEntry * > m_entries[DataStore::c_NDurabilityTypes]
Vector of DataStore entries that are written to the output.
unsigned long m_experimentHigh
Highest experiment number.
unsigned long m_eventLow
Lowest event number in lowest run.
void fillFileMetaData()
Create and fill FileMetaData object.
int m_autosave
Number of entries (if >0) or number of bytes (if <0) after which write the tree metadata to disk.
bool m_regularFile
Whether this is a regular, local file where we can actually create directories.
unsigned long m_runLow
Lowest run number.
int m_compressionAlgorithm
TFile compression algorithm.
virtual void event() override
Write data in c_Event DataStore maps.
bool m_buildIndex
Whether or not we want to build an event index.
bool m_keepParents
Whether to keep parents same as that of input file.
virtual void terminate() override
Write data in the c_Persistent DataStore maps.
TTree * m_tree[DataStore::c_NDurabilityTypes]
TTree for output.
unsigned int m_nFullEvents
Number of full events (aka number of events without an error flag)
unsigned long m_runHigh
Highest run number.
StoreObjPtr< EventMetaData > m_eventMetaData
Pointer to the event meta data.
std::vector< std::string > m_excludeBranchNames[DataStore::c_NDurabilityTypes]
Array for names of branches that should NOT be written out.
int m_basketsize
basket size for each branch in the file in bytes
std::vector< std::string > m_additionalBranchNames[DataStore::c_NDurabilityTypes]
Array of names of branches that should be written out although they are not flagged for writeout.
virtual void initialize() override
Setting up of various stuff.
FileMetaData * m_outputFileMetaData
File meta data stored in the output file.
TFile * m_file
TFile for output.
int m_fileIndex
Keep track of the file index: if we split files than we add '.f{fileIndex:05d}' in front of the ROOT ...
void fillTree(DataStore::EDurability durability)
Fill TTree.
bool m_ignoreCommandLineOverride
Ignore filename override from command line.
void closeFile()
Finalize the output file.
std::optional< uint64_t > m_outputSplitSize
Maximum output file size in MB.
int m_compressionLevel
TFile compression level.
int m_autoflush
Number of entries (if >0) or number of bytes (if <0) after which to flush all baskets to disk.
bool m_updateFileCatalog
Flag to enable or disable the update of the metadata catalog.
int m_splitLevel
Branch split level.
void openFile()
Open the next output file.
unsigned long m_eventHigh
Highest event number in highest run.
virtual ~RootOutputModule()
Destructor.
std::map< std::string, std::string > m_additionalDataDescription
Map of additional metadata to be added to the output file.
std::vector< std::string > m_parentLfns
Vector of parent file LFNs.
std::vector< std::string > m_branchNames[DataStore::c_NDurabilityTypes]
Array for names of branches that should be written out.
virtual std::vector< std::string > getFileNames(bool outputFiles=true) override
Set the used output file, taking into account -o argument to basf2.
StoreObjPtr< FileMetaData > m_fileMetaData
Pointer to the input file meta data.
std::string m_outputFileName
Name for output file.
Base class for StoreObjPtr and StoreArray for easier common treatment.
Class to store variables with their name which were sent to the logging service.
static std::string get(const std::string &name, const std::string &fallback="")
Get the value of an environment variable or the given fallback value if the variable is not set.
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
bool hasCustomStreamer(const TClass *cl)
Returns true if and only if 'cl' has a user-defined streamer.
const std::string c_treeNames[]
Names of trees.
const std::string c_SteerExcludeBranchNames[]
Steering parameter names for m_excludeBranchNames.
const std::string c_SteerBranchNames[]
Steering parameter names for m_branchNames.
void setCreationData(FileMetaData &metadata)
Fill the creation info of a file meta data: site, user, data.
std::set< std::string > filterBranches(const std::set< std::string > &branchesToFilter, const std::vector< std::string > &branches, const std::vector< std::string > &excludeBranches, int durability, bool quiet=false)
Given a list of input branches and lists of branches to include/exclude, returns a list of branches t...
const std::string c_SteerAdditionalBranchNames[]
Steering parameter names for m_additionalBranchNames.
void buildIndex(TTree *tree)
Build TTreeIndex on tree (assumes EventMetaData branch exists there).
bool hasStreamer(const TClass *cl)
Returns true if and only if 'cl' or one of its bases has I/O streamers.
Abstract base class for different kinds of events.
STL namespace.