|
LDMX Software
|
This class manages all ROOT file input/output operations. More...
#include <EventFile.h>
Public Member Functions | |
| EventFile (const framework::config::Parameters ¶ms, const std::string &filename, EventFile *parent, bool isOutputFile, bool isSingleOutput, bool isLoopable) | |
| Constructor to make a general file. | |
| EventFile (const framework::config::Parameters ¶m, const std::string &fileName, bool isLoopable) | |
| Constructor to make a pileup overlay file. | |
| EventFile (const framework::config::Parameters ¶m, const std::string &fileName, EventFile *parent, bool isSingleOutput=false) | |
| Class constructor for cloning data from a "parent" file. | |
| EventFile (const framework::config::Parameters ¶ms, const std::string &fileName) | |
| Class constructor to make a file to read in an event root file. | |
| ~EventFile () | |
| Destructor. | |
| bool | isCorrupted () const |
| Check if the file we have is corrupted. | |
| 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. | |
| void | updateParent (EventFile *parent) |
| Change pointer to different parent file. | |
| Event * | getEvent () |
| Get the Event object containing the event data. | |
| bool | nextEvent (bool storeCurrentEvent=true) |
| Prepare the next event. | |
| int | skipToEvent (int offset) |
| Skip events using an offset. | |
| void | writeRunHeader (std::shared_ptr< ldmx::RunHeader > runHeader) |
| Write the run header into the run map. | |
| 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. | |
| ldmx::RunHeader & | getRunHeader (int runNumber) |
| Get the RunHeader for a given run, if it exists in the input file. | |
| const std::string & | getFileName () |
| std::vector< int > | getIncompleteRuns () const |
| The runs in this file whose writer did not close cleanly. | |
Private Member Functions | |
| void | importRunHeaders () |
| Fill the internal map of run numbers to RunHeader objects from the input file. | |
Private Attributes | |
| Long64_t | entries_ {-1} |
| The number of entries in the tree. | |
| Long64_t | ientry_ {-1} |
| The current entry in the tree. | |
| std::string | file_name_ |
| The file name. | |
| bool | is_output_file_ |
| True if file is an output file being written to disk. | |
| bool | is_single_output_ |
| True if there is only one output file. | |
| bool | is_loopable_ {false} |
| True if this is an input file with pileup overlay events */. | |
| TFile * | file_ {nullptr} |
| The backing TFile for this EventFile. | |
| TTree * | tree_ {nullptr} |
| The tree with event data. | |
| EventFile * | parent_ {nullptr} |
| A parent file containing event data. | |
| Event * | event_ {nullptr} |
| The object containing the actual event data (trees and branches). | |
| std::vector< std::pair< std::string, bool > > | pre_clone_rules_ |
| Pre-clone rules. | |
| 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 input tree. | |
| std::map< int, std::shared_ptr< ldmx::RunHeader > > | run_map_ |
| Map of run numbers to RunHeader objects (owned via shared_ptr) | |
| TTree * | run_tree_ {nullptr} |
| The run tree, owned by file_ once written. | |
| bool | run_headers_have_completeness_ {false} |
| True when the run headers we read were written with a completion flag. | |
This class manages all ROOT file input/output operations.
Definition at line 28 of file EventFile.h.
| framework::EventFile::EventFile | ( | const framework::config::Parameters & | params, |
| const std::string & | filename, | ||
| EventFile * | parent, | ||
| bool | isOutputFile, | ||
| bool | isSingleOutput, | ||
| bool | isLoopable ) |
Constructor to make a general file.
This is not used directly, but it is called in the more specialised constructors. This method is mainly focused on reducing code copying.
| [in] | params | The parameters used to configure this EventFile. |
| [in] | filename | the name of the file to read/write |
| [in] | parent | a pointer to the parent file to copy |
| [in] | isOutputFile | true if this file is written out |
| [in] | isSingleOutput | true if only one output file is being written to |
| [in] | isLoopable | true for an input file where events can be reused |
Definition at line 30 of file EventFile.cxx.
References entries_, file_, file_name_, framework::config::Parameters::get(), importRunHeaders(), is_output_file_, parent_, pre_clone_rules_, reactivate_rules_, and tree_.
| framework::EventFile::EventFile | ( | const framework::config::Parameters & | param, |
| const std::string & | fileName, | ||
| bool | isLoopable ) |
Constructor to make a pileup overlay file.
This is an additional input file from which collections are pulled to be overlaid with simulated hit collections.
| [in] | params | The parameters used to configure this EventFile. |
| fileName | The file name. | |
| isLoopable | true if we want to reset the event counter and keep processing from the start when we hit the end of the event tree in this input file (set in the call in the producer) |
Definition at line 109 of file EventFile.cxx.
| framework::EventFile::EventFile | ( | const framework::config::Parameters & | param, |
| const std::string & | fileName, | ||
| EventFile * | parent, | ||
| bool | isSingleOutput = false ) |
Class constructor for cloning data from a "parent" file.
This is used for output files when there is an input file. (OR for files with a parent EventFile to clone)
| [in] | params | The parameters used to configure this EventFile. |
| [in] | fileName | The file name. |
| [in] | parent | Parent file for cloning data tree. |
| [in] | isSingleOutput | boolean check if only one output file is being written to |
Definition at line 117 of file EventFile.cxx.
| framework::EventFile::EventFile | ( | const framework::config::Parameters & | params, |
| const std::string & | fileName ) |
Class constructor to make a file to read in an event root file.
This constructor just wraps the constructor above and sets the parent to null and the parameters isOutputFile/isSingleOutput to false.
This is used for all input files.
| [in] | params | The parameters used to configure this EventFile. |
| [in] | fileName | The file name. |
Definition at line 113 of file EventFile.cxx.
| framework::EventFile::~EventFile | ( | ) |
Destructor.
Make sure to close the file when we destruct
Definition at line 122 of file EventFile.cxx.
References file_, is_output_file_, and tree_.
| void framework::EventFile::addDrop | ( | const std::string & | rule | ) |
Add a rule for dropping collections from the output.
This needs to be called after setupEvent. This method uses the event to help drop collections.
The rules should be of the following form: <drop,keep, or ignore> exp where exp is an expression that matches the collectionName. ignore ==> any branch with name matching exp is not even read in from the input file (if it exists) keep ==> any branch with name matching exp is read in from the input (if exists) and written to output (if exists) drop ==> any branch with name matching exp is read in from the input (if exists) and NOT written to output
The default behavior for all branches is keep.
ROOT uses the internal TRegexp to match branch names to the passed expression and set the status of the branch (whether it will be read or not). This internal object has different rules than real regular expressions, so it is best to keep it safe and only use asterisks or full names. Additionally, the rules you pass are analyzed in succession, so you can go from something more general to something more specific.
For example to drop all EcalSimHits.* drop EcalSimHits.*
or drop scoring plane collections drop .*ScoringPlane.*
or drop scoring plane collections but keep EcalScoringPlane collection drop .*ScoringPlane.* keep EcalScoringPlane.*
| rule | The rule for dropping collections. |
Definition at line 137 of file EventFile.cxx.
References framework::Event::addDrop(), framework::Event::addIgnore(), ldmx::EventHeader::BRANCH, event_, pre_clone_rules_, and reactivate_rules_.
Referenced by framework::Process::run().
|
inline |
|
inline |
Definition at line 261 of file EventFile.h.
References file_name_.
Referenced by framework::Process::run().
| std::vector< int > framework::EventFile::getIncompleteRuns | ( | ) | const |
The runs in this file whose writer did not close cleanly.
Events are missing from the end of any such run, so processing it silently would produce a biased sample.
A file written before ldmx::RunHeader::VERSION_WITH_COMPLETED carries no completion flag. We cannot say anything about those runs, so they are left out rather than reported as incomplete.
Definition at line 441 of file EventFile.cxx.
References run_headers_have_completeness_, and run_map_.
Referenced by framework::Process::run().
| ldmx::RunHeader & framework::EventFile::getRunHeader | ( | int | runNumber | ) |
Get the RunHeader for a given run, if it exists in the input file.
| runNumber | The run number. |
| Exception | if there is no RunHeader in the map with the given run number. |
Definition at line 432 of file EventFile.cxx.
References getRunHeaderPtr().
| ldmx::RunHeader * framework::EventFile::getRunHeaderPtr | ( | int | runNumber | ) |
Update the RunHeader for a given run, if it exists in the input file.
| [in] | runNumber | The run number. |
Definition at line 425 of file EventFile.cxx.
References run_map_.
Referenced by getRunHeader(), and framework::Process::run().
|
private |
Fill the internal map of run numbers to RunHeader objects from the input file.
If this file is an output file and parent_ and parent_->file_ are valid pointers, then the run headers are imported from parent_->file_.
Otherwise, we try to import run headers from file_.
Does not check if any run headers are getting overwritten!
RunHeaders read in from this function are stored as shared_ptr.
Definition at line 451 of file EventFile.cxx.
References file_, is_output_file_, parent_, run_headers_have_completeness_, run_map_, and ldmx::RunHeader::VERSION_WITH_COMPLETED.
Referenced by EventFile(), and updateParent().
| bool framework::EventFile::isCorrupted | ( | ) | const |
Check if the file we have is corrupted.
The check on if the file is corrupted is only helpful for input files, but we attempt to have a resonable definition for output files as well.
There are two ways a file can be corrupted and these may not be mutually exclusive.
For output files, we just check the IsZombie flag of the TFile. Again, since we are actively writing to this file, a corruption check is not very stable.
Definition at line 132 of file EventFile.cxx.
References file_, is_output_file_, and tree_.
Referenced by framework::Process::run().
| bool framework::EventFile::nextEvent | ( | bool | storeCurrentEvent = true | ) |
Prepare the next event.
We do the necessary set-up if ientry_ < 0. This means if we are an output file with a parent file, we clone our parent tree to our tree so we have the same branches.
After the first entry (when ientry_ >= 0), we "close up" the last event, filling our tree if we storeCurrentEvent is true and telling the event bus to clear.
Going to the next event depends on the configuration of the event file. THere are three cases.
| [in] | storeCurrentEvent | Should we save the current event to the output (if we are an output file)? |
Definition at line 221 of file EventFile.cxx.
References framework::Event::beforeFill(), framework::Event::clear(), entries_, event_, file_, ientry_, is_loopable_, is_output_file_, is_single_output_, framework::Event::nextEvent(), nextEvent(), framework::Event::onEndOfEvent(), parent_, pre_clone_rules_, reactivate_rules_, framework::Event::setInputTree(), framework::Event::setOutputTree(), and tree_.
Referenced by nextEvent(), and framework::Process::run().
| void framework::EventFile::setupEvent | ( | Event * | evt | ) |
Set an Event object containing the event data to work with this file.
| evt | The Event object with event data. |
Definition at line 303 of file EventFile.cxx.
References framework::Event::createTree(), entries_, event_, ientry_, is_output_file_, parent_, framework::Event::setInputTree(), framework::Event::setOutputTree(), and tree_.
Referenced by framework::Process::run().
| int framework::EventFile::skipToEvent | ( | int | offset | ) |
| void framework::EventFile::updateParent | ( | EventFile * | parent | ) |
Change pointer to different parent file.
We assume that the parent file is an EventFile configured to be an input file. This allows us to assume that the tree_ member variable of parent is valid.
| parent | pointer to new parent file |
Definition at line 337 of file EventFile.cxx.
References file_, ientry_, importRunHeaders(), parent_, pre_clone_rules_, reactivate_rules_, and tree_.
Referenced by framework::Process::run().
| void framework::EventFile::writeRunHeader | ( | std::shared_ptr< ldmx::RunHeader > | runHeader | ) |
Write the run header into the run map.
| runHeader | shared pointer to the run header to store |
| Exception | if run number is already in run map |
Definition at line 414 of file EventFile.cxx.
References run_map_.
Referenced by framework::Process::run().
| void framework::EventFile::writeRunTree | ( | bool | completed = false | ) |
Write the map of run headers to the file as a TTree of RunHeader.
Safe to call more than once; any run tree already in the file is overwritten. Process calls it once the producers have filled the headers and again on close, so a killed job still leaves a usable file.
| [in] | completed | true when closing cleanly. Only the final call should pass true. |
| Exception | if call this function on a non-output file. |
ROOT requires us to be in the correct directory when we create the output TTree for us to have it written into the correct location.
In order to allow downstream processors to getHistoDirectory() and enter that directory for this histograms we need to enter the output event file again here so that our run tree ends up in the correct location.
Definition at line 368 of file EventFile.cxx.
References file_, is_output_file_, run_map_, and run_tree_.
Referenced by framework::Process::newRun(), and framework::Process::run().
|
private |
The number of entries in the tree.
Definition at line 297 of file EventFile.h.
Referenced by EventFile(), nextEvent(), setupEvent(), and skipToEvent().
|
private |
The object containing the actual event data (trees and branches).
Definition at line 324 of file EventFile.h.
Referenced by addDrop(), getEvent(), nextEvent(), and setupEvent().
|
private |
The backing TFile for this EventFile.
Definition at line 315 of file EventFile.h.
Referenced by EventFile(), importRunHeaders(), isCorrupted(), nextEvent(), updateParent(), writeRunTree(), and ~EventFile().
|
private |
The file name.
Definition at line 303 of file EventFile.h.
Referenced by EventFile(), and getFileName().
|
private |
The current entry in the tree.
Definition at line 300 of file EventFile.h.
Referenced by nextEvent(), setupEvent(), skipToEvent(), and updateParent().
|
private |
True if this is an input file with pileup overlay events */.
Definition at line 312 of file EventFile.h.
Referenced by nextEvent().
|
private |
True if file is an output file being written to disk.
Definition at line 306 of file EventFile.h.
Referenced by EventFile(), importRunHeaders(), isCorrupted(), nextEvent(), setupEvent(), writeRunTree(), and ~EventFile().
|
private |
True if there is only one output file.
Definition at line 309 of file EventFile.h.
Referenced by nextEvent().
|
private |
A parent file containing event data.
Definition at line 321 of file EventFile.h.
Referenced by EventFile(), importRunHeaders(), nextEvent(), setupEvent(), and updateParent().
|
private |
Pre-clone rules.
The series of rules to call before cloning/copying the parent tree.
Definition at line 332 of file EventFile.h.
Referenced by addDrop(), EventFile(), nextEvent(), and updateParent().
|
private |
Vector of drop rules that have been parsed and need to be used to reactivate these branches on the input tree.
The branches were initial deactivated so they don't get cloned to output tree.
Definition at line 341 of file EventFile.h.
Referenced by addDrop(), EventFile(), nextEvent(), and updateParent().
|
private |
True when the run headers we read were written with a completion flag.
Definition at line 350 of file EventFile.h.
Referenced by getIncompleteRuns(), and importRunHeaders().
|
private |
Map of run numbers to RunHeader objects (owned via shared_ptr)
Definition at line 344 of file EventFile.h.
Referenced by getIncompleteRuns(), getRunHeaderPtr(), importRunHeaders(), writeRunHeader(), and writeRunTree().
|
private |
The run tree, owned by file_ once written.
Definition at line 347 of file EventFile.h.
Referenced by writeRunTree().
|
private |
The tree with event data.
Definition at line 318 of file EventFile.h.
Referenced by EventFile(), isCorrupted(), nextEvent(), setupEvent(), updateParent(), and ~EventFile().