#include <MultiChainEvent.h>
Public Types | |
typedef std::pair < edm::EventID, edm::EventID > | event_id_range |
typedef std::map< edm::EventID, Long64_t > | sec_file_index_map |
typedef std::map < event_id_range, Long64_t > | sec_file_range_index_map |
Public Member Functions | |
bool | atEnd () const |
virtual edm::EventAuxiliary const & | eventAuxiliary () const |
Long64_t | eventIndex () const |
Long64_t | eventIndexSec () const |
virtual Long64_t | fileIndex () const |
std::vector < edm::BranchDescription > const & | getBranchDescriptions () const |
virtual std::string const | getBranchNameFor (std::type_info const &, char const *, char const *, char const *) const |
virtual bool | getByLabel (std::type_info const &, char const *, char const *, char const *, void *) const |
virtual bool | getByLabel (std::type_info const &, char const *, char const *, char const *, edm::WrapperHolder &) const |
edm::WrapperHolder | getByProductID (edm::ProductID const &) const |
fwlite::LuminosityBlock const & | getLuminosityBlock () |
std::vector< std::string > const & | getProcessHistory () const |
fwlite::Run const & | getRun () |
TFile * | getTFile () const |
TFile * | getTFileSec () const |
bool | isValid () const |
MultiChainEvent (std::vector< std::string > const &iFileNames1, std::vector< std::string > const &iFileNames2, bool useSecFileMapSorted=false) | |
operator bool () const | |
const MultiChainEvent & | operator++ () |
ChainEvent const * | primary () const |
edm::ProcessHistory const & | processHistory () const |
ChainEvent const * | secondary () const |
virtual Long64_t | secondaryFileIndex () const |
Long64_t | size () const |
bool | to (edm::EventID id) |
Go to event with event id "id". | |
bool | to (Long64_t iIndex) |
Go to the event at index iIndex. | |
bool | to (edm::RunNumber_t run, edm::EventNumber_t event) |
Go to event with given run and event number. | |
bool | to (edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event) |
Go to event with given run , lumi (if non-zero), and event number. | |
const MultiChainEvent & | toBegin () |
virtual edm::TriggerNames const & | triggerNames (edm::TriggerResults const &triggerResults) const |
virtual edm::TriggerResultsByName | triggerResultsByName (std::string const &process) const |
virtual | ~MultiChainEvent () |
Static Public Member Functions | |
static void | throwProductNotFoundException (std::type_info const &, char const *, char const *, char const *) |
Private Member Functions | |
MultiChainEvent (Event const &) | |
const MultiChainEvent & | operator= (Event const &) |
bool | toSec (edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event) |
Go to event with given run, lumi, and event number. | |
bool | toSec (const edm::EventID &id) |
bool | toSec (Long64_t iIndex) |
Go to the event from secondary files at index iIndex. | |
bool | toSec (edm::RunNumber_t run, edm::EventNumber_t event) |
Go to event with given run and event number. | |
Private Attributes | |
boost::shared_ptr< ChainEvent > | event1_ |
boost::shared_ptr< ChainEvent > | event2_ |
boost::shared_ptr < internal::MultiProductGetter > | getter_ |
sec_file_range_index_map | secFileMapSorted_ |
bool | useSecFileMapSorted_ |
Definition at line 50 of file MultiChainEvent.h.
typedef std::pair<edm::EventID, edm::EventID> fwlite::MultiChainEvent::event_id_range |
Definition at line 56 of file MultiChainEvent.h.
typedef std::map<edm::EventID, Long64_t> fwlite::MultiChainEvent::sec_file_index_map |
Definition at line 55 of file MultiChainEvent.h.
typedef std::map<event_id_range, Long64_t> fwlite::MultiChainEvent::sec_file_range_index_map |
Definition at line 57 of file MultiChainEvent.h.
MultiChainEvent::MultiChainEvent | ( | std::vector< std::string > const & | iFileNames1, |
std::vector< std::string > const & | iFileNames2, | ||
bool | useSecFileMapSorted = false |
||
) |
Definition at line 53 of file MultiChainEvent.cc.
References gather_cfg::cout, event1_, event2_, getter_, secFileMapSorted_, makeLayoutFileForGui::toAdd, and useSecFileMapSorted_.
{ event1_ = boost::shared_ptr<ChainEvent> (new ChainEvent(iFileNames1)); event2_ = boost::shared_ptr<ChainEvent> (new ChainEvent(iFileNames2)); getter_ = boost::shared_ptr<internal::MultiProductGetter>(new internal::MultiProductGetter(this)); event1_->setGetter(getter_); event2_->setGetter(getter_); useSecFileMapSorted_ = useSecFileMapSorted; if (!useSecFileMapSorted_) { std::cout << "------------------------------------------------------------------------" << std::endl; std::cout << "WARNING! What you are about to do may be very slow." << std::endl; std::cout << "The 2-file solution in FWLite works with very simple assumptions." << std::endl; std::cout << "It will linearly search through the files in the secondary file list for Products." << std::endl; std::cout << "There are speed improvements available to make this run faster." << std::endl; std::cout << "***If your secondary files are sorted with a run-range within a file, (almost always the case) " << std::endl; std::cout << "***please use the option useSecFileMapSorted=true in this constructor. " << std::endl; std::cout << " > usage: MultiChainEvent(primaryFiles, secondaryFiles, true);" << std::endl; std::cout << "------------------------------------------------------------------------" << std::endl; } if (useSecFileMapSorted_) { std::cout << "------------------------------------------------------------------------" << std::endl; std::cout << "This MultiChainEvent is now creating a (run_range)_2 ---> file_index_2 map" << std::endl; std::cout << "for the 2-file solution. " << std::endl; std::cout << "This is assuming the files you are giving me are sorted by run,event pairs within each secondary file." << std::endl; std::cout << "If this is not true (rarely the case), set this option to false." << std::endl; std::cout << " > usage: MultiChainEvent(primaryFiles, secondaryFiles, false);" << std::endl; std::cout << "------------------------------------------------------------------------" << std::endl; // speed up secondary file access with a (run,event)_1 ---> index_2 map // Loop over events, when a new file is encountered, store the first run number from this file, // and the last run number from the last file. TFile * lastFile = 0; std::pair<event_id_range,Long64_t> eventRange; bool firstFile = true; bool foundAny = false; for(event2_->toBegin(); ! event2_->atEnd(); ++(*event2_)) { // if we have a new file, cache the "first" if (lastFile != event2_->getTFile()) { // if this is not the first file, we have an entry. // Add it to the list. if (!firstFile) { foundAny = true; event_id_range toAdd = eventRange.first; secFileMapSorted_[ toAdd ] = eventRange.second; } // always add the "first" event id to the cached event range eventRange.first.first = event2_->event()->id(); lastFile = event2_->getTFile(); } // otherwise, cache the "second" event id in the cached event range. // Upon the discovery of a new file, this will be used as the // "last" event id in the cached event range. else { eventRange.first.second = event2_->event()->id(); eventRange.second = event2_->eventIndex(); } firstFile = false; } // due to the invailability of a "look ahead" operation, we have one additional "put" to make // after the loop (which puts the "last" event, not "this" event. if (foundAny) { event_id_range toAdd = eventRange.first; secFileMapSorted_[ toAdd ] = eventRange.second; } // std::cout << "Dumping run range to event id list:" << std::endl; // for (sec_file_range_index_map::const_iterator mBegin = secFileMapSorted_.begin(), // mEnd = secFileMapSorted_.end(), // mit = mBegin; // mit != mEnd; ++mit) { // char buff[1000]; // event2_->to(mit->second); // sprintf(buff, "[%10d,%10d - %10d,%10d] ---> %10d", // mit->first.first.run(), // mit->first.first.event(), // mit->first.second.run(), // mit->first.second.event(), // mit->second); // std::cout << buff << std::endl; // } } }
MultiChainEvent::~MultiChainEvent | ( | ) | [virtual] |
Definition at line 156 of file MultiChainEvent.cc.
{ }
fwlite::MultiChainEvent::MultiChainEvent | ( | Event const & | ) | [private] |
bool MultiChainEvent::atEnd | ( | ) | const [virtual] |
Implements fwlite::EventBase.
Definition at line 400 of file MultiChainEvent.cc.
References event1_.
{ return event1_->atEnd(); }
edm::EventAuxiliary const & MultiChainEvent::eventAuxiliary | ( | ) | const [virtual] |
Implements edm::EventBase.
Definition at line 335 of file MultiChainEvent.cc.
References event1_.
{ return event1_->eventAuxiliary(); }
Long64_t fwlite::MultiChainEvent::eventIndex | ( | ) | const [inline] |
Definition at line 107 of file MultiChainEvent.h.
References event1_.
{ return event1_->eventIndex(); }
Long64_t fwlite::MultiChainEvent::eventIndexSec | ( | ) | const [inline] |
Definition at line 108 of file MultiChainEvent.h.
References event2_.
{ return event2_->eventIndex(); }
virtual Long64_t fwlite::MultiChainEvent::fileIndex | ( | ) | const [inline, virtual] |
Reimplemented from fwlite::EventBase.
Definition at line 119 of file MultiChainEvent.h.
References event1_.
{ return event1_->eventIndex(); }
std::vector< edm::BranchDescription > const & MultiChainEvent::getBranchDescriptions | ( | ) | const |
Definition at line 317 of file MultiChainEvent.cc.
References event1_.
{ return event1_->getBranchDescriptions(); }
std::string const MultiChainEvent::getBranchNameFor | ( | std::type_info const & | iType, |
char const * | iModule, | ||
char const * | iInstance, | ||
char const * | iProcess | ||
) | const [virtual] |
Implements fwlite::EventBase.
Definition at line 308 of file MultiChainEvent.cc.
References event1_.
{ return event1_->getBranchNameFor(iType,iModule,iInstance,iProcess); }
bool MultiChainEvent::getByLabel | ( | std::type_info const & | iType, |
char const * | iModule, | ||
char const * | iInstance, | ||
char const * | iProcess, | ||
edm::WrapperHolder & | holder | ||
) | const [virtual] |
Implements fwlite::EventBase.
Definition at line 358 of file MultiChainEvent.cc.
References event1_, and event2_.
{ bool ret1 = event1_->getByLabel(iType, iModule, iInstance, iProcess, holder); if(!ret1) { (const_cast<MultiChainEvent*>(this))->toSec(event1_->id()); bool ret2 = event2_->getByLabel(iType, iModule, iInstance, iProcess, holder); if(!ret2) return false; } return true; }
bool MultiChainEvent::getByLabel | ( | std::type_info const & | iType, |
char const * | iModule, | ||
char const * | iInstance, | ||
char const * | iProcess, | ||
void * | iValue | ||
) | const [virtual] |
This function should only be called by fwlite::Handle<>
Implements fwlite::EventBase.
Definition at line 341 of file MultiChainEvent.cc.
References event1_, and event2_.
{ bool ret1 = event1_->getByLabel(iType, iModule, iInstance, iProcess, iValue); if (!ret1) { (const_cast<MultiChainEvent*>(this))->toSec(event1_->id()); bool ret2 = event2_->getByLabel(iType,iModule,iInstance,iProcess,iValue); if (!ret2) return false; } return true; }
edm::WrapperHolder MultiChainEvent::getByProductID | ( | edm::ProductID const & | iID | ) | const |
Definition at line 373 of file MultiChainEvent.cc.
References event1_, event2_, Exception, and edm::WrapperHolder::isValid().
Referenced by fwlite::internal::MultiProductGetter::getIt().
{ // First try the first file edm::WrapperHolder edp = event1_->getByProductID(iID); // Did not find the product, try secondary file if (!edp.isValid()) { (const_cast<MultiChainEvent*>(this))->toSec(event1_->id()); edp = event2_->getByProductID(iID); if (!edp.isValid()) { throw cms::Exception("ProductNotFound") << "Cannot find product " << iID; } } return edp; }
fwlite::LuminosityBlock const& fwlite::MultiChainEvent::getLuminosityBlock | ( | ) | [inline] |
Definition at line 110 of file MultiChainEvent.h.
References event1_.
{ return event1_->getLuminosityBlock(); }
std::vector< std::string > const & MultiChainEvent::getProcessHistory | ( | ) | const |
Definition at line 323 of file MultiChainEvent.cc.
References event1_.
{ return event1_->getProcessHistory(); }
fwlite::Run const& fwlite::MultiChainEvent::getRun | ( | ) | [inline] |
TFile* fwlite::MultiChainEvent::getTFile | ( | ) | const [inline] |
Definition at line 100 of file MultiChainEvent.h.
References event1_.
{ return event1_->getTFile(); }
TFile* fwlite::MultiChainEvent::getTFileSec | ( | ) | const [inline] |
Definition at line 103 of file MultiChainEvent.h.
References event2_.
{ return event2_->getTFile(); }
bool MultiChainEvent::isValid | ( | void | ) | const |
Definition at line 390 of file MultiChainEvent.cc.
References event1_.
{ return event1_->isValid(); }
MultiChainEvent::operator bool | ( | ) | const |
const MultiChainEvent & MultiChainEvent::operator++ | ( | ) | [virtual] |
Implements fwlite::EventBase.
Definition at line 177 of file MultiChainEvent.cc.
References event1_.
{ event1_->operator++(); return *this; }
const MultiChainEvent& fwlite::MultiChainEvent::operator= | ( | Event const & | ) | [private] |
ChainEvent const* fwlite::MultiChainEvent::primary | ( | ) | const [inline] |
edm::ProcessHistory const & MultiChainEvent::processHistory | ( | ) | const [virtual] |
Implements edm::EventBase.
Definition at line 329 of file MultiChainEvent.cc.
References event1_.
{ return event1_->processHistory(); }
ChainEvent const* fwlite::MultiChainEvent::secondary | ( | ) | const [inline] |
virtual Long64_t fwlite::MultiChainEvent::secondaryFileIndex | ( | ) | const [inline, virtual] |
Reimplemented from fwlite::EventBase.
Definition at line 121 of file MultiChainEvent.h.
References event2_.
{ return event2_->eventIndex(); }
Long64_t MultiChainEvent::size | ( | void | ) | const |
void MultiChainEvent::throwProductNotFoundException | ( | std::type_info const & | iType, |
char const * | iModule, | ||
char const * | iInstance, | ||
char const * | iProcess | ||
) | [static] |
Definition at line 462 of file MultiChainEvent.cc.
{ ChainEvent::throwProductNotFoundException(iType,iModule,iInstance,iProcess); }
bool MultiChainEvent::to | ( | edm::RunNumber_t | run, |
edm::EventNumber_t | event | ||
) |
bool MultiChainEvent::to | ( | Long64_t | iIndex | ) |
Go to the event at index iIndex.
Definition at line 185 of file MultiChainEvent.cc.
References event1_.
Referenced by to().
{ return event1_->to(iIndex); }
bool MultiChainEvent::to | ( | edm::RunNumber_t | run, |
edm::LuminosityBlockNumber_t | lumi, | ||
edm::EventNumber_t | event | ||
) |
bool MultiChainEvent::to | ( | edm::EventID | id | ) |
Go to event with event id "id".
Definition at line 193 of file MultiChainEvent.cc.
References event(), edm::EventBase::luminosityBlock(), DTTTrigCorrFirst::run, and to().
{ return to(id.run(), id.luminosityBlock(), id.event()); }
const MultiChainEvent & MultiChainEvent::toBegin | ( | ) | [virtual] |
Implements fwlite::EventBase.
Definition at line 298 of file MultiChainEvent.cc.
References event1_.
{ event1_->toBegin(); return *this; }
bool MultiChainEvent::toSec | ( | edm::RunNumber_t | run, |
edm::EventNumber_t | event | ||
) | [private] |
Go to event with given run and event number.
Definition at line 291 of file MultiChainEvent.cc.
References toSec().
{ return toSec(edm::EventID(run, 0U, event)); }
bool MultiChainEvent::toSec | ( | Long64_t | iIndex | ) | [private] |
Go to the event from secondary files at index iIndex.
Go to the event at index iIndex.
Definition at line 215 of file MultiChainEvent.cc.
References event2_.
Referenced by toSec().
{ return event2_->to(iIndex); }
bool MultiChainEvent::toSec | ( | const edm::EventID & | id | ) | [private] |
Definition at line 222 of file MultiChainEvent.cc.
References event2_, Exception, first, and secFileMapSorted_.
{ // First try this file. if (event2_->event_->to(id)) { // Found it, return. return true; } // Second, assume that the secondary files are each in run/event // order. So, let's loop over all files and see if we can figure // out where the event ought to be. for (sec_file_range_index_map::const_iterator mBegin = secFileMapSorted_.begin(), mEnd = secFileMapSorted_.end(), mit = mBegin; mit != mEnd; ++mit) { if (id < mit->first.first || id > mit->first.second) { // We don't expect this event to be in this file, so don't // bother checking it right now. continue; } // If we're here, then we have a reasonable belief that this // event is in this secondary file. This part is // expensive. switchToFile does memory allocations and opens the // files which becomes very time consuming. This should be done // as infrequently as possible. event2_->switchToFile(mit->second); // Is it here? if (event2_->to(id)) { // Yes! return true; } // if we assumed that the secondary files were not each in // order, but were non-overlapping, we could break here. But at // this point, we might as well keep going. } // for loop over files // if we are still here, then we did not find the id in question, // do it the old fashioned way. This will open up each secondary // file and explicitly check to see if the event is there. if (event2_->to(id)) { return true; } // if we're still here, then there really is no matching event in // the secondary files. Throw. throw cms::Exception("ProductNotFound") << "Cannot find id " << id.run() << ", " << id.event() << " in secondary list. Exiting." << std::endl; // to make the compiler happy return false; }
bool MultiChainEvent::toSec | ( | edm::RunNumber_t | run, |
edm::LuminosityBlockNumber_t | lumi, | ||
edm::EventNumber_t | event | ||
) | [private] |
Go to event with given run, lumi, and event number.
Definition at line 283 of file MultiChainEvent.cc.
References toSec().
{ return toSec(edm::EventID(run, lumi, event)); }
edm::TriggerNames const & MultiChainEvent::triggerNames | ( | edm::TriggerResults const & | triggerResults | ) | const [virtual] |
Implements edm::EventBase.
Definition at line 412 of file MultiChainEvent.cc.
References event1_, event2_, Exception, h::names, and edm::EventBase::triggerNames_().
{ edm::TriggerNames const* names = triggerNames_(triggerResults); if (names != 0) return *names; event1_->fillParameterSetRegistry(); names = triggerNames_(triggerResults); if (names != 0) return *names; // If we cannot find it in the primary file, this probably will // not help but try anyway event2_->to(event1_->id()); event2_->fillParameterSetRegistry(); names = triggerNames_(triggerResults); if (names != 0) return *names; throw cms::Exception("TriggerNamesNotFound") << "TriggerNames not found in ParameterSet registry"; return *names; }
edm::TriggerResultsByName MultiChainEvent::triggerResultsByName | ( | std::string const & | process | ) | const [virtual] |
Implements edm::EventBase.
Definition at line 434 of file MultiChainEvent.cc.
References event1_, event2_, fwlite::Handle< T >::getByLabel(), fwlite::Handle< T >::isValid(), h::names, fwlite::Handle< T >::product(), and edm::EventBase::triggerNames_().
{ fwlite::Handle<edm::TriggerResults> hTriggerResults; hTriggerResults.getByLabel(*this,"TriggerResults","",process.c_str()); if (!hTriggerResults.isValid()) { return edm::TriggerResultsByName(0,0); } edm::TriggerNames const* names = triggerNames_(*hTriggerResults); if (names == 0) { event1_->fillParameterSetRegistry(); names = triggerNames_(*hTriggerResults); } if (names == 0) { event2_->to(event1_->id()); event2_->fillParameterSetRegistry(); names = triggerNames_(*hTriggerResults); } return edm::TriggerResultsByName(hTriggerResults.product(), names); }
boost::shared_ptr<ChainEvent> fwlite::MultiChainEvent::event1_ [private] |
Definition at line 156 of file MultiChainEvent.h.
Referenced by atEnd(), eventAuxiliary(), eventIndex(), fileIndex(), getBranchDescriptions(), getBranchNameFor(), getByLabel(), getByProductID(), getLuminosityBlock(), getProcessHistory(), getRun(), getTFile(), isValid(), MultiChainEvent(), operator bool(), operator++(), primary(), processHistory(), size(), to(), toBegin(), triggerNames(), and triggerResultsByName().
boost::shared_ptr<ChainEvent> fwlite::MultiChainEvent::event2_ [private] |
Definition at line 157 of file MultiChainEvent.h.
Referenced by eventIndexSec(), getByLabel(), getByProductID(), getTFileSec(), MultiChainEvent(), secondary(), secondaryFileIndex(), toSec(), triggerNames(), and triggerResultsByName().
boost::shared_ptr<internal::MultiProductGetter> fwlite::MultiChainEvent::getter_ [private] |
Definition at line 158 of file MultiChainEvent.h.
Referenced by MultiChainEvent().
Definition at line 165 of file MultiChainEvent.h.
Referenced by MultiChainEvent(), and toSec().
bool fwlite::MultiChainEvent::useSecFileMapSorted_ [private] |
Definition at line 164 of file MultiChainEvent.h.
Referenced by MultiChainEvent().