LDMX Software
EventFile.h
1#ifndef FRAMEWORK_EVENT_EVENTFILE_H_
2#define FRAMEWORK_EVENT_EVENTFILE_H_
3
4//---< C++ >---//
5#include <map>
6#include <string>
7#include <vector>
8
9//---< Framework >---//
10#include "Framework/Configure/Parameters.h"
11#include "Framework/Event.h"
12#include "Framework/Logger.h"
13
14//---< ROOT >---//
15#include "TFile.h"
16#include "TTree.h"
17
18namespace ldmx {
19class RunHeader;
20}
21
22namespace framework {
23
27class EventFile {
28 public:
44 const std::string &filename, EventFile *parent, bool isOutputFile,
45 bool isSingleOutput, bool isLoopable);
46
60 const std::string &fileName, bool isLoopable);
61
75 const std::string &fileName, EventFile *parent,
76 bool isSingleOutput = false);
77
90 const std::string &fileName);
91
97 ~EventFile();
98
117 bool isCorrupted() const;
118
158 void addDrop(const std::string &rule);
159
164 void setupEvent(Event *evt);
165
176 void updateParent(EventFile *parent);
177
182 Event *getEvent() { return event_; };
183
213 bool nextEvent(bool storeCurrentEvent = true);
214
219 int skipToEvent(int offset);
220
230 void writeRunHeader(ldmx::RunHeader &runHeader);
231
239 void writeRunTree();
240
247 ldmx::RunHeader *getRunHeaderPtr(int runNumber);
248
256 ldmx::RunHeader &getRunHeader(int runNumber);
257
259 const std::string &getFileName() { return file_name_; }
260
261 private:
278 void importRunHeaders();
279
280 private:
282 Long64_t entries_{-1};
283
285 Long64_t ientry_{-1};
286
288 std::string file_name_;
289
292
295
297 bool is_loopable_{false};
298
300 TFile *file_{nullptr};
301
303 TTree *tree_{nullptr};
304
307
309 Event *event_{nullptr};
310
317 std::vector<std::pair<std::string, bool>> pre_clone_rules_;
318
326 std::vector<std::string> reactivate_rules_;
327
338 std::map<int, std::pair<bool, ldmx::RunHeader *>> run_map_;
339
340 enableLogging("EventFile")
341};
342} // namespace framework
343
344#endif // FRAMEWORK_EVENT_EVENTFILE_H
Class implementing an event buffer system for storing event data.
This class manages all ROOT file input/output operations.
Definition EventFile.h:27
void updateParent(EventFile *parent)
Change pointer to different parent file.
const std::string & getFileName()
Definition EventFile.h:259
TFile * file_
The backing TFile for this EventFile.
Definition EventFile.h:300
void addDrop(const std::string &rule)
Add a rule for dropping collections from the output.
void setupEvent(Event *evt)
Set an Event object containing the event data to work with this file.
std::map< int, std::pair< bool, ldmx::RunHeader * > > run_map_
Map of run numbers to RunHeader objects.
Definition EventFile.h:338
Long64_t entries_
The number of entries in the tree.
Definition EventFile.h:282
void writeRunTree()
Write the map of run headers to the file as a TTree of RunHeader.
bool nextEvent(bool storeCurrentEvent=true)
Prepare the next event.
Event * getEvent()
Get the Event object containing the event data.
Definition EventFile.h:182
ldmx::RunHeader * getRunHeaderPtr(int runNumber)
Update the RunHeader for a given run, if it exists in the input file.
Long64_t ientry_
The current entry in the tree.
Definition EventFile.h:285
std::vector< std::pair< std::string, bool > > pre_clone_rules_
Pre-clone rules.
Definition EventFile.h:317
void writeRunHeader(ldmx::RunHeader &runHeader)
Write the run header into the run map.
bool is_loopable_
True if this is an input file with pileup overlay events *‍/.
Definition EventFile.h:297
~EventFile()
Destructor.
void importRunHeaders()
Fill the internal map of run numbers to RunHeader objects from the input file.
int skipToEvent(int offset)
Skip events using an offset.
std::string file_name_
The file name.
Definition EventFile.h:288
ldmx::RunHeader & getRunHeader(int runNumber)
Get the RunHeader for a given run, if it exists in the input file.
bool is_single_output_
True if there is only one output file.
Definition EventFile.h:294
EventFile(const framework::config::Parameters &params, const std::string &filename, EventFile *parent, bool isOutputFile, bool isSingleOutput, bool isLoopable)
Constructor to make a general file.
Definition EventFile.cxx:15
EventFile * parent_
A parent file containing event data.
Definition EventFile.h:306
std::vector< std::string > reactivate_rules_
Vector of drop rules that have been parsed and need to be used to reactivate these branches on the in...
Definition EventFile.h:326
bool is_output_file_
True if file is an output file being written to disk.
Definition EventFile.h:291
TTree * tree_
The tree with event data.
Definition EventFile.h:303
Event * event_
The object containing the actual event data (trees and branches).
Definition EventFile.h:309
bool isCorrupted() const
Check if the file we have is corrupted.
Implements an event buffer system for storing event data.
Definition Event.h:42
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Run-specific configuration and data stored in its own output TTree alongside the event TTree in the o...
Definition RunHeader.h:57
All classes in the ldmx-sw project use this namespace.