LDMX Software
EventFile.h
1#ifndef FRAMEWORK_EVENT_EVENTFILE_H_
2#define FRAMEWORK_EVENT_EVENTFILE_H_
3
4//---< C++ >---//
5#include <map>
6#include <memory>
7#include <string>
8#include <vector>
9
10//---< Framework >---//
11#include "Framework/Configure/Parameters.h"
12#include "Framework/Event.h"
13#include "Framework/Logger.h"
14
15//---< ROOT >---//
16#include "TFile.h"
17#include "TTree.h"
18
19namespace ldmx {
20class RunHeader;
21}
22
23namespace framework {
24
28class EventFile {
29 public:
45 const std::string& filename, EventFile* parent, bool isOutputFile,
46 bool isSingleOutput, bool isLoopable);
47
61 const std::string& fileName, bool isLoopable);
62
76 const std::string& fileName, EventFile* parent,
77 bool isSingleOutput = false);
78
91 const std::string& fileName);
92
98 ~EventFile();
99
118 bool isCorrupted() const;
119
159 void addDrop(const std::string& rule);
160
165 void setupEvent(Event* evt);
166
177 void updateParent(EventFile* parent);
178
183 Event* getEvent() { return event_; };
184
214 bool nextEvent(bool storeCurrentEvent = true);
215
220 int skipToEvent(int offset);
221
228 void writeRunHeader(std::shared_ptr<ldmx::RunHeader> runHeader);
229
241 void writeRunTree(bool completed = false);
242
249 ldmx::RunHeader* getRunHeaderPtr(int runNumber);
250
258 ldmx::RunHeader& getRunHeader(int runNumber);
259
261 const std::string& getFileName() { return file_name_; }
262
275 std::vector<int> getIncompleteRuns() const;
276
277 private:
293 void importRunHeaders();
294
295 private:
297 Long64_t entries_{-1};
298
300 Long64_t ientry_{-1};
301
303 std::string file_name_;
304
307
310
312 bool is_loopable_{false};
313
315 TFile* file_{nullptr};
316
318 TTree* tree_{nullptr};
319
322
324 Event* event_{nullptr};
325
332 std::vector<std::pair<std::string, bool>> pre_clone_rules_;
333
341 std::vector<std::string> reactivate_rules_;
342
344 std::map<int, std::shared_ptr<ldmx::RunHeader>> run_map_;
345
347 TTree* run_tree_{nullptr};
348
351
352 enableLogging("EventFile")
353};
354} // namespace framework
355
356#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:28
void updateParent(EventFile *parent)
Change pointer to different parent file.
const std::string & getFileName()
Definition EventFile.h:261
TFile * file_
The backing TFile for this EventFile.
Definition EventFile.h:315
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::shared_ptr< ldmx::RunHeader > > run_map_
Map of run numbers to RunHeader objects (owned via shared_ptr)
Definition EventFile.h:344
Long64_t entries_
The number of entries in the tree.
Definition EventFile.h:297
void writeRunHeader(std::shared_ptr< ldmx::RunHeader > runHeader)
Write the run header into the run map.
bool nextEvent(bool storeCurrentEvent=true)
Prepare the next event.
Event * getEvent()
Get the Event object containing the event data.
Definition EventFile.h:183
void writeRunTree(bool completed=false)
Write the map of run headers to the file as a TTree of RunHeader.
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:300
std::vector< std::pair< std::string, bool > > pre_clone_rules_
Pre-clone rules.
Definition EventFile.h:332
bool run_headers_have_completeness_
True when the run headers we read were written with a completion flag.
Definition EventFile.h:350
TTree * run_tree_
The run tree, owned by file_ once written.
Definition EventFile.h:347
bool is_loopable_
True if this is an input file with pileup overlay events *‍/.
Definition EventFile.h:312
~EventFile()
Destructor.
void importRunHeaders()
Fill the internal map of run numbers to RunHeader objects from the input file.
std::vector< int > getIncompleteRuns() const
The runs in this file whose writer did not close cleanly.
int skipToEvent(int offset)
Skip events using an offset.
std::string file_name_
The file name.
Definition EventFile.h:303
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:309
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:30
EventFile * parent_
A parent file containing event data.
Definition EventFile.h:321
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:341
bool is_output_file_
True if file is an output file being written to disk.
Definition EventFile.h:306
TTree * tree_
The tree with event data.
Definition EventFile.h:318
Event * event_
The object containing the actual event data (trees and branches).
Definition EventFile.h:324
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:67
All classes in the ldmx-sw project use this namespace.