Belle II Software  release-05-02-19
RootInputModule.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Heck, Christian Pulvermacher, 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/datastore/DataStore.h>
15 #include <framework/core/Environment.h>
16 #include <framework/dataobjects/FileMetaData.h>
17 #include <framework/dataobjects/EventMetaData.h>
18 
19 #include <string>
20 #include <vector>
21 #include <set>
22 
23 #include <TChain.h>
24 #include <TFile.h>
25 
26 
27 namespace Belle2 {
44  class RootInputModule : public Module {
45  public:
46 
49 
51  virtual ~RootInputModule();
52 
54  virtual void initialize() override;
55 
57  virtual void event() override;
58 
60  virtual void terminate() override;
61 
63  virtual std::vector<std::string> getFileNames(bool outputFiles = false) override
64  {
65  B2ASSERT("RootInput is not an output module", !outputFiles);
66  std::vector<std::string> inputFiles = Environment::Instance().getInputFilesOverride();
67  if (!m_ignoreCommandLineOverride and !inputFiles.empty()) {
68  return inputFiles;
69  }
70  inputFiles = m_inputFileNames;
71  if (!m_inputFileName.empty())
72  inputFiles.push_back(m_inputFileName);
73  return inputFiles;
74  }
75 
76  protected:
77 
78 
79  private:
80  typedef std::vector<DataStore::StoreEntry*> StoreEntries;
83  void readTree();
84 
93  bool connectBranches(TTree* tree, DataStore::EDurability durability, StoreEntries* storeEntries);
94 
97 
99  bool readParentTrees();
100 
102  void readPersistentEntry(long fileEntry);
103 
105  void entryNotFound(const std::string& entryOrigin, const std::string& name, bool fileChanged = true);
106 
108  void addEventListForIndexFile(const std::string& parentLfn);
109 
111  void realDataWorkaround(FileMetaData& metaData);
112 
113  //first the steerable variables:
115  std::string m_inputFileName;
116 
118  std::vector<std::string> m_inputFileNames;
119 
123  std::vector<std::string> m_entrySequences;
124 
127 
134  std::vector<std::string> m_branchNames[DataStore::c_NDurabilityTypes];
135 
141  std::vector<std::string> m_excludeBranchNames[DataStore::c_NDurabilityTypes];
142 
143 
145  unsigned int m_skipNEvents;
146 
148  int m_parentLevel;
149 
151  bool m_collectStatistics;
152 
154  std::vector<int> m_skipToEvent;
155 
156  //then those for purely internal use:
157 
160 
163 
165  std::string m_lastParentFileLFN;
166 
167 
169  TChain* m_tree;
170 
172  TChain* m_persistent;
173 
175  std::set<std::string> m_connectedBranches[DataStore::c_NDurabilityTypes];
176 
181 
183  std::vector<StoreEntries> m_parentStoreEntries;
184 
186  std::map<std::string, TTree*> m_parentTrees;
187 
189  struct ReadStats {
190  long calls{0};
191  long bytesRead{0};
192  long bytesReadExtra{0};
194  void add(const ReadStats& b)
195  {
196  calls += b.calls;
197  bytesRead += b.bytesRead;
198  bytesReadExtra += b.bytesReadExtra;
199  }
201  void addFromFile(const TFile* f)
202  {
203  calls += f->GetReadCalls();
204  bytesRead += f->GetBytesRead();
205  bytesReadExtra += f->GetBytesReadExtra();
206  }
208  std::string getString() const
209  {
210  std::string s;
211  s += "read: " + std::to_string(bytesRead) + " Bytes";
212  s += ", overhead: " + std::to_string(bytesReadExtra) + " Bytes";
213  s += ", Read() calls: " + std::to_string(calls);
214  return s;
215  }
216  };
217 
220 
222  int m_cacheSize{0};
223 
225  bool m_discardErrorEvents{true};
228 
231  };
233 } // end namespace Belle2
Belle2::RootInputModule::createParentStoreEntries
bool createParentStoreEntries()
Connect the parent trees and fill m_parentStoreEntries.
Definition: RootInputModule.cc:561
Belle2::RootInputModule::StoreEntries
std::vector< DataStore::StoreEntry * > StoreEntries
Vector of entries in the data store.
Definition: RootInputModule.h:88
Belle2::RootInputModule::m_inputFileNames
std::vector< std::string > m_inputFileNames
Files to read from.
Definition: RootInputModule.h:126
Belle2::RootInputModule::m_discardErrorEvents
bool m_discardErrorEvents
Discard events that have an error flag != 0.
Definition: RootInputModule.h:233
Belle2::RootInputModule::ReadStats::bytesRead
long bytesRead
total number of bytes read.
Definition: RootInputModule.h:199
Belle2::RootInputModule::readParentTrees
bool readParentTrees()
Read data of the current event from the parents.
Definition: RootInputModule.cc:618
Belle2::RootInputModule::m_ignoreCommandLineOverride
bool m_ignoreCommandLineOverride
Ignore filename override from command line.
Definition: RootInputModule.h:134
Belle2::Environment::getInputFilesOverride
const std::vector< std::string > & getInputFilesOverride() const
Return overriden input file names, or empty vector if none were set.
Definition: Environment.h:111
Belle2::RootInputModule::addEventListForIndexFile
void addEventListForIndexFile(const std::string &parentLfn)
For index files, this creates TEventList/TEntryListArray to enable better cache use.
Definition: RootInputModule.cc:677
Belle2::RootInputModule::m_persistentStoreEntries
StoreEntries m_persistentStoreEntries
Vector of DataStore entries of persistent durability that we are supposed to read in.
Definition: RootInputModule.h:188
Belle2::RootInputModule::m_storeEntries
StoreEntries m_storeEntries
Vector of DataStore entries of event durability that we are supposed to read in.
Definition: RootInputModule.h:186
Belle2::RootInputModule::m_parentTrees
std::map< std::string, TTree * > m_parentTrees
Map of file LFNs to trees.
Definition: RootInputModule.h:194
Belle2::RootInputModule::m_persistent
TChain * m_persistent
TTree for persistent input.
Definition: RootInputModule.h:180
Belle2::RootInputModule::initialize
virtual void initialize() override
Initialize the Module.
Definition: RootInputModule.cc:98
Belle2::RootInputModule::getFileNames
virtual std::vector< std::string > getFileNames(bool outputFiles=false) override
Get list of input files, taking -i command line overrides into account.
Definition: RootInputModule.h:71
Belle2::RootInputModule::entryNotFound
void entryNotFound(const std::string &entryOrigin, const std::string &name, bool fileChanged=true)
Check if we warn the user or abort after an entry was missing after changing files.
Definition: RootInputModule.cc:721
Belle2::FileMetaData
Metadata information about a file.
Definition: FileMetaData.h:39
Belle2::RootInputModule::readTree
void readTree()
Actually performs the reading from the tree.
Definition: RootInputModule.cc:415
Belle2::RootInputModule::m_collectStatistics
bool m_collectStatistics
Collect statistics on amount of data read and print statistics (seperate for input & parent files) af...
Definition: RootInputModule.h:159
Belle2::RootInputModule::m_readStats
ReadStats m_readStats
some statistics for all files read so far.
Definition: RootInputModule.h:227
Belle2::RootInputModule::ReadStats
for collecting statistics over multiple files.
Definition: RootInputModule.h:197
Belle2::RootInputModule::m_parentStoreEntries
std::vector< StoreEntries > m_parentStoreEntries
The parent DataStore entries per level.
Definition: RootInputModule.h:191
Belle2::RootInputModule::RootInputModule
RootInputModule()
Constructor.
Definition: RootInputModule.cc:41
Belle2::RootInputModule::m_tree
TChain * m_tree
TTree for event input.
Definition: RootInputModule.h:177
Belle2::RootInputModule::readPersistentEntry
void readPersistentEntry(long fileEntry)
Loads given entry from persistent tree.
Definition: RootInputModule.cc:731
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RootInputModule::m_connectedBranches
std::set< std::string > m_connectedBranches[DataStore::c_NDurabilityTypes]
Already connected branches.
Definition: RootInputModule.h:183
Belle2::RootInputModule::m_discardErrorMask
unsigned int m_discardErrorMask
Don't issue a warning when discarding events if the error flag consists exclusively of flags in this ...
Definition: RootInputModule.h:235
Belle2::RootInputModule::ReadStats::add
void add(const ReadStats &b)
add other stats object.
Definition: RootInputModule.h:202
Belle2::DataStore::c_NDurabilityTypes
const static int c_NDurabilityTypes
Number of Durability Types.
Definition: DataStore.h:65
Belle2::RootInputModule::m_inputFileName
std::string m_inputFileName
File to read from.
Definition: RootInputModule.h:123
Belle2::RootInputModule::m_skipToEvent
std::vector< int > m_skipToEvent
experiment, run, event number of first event to load
Definition: RootInputModule.h:162
Belle2::RootInputModule::m_branchNames
std::vector< std::string > m_branchNames[DataStore::c_NDurabilityTypes]
Array for names of branches, that shall be written out.
Definition: RootInputModule.h:142
Belle2::RootInputModule::m_entrySequences
std::vector< std::string > m_entrySequences
The number sequences (e.g.
Definition: RootInputModule.h:131
Belle2::RootInputModule::m_lastPersistentEntry
long m_lastPersistentEntry
last entry to be in persistent tree.
Definition: RootInputModule.h:170
Belle2::RootInputModule::m_excludeBranchNames
std::vector< std::string > m_excludeBranchNames[DataStore::c_NDurabilityTypes]
Array for names of branches that should NOT be written out.
Definition: RootInputModule.h:149
Belle2::EventMetaData::c_HLTDiscard
@ c_HLTDiscard
The HLT discarded the event and only metadata is kept.
Definition: EventMetaData.h:58
Belle2::RootInputModule::connectBranches
bool connectBranches(TTree *tree, DataStore::EDurability durability, StoreEntries *storeEntries)
Connect branches of the given tree to the data store.
Definition: RootInputModule.cc:496
Belle2::RootInputModule::ReadStats::calls
long calls
number of read calls.
Definition: RootInputModule.h:198
Belle2::RootInputModule::realDataWorkaround
void realDataWorkaround(FileMetaData &metaData)
Correct isMC flag for raw data recorded before experiment 8 run 2364.
Definition: RootInputModule.cc:771
Belle2::RootInputModule::event
virtual void event() override
Running over all events.
Definition: RootInputModule.cc:336
Belle2::RootInputModule::terminate
virtual void terminate() override
Is called at the end of your Module.
Definition: RootInputModule.cc:383
Belle2::RootInputModule::m_cacheSize
int m_cacheSize
Input ROOT File Cache size in MB, <0 means default.
Definition: RootInputModule.h:230
Belle2::RootInputModule::m_nextEntry
long m_nextEntry
Next entry to be read in event tree.
Definition: RootInputModule.h:167
Belle2::RootInputModule::~RootInputModule
virtual ~RootInputModule()
Destructor.
Belle2::RootInputModule::ReadStats::addFromFile
void addFromFile(const TFile *f)
add current statistics from TFile object.
Definition: RootInputModule.h:209
Belle2::RootInputModule::ReadStats::bytesReadExtra
long bytesReadExtra
what TFile thinks was the overhead.
Definition: RootInputModule.h:200
Belle2::RootInputModule::m_processingAllEvents
bool m_processingAllEvents
Set to true if we process the input files completely: No skip events or sequences or -n parameters.
Definition: RootInputModule.h:238
Belle2::RootInputModule::m_skipNEvents
unsigned int m_skipNEvents
Can be set from steering file to skip the first N events.
Definition: RootInputModule.h:153
Belle2::RootInputModule::m_parentLevel
int m_parentLevel
Level of parent files to be read.
Definition: RootInputModule.h:156
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
Belle2::RootInputModule::ReadStats::getString
std::string getString() const
string suitable for printing.
Definition: RootInputModule.h:216
Belle2::RootInputModule::m_lastParentFileLFN
std::string m_lastParentFileLFN
last parent file LFN seen.
Definition: RootInputModule.h:173
Belle2::DataStore::EDurability
EDurability
Durability types.
Definition: DataStore.h:60