Belle II Software  release-08-01-10
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 
29 namespace Belle2 {
44 
45  public:
46 
50 
56 
61  virtual void initialize() override;
62 
67  virtual void endRun() override;
68 
73  virtual void event() override;
74 
80  virtual void terminate() override;
81 
83  virtual std::vector<std::string> getFileNames(bool outputFiles = true) override
84  {
85  B2ASSERT("StorageRootOutput is not an input module", outputFiles);
87  // This will warn if already consumed which is what we want
88  std::string outputFileArgument = Environment::Instance().consumeOutputFileOverride(getName());
89  if (!outputFileArgument.empty())
90  m_outputFileName = outputFileArgument;
92  }
93  return {m_outputFileName};
94  }
95 
96  private:
97 
99  void closeFile();
100 
102  void openFile();
103 
110  void fillTree(DataStore::EDurability durability);
111 
113  void fillFileMetaData();
114 
115  //first the steerable variables:
116 
122  std::string m_outputFileName;
123 
129  std::vector<std::string> m_branchNames[DataStore::c_NDurabilityTypes];
130 
135 
142 
145 
148 
154 
157 
160 
163 
166 
170 
173  std::optional<uint64_t> m_outputSplitSize{std::nullopt};
174 
175  //then those for purely internal use:
176 
178  int m_fileIndex{0};
179 
181  unsigned int m_nFullEvents{0};
182 
184  TFile* m_file;
185 
188 
190  std::vector<DataStore::StoreEntry*> m_entries[DataStore::c_NDurabilityTypes];
191 
193  std::vector<std::string> m_parentLfns;
194 
196  std::map<std::string, std::string> m_additionalDataDescription;
197 
200  unsigned long m_experimentLow;
201 
204  unsigned long m_runLow;
205 
208  unsigned long m_eventLow;
209 
212  unsigned long m_experimentHigh;
213 
216  unsigned long m_runHigh;
217 
220  unsigned long m_eventHigh;
221 
223  bool m_buildIndex{false};
224 
226  bool m_keepParents{false};
227 
229  bool m_regularFile{true};
230 
237 
239  int m_expno{0};
240  int m_runno{0};
241  DBInterface* m_db;
242  std::string m_runType;
243  std::string m_HLTName;
244  std::string m_disk;
245  int m_nDisk;
246  int m_processNumber;
247  bool m_firstEvent{false};
248  bool m_ramdiskBuffer{false};
249  };
251 } // 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.
virtual std::vector< std::string > getFileNames(bool outputFiles=true) override
Set the used output file, taking into account -o argument to basf2.
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.
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.