Belle II Software development
StorageRootOutputModule.h
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#pragma once
10
11#include <framework/core/Module.h>
12#include <framework/core/Environment.h>
13#include <framework/datastore/DataStore.h>
14#include <framework/datastore/StoreObjPtr.h>
15#include <framework/dataobjects/FileMetaData.h>
16#include <framework/dataobjects/EventMetaData.h>
17
18#include <TFile.h>
19#include <TTree.h>
20
21#include <optional>
22#include <string>
23#include <vector>
24
25// For online storage
26#include <daq/slc/database/DBInterface.h>
27#include <daq/slc/psql/PostgreSQLInterface.h>
28
29namespace Belle2 {
41
42 public:
43
47
53
58 virtual void initialize() override;
59
64 virtual void endRun() override;
65
70 virtual void event() override;
71
77 virtual void terminate() override;
78
80 virtual std::vector<std::string> getFileNames(bool outputFiles = true) override
81 {
82 B2ASSERT("StorageRootOutput is not an input module", outputFiles);
84 // This will warn if already consumed which is what we want
85 std::string outputFileArgument = Environment::Instance().consumeOutputFileOverride(getName());
86 if (!outputFileArgument.empty())
87 m_outputFileName = outputFileArgument;
89 }
90 return {m_outputFileName};
91 }
92
93 private:
94
96 void closeFile();
97
99 void openFile();
100
107 void fillTree(DataStore::EDurability durability);
108
110 void fillFileMetaData();
111
112 //first the steerable variables:
113
119 std::string m_outputFileName;
120
127
132
139
142
145
151
154
157
160
163
167
170 std::optional<uint64_t> m_outputSplitSize{std::nullopt};
171
172 //then those for purely internal use:
173
176
178 unsigned int m_nFullEvents{0};
179
181 TFile* m_file;
182
185
187 std::vector<DataStore::StoreEntry*> m_entries[DataStore::c_NDurabilityTypes];
188
190 std::vector<std::string> m_parentLfns;
191
193 std::map<std::string, std::string> m_additionalDataDescription;
194
197 unsigned long m_experimentLow;
198
201 unsigned long m_runLow;
202
205 unsigned long m_eventLow;
206
209 unsigned long m_experimentHigh;
210
213 unsigned long m_runHigh;
214
217 unsigned long m_eventHigh;
218
220 bool m_buildIndex{false};
221
223 bool m_keepParents{false};
224
226 bool m_regularFile{true};
227
234
236 int m_expno{0};
237 int m_runno{0};
238 DBInterface* m_db;
239 std::string m_runType;
240 std::string m_HLTName;
241 std::string m_disk;
242 int m_nDisk;
243 int m_processNumber;
244 bool m_firstEvent{false};
245 bool m_ramdiskBuffer{false};
246 };
248} // end namespace Belle2
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
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overriden output file name, or "" if none was set.
Definition: Environment.cc:67
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
Metadata information about a file.
Definition: FileMetaData.h:29
Base class for Modules.
Definition: Module.h:72
const std::string & getName() const
Returns the name of the module.
Definition: Module.h:187
Write objects from DataStore into a ROOT file.
unsigned long m_experimentLow
Lowest experiment number.
int m_expno
Variables for online storage.
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 endRun() override
Issued by the lastEventMessage = DAQ STOP.
virtual ~StorageRootOutputModule()
Destructor.
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.
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.
void openFile()
Open the next output file.
unsigned long m_eventHigh
Highest event number in highest run.
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.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
Abstract base class for different kinds of events.