Belle II Software  release-05-02-19
RootOutputModule.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Heck, Thomas Kuhr *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/core/Module.h>
14 #include <framework/core/Environment.h>
15 #include <framework/datastore/DataStore.h>
16 #include <framework/datastore/StoreObjPtr.h>
17 #include <framework/dataobjects/FileMetaData.h>
18 #include <framework/dataobjects/EventMetaData.h>
19 
20 #include <TFile.h>
21 #include <TTree.h>
22 
23 #include <string>
24 #include <vector>
25 
26 #include <boost/optional.hpp>
27 
28 namespace Belle2 {
39  class RootOutputModule : public Module {
40 
41  public:
42 
46 
51  virtual ~RootOutputModule();
52 
57  virtual void initialize() override;
58 
63  virtual void event() override;
64 
70  virtual void terminate() override;
71 
73  virtual std::vector<std::string> getFileNames(bool outputFiles = true) override
74  {
75  B2ASSERT("RootOutput is not an input module", outputFiles);
77  // This will warn if already consumed which is what we want
78  std::string outputFileArgument = Environment::Instance().consumeOutputFileOverride(getName());
79  if (!outputFileArgument.empty())
80  m_outputFileName = outputFileArgument;
82  }
83  return {m_outputFileName};
84  }
85 
86  private:
87 
89  void closeFile();
90 
92  void openFile();
93 
100  void fillTree(DataStore::EDurability durability);
101 
103  void fillFileMetaData();
104 
105  //first the steerable variables:
106 
112  std::string m_outputFileName;
113 
119  std::vector<std::string> m_branchNames[DataStore::c_NDurabilityTypes];
120 
124  std::vector<std::string> m_additionalBranchNames[DataStore::c_NDurabilityTypes];
125 
131  std::vector<std::string> m_excludeBranchNames[DataStore::c_NDurabilityTypes];
132 
134  int m_compressionAlgorithm{0};
135 
137  int m_compressionLevel{1};
138 
143  int m_splitLevel;
144 
146  int m_autoflush;
147 
149  int m_autosave;
150 
152  int m_basketsize;
153 
155  bool m_updateFileCatalog;
156 
160 
163  boost::optional<uint64_t> m_outputSplitSize{boost::none};
164 
165  //then those for purely internal use:
166 
168  int m_fileIndex{0};
169 
171  TFile* m_file;
172 
175 
177  std::vector<DataStore::StoreEntry*> m_entries[DataStore::c_NDurabilityTypes];
178 
180  std::vector<std::string> m_parentLfns;
181 
183  std::map<std::string, std::string> m_additionalDataDescription;
184 
187  unsigned long m_experimentLow;
188 
191  unsigned long m_runLow;
192 
195  unsigned long m_eventLow;
196 
199  unsigned long m_experimentHigh;
200 
203  unsigned long m_runHigh;
204 
207  unsigned long m_eventHigh;
208 
210  bool m_buildIndex{true};
211 
213  bool m_keepParents{false};
214 
216  bool m_regularFile{true};
217 
219  StoreObjPtr<EventMetaData> m_eventMetaData;
224  };
226 } // end namespace Belle2
Belle2::RootOutputModule::getFileNames
virtual std::vector< std::string > getFileNames(bool outputFiles=true) override
Set the used output file, taking into account -o argument to basf2.
Definition: RootOutputModule.h:81
Belle2::RootOutputModule::m_branchNames
std::vector< std::string > m_branchNames[DataStore::c_NDurabilityTypes]
Array for names of branches that should be written out.
Definition: RootOutputModule.h:127
Belle2::RootOutputModule::m_experimentLow
unsigned long m_experimentLow
Lowest experiment number.
Definition: RootOutputModule.h:195
Belle2::RootOutputModule::m_updateFileCatalog
bool m_updateFileCatalog
Flag to enable or disable the update of the metadata catalog.
Definition: RootOutputModule.h:163
Belle2::RootOutputModule::m_keepParents
bool m_keepParents
Whether to keep parents same as that of input file.
Definition: RootOutputModule.h:221
Belle2::RootOutputModule::m_parentLfns
std::vector< std::string > m_parentLfns
Vector of parent file LFNs.
Definition: RootOutputModule.h:188
Belle2::RootOutputModule::m_eventLow
unsigned long m_eventLow
Lowest event number in lowest run.
Definition: RootOutputModule.h:203
Belle2::RootOutputModule::closeFile
void closeFile()
Finalize the output file.
Definition: RootOutputModule.cc:427
Belle2::RootOutputModule::event
virtual void event() override
Write data in c_Event DataStore maps.
Definition: RootOutputModule.cc:295
Belle2::RootOutputModule::~RootOutputModule
virtual ~RootOutputModule()
Destructor.
Belle2::RootOutputModule::m_outputSplitSize
boost::optional< uint64_t > m_outputSplitSize
Maximum output file size in MB.
Definition: RootOutputModule.h:171
Belle2::RootOutputModule::m_eventHigh
unsigned long m_eventHigh
Highest event number in highest run.
Definition: RootOutputModule.h:215
Belle2::RootOutputModule::RootOutputModule
RootOutputModule()
Constructor.
Definition: RootOutputModule.cc:50
Belle2::RootOutputModule::m_autosave
int m_autosave
Number of entries (if >0) or number of bytes (if <0) after which write the tree metadata to disk.
Definition: RootOutputModule.h:157
Belle2::RootOutputModule::initialize
virtual void initialize() override
Setting up of various stuff.
Belle2::FileMetaData
Metadata information about a file.
Definition: FileMetaData.h:39
Belle2::RootOutputModule::m_runHigh
unsigned long m_runHigh
Highest run number.
Definition: RootOutputModule.h:211
Belle2::RootOutputModule::m_compressionAlgorithm
int m_compressionAlgorithm
TFile compression algorithm.
Definition: RootOutputModule.h:142
Belle2::RootOutputModule::fillTree
void fillTree(DataStore::EDurability durability)
Fill TTree.
Definition: RootOutputModule.cc:482
Belle2::RootOutputModule::m_outputFileName
std::string m_outputFileName
Name for output file.
Definition: RootOutputModule.h:120
Belle2::RootOutputModule::m_experimentHigh
unsigned long m_experimentHigh
Highest experiment number.
Definition: RootOutputModule.h:207
Belle2::RootOutputModule::m_tree
TTree * m_tree[DataStore::c_NDurabilityTypes]
TTree for output.
Definition: RootOutputModule.h:182
Belle2::RootOutputModule::m_fileMetaData
StoreObjPtr< FileMetaData > m_fileMetaData
Pointer to the file meta data.
Definition: RootOutputModule.h:229
Belle2::Environment::consumeOutputFileOverride
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overriden output file name, or "" if none was set.
Definition: Environment.cc:64
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::DataStore::c_NDurabilityTypes
const static int c_NDurabilityTypes
Number of Durability Types.
Definition: DataStore.h:65
Belle2::RootOutputModule::terminate
virtual void terminate() override
Write data in the c_Persistent DataStore maps.
Definition: RootOutputModule.cc:422
Belle2::RootOutputModule::m_splitLevel
int m_splitLevel
Branch split level.
Definition: RootOutputModule.h:151
Belle2::RootOutputModule::fillFileMetaData
void fillFileMetaData()
Create and fill FileMetaData object.
Definition: RootOutputModule.cc:356
Belle2::RootOutputModule::m_ignoreCommandLineOverride
bool m_ignoreCommandLineOverride
Ignore filename override from command line.
Definition: RootOutputModule.h:167
Belle2::RootOutputModule::m_runLow
unsigned long m_runLow
Lowest run number.
Definition: RootOutputModule.h:199
Belle2::RootOutputModule::m_file
TFile * m_file
TFile for output.
Definition: RootOutputModule.h:179
Belle2::RootOutputModule::m_additionalBranchNames
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.
Definition: RootOutputModule.h:132
Belle2::RootOutputModule::m_entries
std::vector< DataStore::StoreEntry * > m_entries[DataStore::c_NDurabilityTypes]
Vector of DataStore entries that are written to the output.
Definition: RootOutputModule.h:185
Belle2::DataStore::c_Persistent
@ c_Persistent
Object is available during entire execution time.
Definition: DataStore.h:62
Belle2::RootOutputModule::m_autoflush
int m_autoflush
Number of entries (if >0) or number of bytes (if <0) after which to flush all baskets to disk.
Definition: RootOutputModule.h:154
Belle2::RootOutputModule::m_excludeBranchNames
std::vector< std::string > m_excludeBranchNames[DataStore::c_NDurabilityTypes]
Array for names of branches that should NOT be written out.
Definition: RootOutputModule.h:139
Belle2::RootOutputModule::m_outputFileMetaData
FileMetaData m_outputFileMetaData
File meta data finally stored in the output file.
Definition: RootOutputModule.h:231
Belle2::RootOutputModule::m_regularFile
bool m_regularFile
Whether this is a regular, local file where we can actually create directories.
Definition: RootOutputModule.h:224
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
Belle2::RootOutputModule::m_additionalDataDescription
std::map< std::string, std::string > m_additionalDataDescription
Map of additional metadata to be added to the output file.
Definition: RootOutputModule.h:191
Belle2::Module::getName
const std::string & getName() const
Returns the name of the module.
Definition: Module.h:189
Belle2::RootOutputModule::m_buildIndex
bool m_buildIndex
Whether or not we want to build an event index.
Definition: RootOutputModule.h:218
Belle2::RootOutputModule::m_compressionLevel
int m_compressionLevel
TFile compression level.
Definition: RootOutputModule.h:145
Belle2::RootOutputModule::m_basketsize
int m_basketsize
basket size for each branch in the file in bytes
Definition: RootOutputModule.h:160
Belle2::RootOutputModule::openFile
void openFile()
Open the next output file.
Definition: RootOutputModule.cc:174
Belle2::RootOutputModule::m_fileIndex
int m_fileIndex
Keep track of the file index: if we split files than we add '.f{fileIndex:05d}' in front of the ROOT ...
Definition: RootOutputModule.h:176
Belle2::DataStore::EDurability
EDurability
Durability types.
Definition: DataStore.h:60
Belle2::RootOutputModule::m_eventMetaData
StoreObjPtr< EventMetaData > m_eventMetaData
Pointer to the event meta data.
Definition: RootOutputModule.h:227