CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
fwlite::ChainEvent Class Reference

#include <ChainEvent.h>

Inheritance diagram for fwlite::ChainEvent:
fwlite::EventBase edm::EventBase

Public Member Functions

bool atEnd () const override
 
 ChainEvent (std::vector< std::string > const &iFileNames)
 
Event const * event () const
 
edm::EventAuxiliary const & eventAuxiliary () const override
 
Long64_t eventIndex () const
 
Long64_t fileIndex () const override
 
void fillParameterSetRegistry () const
 
std::vector< edm::BranchDescription > const & getBranchDescriptions () const
 
std::string const getBranchNameFor (std::type_info const &, char const *, char const *, char const *) const override
 
bool getByLabel (std::type_info const &, char const *, char const *, char const *, void *) const override
 
edm::WrapperBase const * getByProductID (edm::ProductID const &) const override
 
fwlite::LuminosityBlock const & getLuminosityBlock ()
 
std::vector< std::string > const & getProcessHistory () const
 
fwlite::Run const & getRun ()
 
TFile * getTFile () const
 
edm::WrapperBase const * getThinnedProduct (edm::ProductID const &pid, unsigned int &key) const
 
void getThinnedProducts (edm::ProductID const &pid, std::vector< edm::WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const
 
bool isValid () const
 
 operator bool () const
 
ChainEvent const & operator++ () override
 
edm::ParameterSet const * parameterSet (edm::ParameterSetID const &psID) const override
 
edm::ProcessHistory const & processHistory () const override
 
void setGetter (std::shared_ptr< edm::EDProductGetter const > getter)
 
Long64_t size () const
 
bool to (Long64_t iIndex)
 Go to the event at index iIndex. More...
 
bool to (const edm::EventID &id)
 Go to event with event id "id". More...
 
bool to (edm::RunNumber_t run, edm::EventNumber_t event)
 
bool to (edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi, edm::EventNumber_t event)
 
ChainEvent const & toBegin () override
 
edm::TriggerNames const & triggerNames (edm::TriggerResults const &triggerResults) const override
 
edm::TriggerResultsByName triggerResultsByName (edm::TriggerResults const &triggerResults) const override
 
 ~ChainEvent () override
 
- Public Member Functions inherited from fwlite::EventBase
 EventBase ()
 
virtual Long64_t secondaryFileIndex () const
 
 ~EventBase () override
 
- Public Member Functions inherited from edm::EventBase
int bunchCrossing () const
 
 EventBase ()
 
edm::EventAuxiliary::ExperimentType experimentType () const
 
template<typename T >
bool get (ProductID const &, Handle< T > &) const
 
template<typename T >
bool getByLabel (InputTag const &, Handle< T > &) const
 
template<>
bool getByLabel (edm::InputTag const &tag, Handle< FWGenericObject > &result) const
 Specialize the getByLabel method to work with a Handle<FWGenericObject> More...
 
edm::EventID id () const
 
bool isRealData () const
 
edm::LuminosityBlockNumber_t luminosityBlock () const
 
int orbitNumber () const
 
edm::Timestamp time () const
 

Static Public Member Functions

static void throwProductNotFoundException (std::type_info const &, char const *, char const *, char const *)
 

Private Member Functions

 ChainEvent (Event const &)
 
void findSizes ()
 
ChainEvent const & operator= (Event const &)
 
void switchToFile (Long64_t)
 

Private Attributes

std::vector< Long64_t > accumulatedSize_
 
edm::propagate_const< std::shared_ptr< Event > > event_
 
Long64_t eventIndex_
 
edm::propagate_const< std::shared_ptr< TFile > > file_
 
std::vector< std::string > fileNames_
 
edm::propagate_const< std::shared_ptr< edm::EDProductGetter > > getter_
 

Friends

class MultiChainEvent
 

Additional Inherited Members

- Static Protected Member Functions inherited from edm::EventBase
static edm::ParameterSet const * parameterSetForID_ (edm::ParameterSetID const &psID)
 
static TriggerNames const * triggerNames_ (edm::TriggerResults const &triggerResults)
 

Detailed Description

Definition at line 46 of file ChainEvent.h.

Constructor & Destructor Documentation

ChainEvent::ChainEvent ( std::vector< std::string > const &  iFileNames)

Definition at line 35 of file ChainEvent.cc.

References accumulatedSize_, edm::poolNames::eventTreeName(), Exception, file_, MillePedeFileConverter_cfg::fileName, fileNames_, nEvents, and switchToFile().

37  Long64_t summedSize = 0;
38  accumulatedSize_.reserve(iFileNames.size() + 1);
39  fileNames_.reserve(iFileNames.size());
40 
41  for (auto const& fileName : iFileNames) {
42  TFile* tfilePtr = TFile::Open(fileName.c_str());
43  file_ = std::shared_ptr<TFile>(tfilePtr);
44  gROOT->GetListOfFiles()->Remove(tfilePtr);
45  TTree* tree = dynamic_cast<TTree*>(file_->Get(edm::poolNames::eventTreeName().c_str()));
46  if (nullptr == tree) {
47  throw cms::Exception("NotEdmFile")
48  << "The file " << fileName << " has no 'Events' TTree and therefore is not an EDM ROOT file";
49  }
50  Long64_t nEvents = tree->GetEntries();
51  if (nEvents > 0) { // skip empty files
52  fileNames_.push_back(fileName);
53  // accumulatedSize_ is the entry # at the beginning of this file
54  accumulatedSize_.push_back(summedSize);
55  summedSize += nEvents;
56  }
57  }
58  // total accumulated size (last enry + 1) at the end of last file
59  accumulatedSize_.push_back(summedSize);
60 
61  if (!fileNames_.empty())
62  switchToFile(0);
63  }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:177
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
std::vector< Long64_t > accumulatedSize_
Definition: ChainEvent.h:135
edm::propagate_const< std::shared_ptr< TFile > > file_
Definition: ChainEvent.h:132
std::string const & eventTreeName()
Definition: BranchType.cc:218
Definition: tree.py:1
UInt_t nEvents
Definition: hcalCalib.cc:41
std::vector< std::string > fileNames_
Definition: ChainEvent.h:131
ChainEvent::~ChainEvent ( )
override

Definition at line 70 of file ChainEvent.cc.

70 {}
fwlite::ChainEvent::ChainEvent ( Event const &  )
private

Member Function Documentation

bool ChainEvent::atEnd ( ) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 234 of file ChainEvent.cc.

References event_, eventIndex_, fileNames_, and size().

Referenced by fwlite::AnalyzerWrapper< T >::analyze(), and main().

234  {
235  if (!size())
236  return true;
237  if (eventIndex_ == static_cast<Long64_t>(fileNames_.size()) - 1) {
238  return event_->atEnd();
239  }
240  return false;
241  }
Long64_t size() const
Definition: ChainEvent.cc:243
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
std::vector< std::string > fileNames_
Definition: ChainEvent.h:131
Event const* fwlite::ChainEvent::event ( ) const
inline
edm::EventAuxiliary const & ChainEvent::eventAuxiliary ( ) const
overridevirtual

Implements edm::EventBase.

Definition at line 203 of file ChainEvent.cc.

References event_.

203 { return event_->eventAuxiliary(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t fwlite::ChainEvent::eventIndex ( ) const
inline

Definition at line 93 of file ChainEvent.h.

93 { return eventIndex_; }
Long64_t eventIndex_
Definition: ChainEvent.h:134
Long64_t fwlite::ChainEvent::fileIndex ( ) const
inlineoverridevirtual

Reimplemented from fwlite::EventBase.

Definition at line 94 of file ChainEvent.h.

Referenced by python.Events::fileIndicies().

94 { return eventIndex_; }
Long64_t eventIndex_
Definition: ChainEvent.h:134
void ChainEvent::fillParameterSetRegistry ( ) const

Definition at line 253 of file ChainEvent.cc.

References event_.

253 { event_->fillParameterSetRegistry(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
void fwlite::ChainEvent::findSizes ( )
private
std::vector< edm::BranchDescription > const & ChainEvent::getBranchDescriptions ( ) const

Definition at line 195 of file ChainEvent.cc.

References event_.

195  {
196  return event_->getBranchDescriptions();
197  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
std::string const ChainEvent::getBranchNameFor ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess 
) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 188 of file ChainEvent.cc.

References event_.

191  {
192  return event_->getBranchNameFor(iType, iModule, iInstance, iProcess);
193  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
bool ChainEvent::getByLabel ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess,
void *  iValue 
) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 209 of file ChainEvent.cc.

References event_.

213  {
214  return event_->getByLabel(iType, iModule, iInstance, iProcess, iValue);
215  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
edm::WrapperBase const * ChainEvent::getByProductID ( edm::ProductID const &  iID) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 217 of file ChainEvent.cc.

References event_.

217  {
218  return event_->getByProductID(iID);
219  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
fwlite::LuminosityBlock const & ChainEvent::getLuminosityBlock ( )

Definition at line 205 of file ChainEvent.cc.

References event_.

205 { return event_->getLuminosityBlock(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
std::vector< std::string > const & ChainEvent::getProcessHistory ( ) const

Definition at line 199 of file ChainEvent.cc.

References event_.

199 { return event_->getProcessHistory(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
fwlite::Run const & ChainEvent::getRun ( )

Definition at line 207 of file ChainEvent.cc.

References event_.

207 { return event_->getRun(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
TFile* fwlite::ChainEvent::getTFile ( ) const
inline

Definition at line 85 of file ChainEvent.h.

References event_().

85 { return event_->getTFile(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
edm::WrapperBase const * ChainEvent::getThinnedProduct ( edm::ProductID const &  pid,
unsigned int &  key 
) const

Definition at line 221 of file ChainEvent.cc.

References event_.

221  {
222  return event_->getThinnedProduct(pid, key);
223  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
void ChainEvent::getThinnedProducts ( edm::ProductID const &  pid,
std::vector< edm::WrapperBase const * > &  foundContainers,
std::vector< unsigned int > &  keys 
) const

Definition at line 225 of file ChainEvent.cc.

References event_.

227  {
228  event_->getThinnedProducts(pid, foundContainers, keys);
229  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
bool ChainEvent::isValid ( void  ) const

Definition at line 231 of file ChainEvent.cc.

References event_.

Referenced by ntupleDataFormat._Object::_checkIsValid(), and core.AutoHandle.AutoHandle::ReallyLoad().

231 { return event_->isValid(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
ChainEvent::operator bool ( ) const

Definition at line 232 of file ChainEvent.cc.

References event_.

232 { return *event_; }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
ChainEvent const & ChainEvent::operator++ ( )
overridevirtual

Implements fwlite::EventBase.

Definition at line 88 of file ChainEvent.cc.

References event_, eventIndex_, fileNames_, and switchToFile().

88  {
89  if (eventIndex_ != static_cast<Long64_t>(fileNames_.size()) - 1) {
90  ++(*event_);
91  if (event_->atEnd()) {
93  }
94  } else {
95  if (*event_) {
96  ++(*event_);
97  }
98  }
99  return *this;
100  }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:177
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
std::vector< std::string > fileNames_
Definition: ChainEvent.h:131
ChainEvent const& fwlite::ChainEvent::operator= ( Event const &  )
private
edm::ParameterSet const * ChainEvent::parameterSet ( edm::ParameterSetID const &  psID) const
overridevirtual

Implements edm::EventBase.

Definition at line 249 of file ChainEvent.cc.

References event_.

249  {
250  return event_->parameterSet(psID);
251  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
edm::ProcessHistory const & ChainEvent::processHistory ( ) const
overridevirtual

Implements edm::EventBase.

Definition at line 201 of file ChainEvent.cc.

References event_.

201 { return event_->processHistory(); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
void fwlite::ChainEvent::setGetter ( std::shared_ptr< edm::EDProductGetter const >  getter)
inline

Definition at line 96 of file ChainEvent.h.

References event_().

96 { event_->setGetter(getter); }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t ChainEvent::size ( void  ) const

Definition at line 243 of file ChainEvent.cc.

References accumulatedSize_.

Referenced by ntupleDataFormat._Collection::__iter__(), ntupleDataFormat._Collection::__len__(), atEnd(), and toBegin().

243 { return accumulatedSize_.empty() ? 0 : accumulatedSize_.back(); }
std::vector< Long64_t > accumulatedSize_
Definition: ChainEvent.h:135
void ChainEvent::switchToFile ( Long64_t  iIndex)
private

Definition at line 177 of file ChainEvent.cc.

References event_, eventIndex_, file_, fileNames_, and edm::propagate_const< T >::get().

Referenced by ChainEvent(), operator++(), to(), and toBegin().

177  {
178  eventIndex_ = iIndex;
179  TFile* tfilePtr = TFile::Open(fileNames_[iIndex].c_str());
180  file_ = std::shared_ptr<TFile>(tfilePtr);
181  gROOT->GetListOfFiles()->Remove(tfilePtr);
182  event_ = std::make_shared<Event>(file_.get());
183  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
element_type const * get() const
edm::propagate_const< std::shared_ptr< TFile > > file_
Definition: ChainEvent.h:132
std::vector< std::string > fileNames_
Definition: ChainEvent.h:131
void ChainEvent::throwProductNotFoundException ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess 
)
static

Definition at line 262 of file ChainEvent.cc.

References fwlite::Event::throwProductNotFoundException().

Referenced by fwlite::MultiChainEvent::throwProductNotFoundException().

265  {
266  Event::throwProductNotFoundException(iType, iModule, iInstance, iProcess);
267  }
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
Definition: Event.cc:471
bool ChainEvent::to ( Long64_t  iIndex)

Go to the event at index iIndex.

Definition at line 103 of file ChainEvent.cc.

References accumulatedSize_, event_, eventIndex_, and switchToFile().

Referenced by to().

103  {
104  if (iIndex >= accumulatedSize_.back()) {
105  // if we're here, then iIndex was not valid
106  return false;
107  }
108 
109  Long64_t offsetIndex = eventIndex_;
110 
111  // we're going backwards, so start from the beginning
112  if (iIndex < accumulatedSize_[offsetIndex]) {
113  offsetIndex = 0;
114  }
115 
116  // is it past the end of this file?
117  while (iIndex >= accumulatedSize_[offsetIndex + 1]) {
118  ++offsetIndex;
119  }
120 
121  if (offsetIndex != eventIndex_) {
122  switchToFile(eventIndex_ = offsetIndex);
123  }
124 
125  // adjust to entry # in this file
126  return event_->to(iIndex - accumulatedSize_[offsetIndex]);
127  }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:177
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
std::vector< Long64_t > accumulatedSize_
Definition: ChainEvent.h:135
bool ChainEvent::to ( const edm::EventID id)

Go to event with event id "id".

Definition at line 130 of file ChainEvent.cc.

References event(), edm::EventBase::luminosityBlock(), writedatasetfile::run, and to().

130 { return to(id.run(), id.luminosityBlock(), id.event()); }
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: ChainEvent.cc:103
Event const * event() const
Definition: ChainEvent.h:98
bool ChainEvent::to ( edm::RunNumber_t  run,
edm::EventNumber_t  event 
)

Definition at line 163 of file ChainEvent.cc.

References to(), and mitigatedMETSequence_cff::U.

163 { return to(run, 0U, event); }
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: ChainEvent.cc:103
Definition: event.py:1
bool ChainEvent::to ( edm::RunNumber_t  run,
edm::LuminosityBlockNumber_t  lumi,
edm::EventNumber_t  event 
)

If lumi is non-zero, go to event with given run, lumi, and event number If lumi is zero, go to event with given run and event number

Definition at line 134 of file ChainEvent.cc.

References event_, eventIndex_, fileNames_, compare_using_db::ifile, and switchToFile().

134  {
135  // First try this file
136  if (event_->to(run, lumi, event)) {
137  // found it, return
138  return true;
139  } else {
140  // Did not find it, try the other files sequentially.
141  // Someday I can make this smarter. For now... we get something working.
142  Long64_t thisFile = eventIndex_;
143  std::vector<std::string>::const_iterator filesBegin = fileNames_.begin(), filesEnd = fileNames_.end(),
144  ifile = filesBegin;
145  for (; ifile != filesEnd; ++ifile) {
146  // skip the "first" file that we tried
147  if (ifile - filesBegin != thisFile) {
148  // switch to the next file
149  switchToFile(ifile - filesBegin);
150  // check that tree for the desired event
151  if (event_->to(run, lumi, event)) {
152  // found it, return
153  return true;
154  }
155  } // end ignore "first" file that we tried
156  } // end loop over files
157 
158  // did not find the event with id "id".
159  return false;
160  } // end if we did not find event id in "first" file
161  }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:177
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
std::vector< std::string > fileNames_
Definition: ChainEvent.h:131
Definition: event.py:1
ChainEvent const & ChainEvent::toBegin ( )
overridevirtual

Go to the very first Event

Implements fwlite::EventBase.

Definition at line 167 of file ChainEvent.cc.

References event_, eventIndex_, size(), and switchToFile().

Referenced by fwlite::AnalyzerWrapper< T >::analyze(), and main().

167  {
168  if (!size())
169  return *this;
170  if (eventIndex_ != 0) {
171  switchToFile(0);
172  }
173  event_->toBegin();
174  return *this;
175  }
Long64_t size() const
Definition: ChainEvent.cc:243
void switchToFile(Long64_t)
Definition: ChainEvent.cc:177
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
Long64_t eventIndex_
Definition: ChainEvent.h:134
edm::TriggerNames const & ChainEvent::triggerNames ( edm::TriggerResults const &  triggerResults) const
overridevirtual

Implements edm::EventBase.

Definition at line 245 of file ChainEvent.cc.

References event_.

245  {
246  return event_->triggerNames(triggerResults);
247  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
static std::string const triggerResults
Definition: EdmProvDump.cc:45
edm::TriggerResultsByName ChainEvent::triggerResultsByName ( edm::TriggerResults const &  triggerResults) const
overridevirtual

Implements edm::EventBase.

Definition at line 255 of file ChainEvent.cc.

References event_.

255  {
256  return event_->triggerResultsByName(triggerResults);
257  }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:133
static std::string const triggerResults
Definition: EdmProvDump.cc:45

Friends And Related Function Documentation

friend class MultiChainEvent
friend

Definition at line 122 of file ChainEvent.h.

Member Data Documentation

std::vector<Long64_t> fwlite::ChainEvent::accumulatedSize_
private

Definition at line 135 of file ChainEvent.h.

Referenced by ChainEvent(), size(), and to().

edm::propagate_const<std::shared_ptr<Event> > fwlite::ChainEvent::event_
private
Long64_t fwlite::ChainEvent::eventIndex_
private

Definition at line 134 of file ChainEvent.h.

Referenced by atEnd(), operator++(), switchToFile(), to(), and toBegin().

edm::propagate_const<std::shared_ptr<TFile> > fwlite::ChainEvent::file_
private

Definition at line 132 of file ChainEvent.h.

Referenced by ChainEvent(), and switchToFile().

std::vector<std::string> fwlite::ChainEvent::fileNames_
private

Definition at line 131 of file ChainEvent.h.

Referenced by atEnd(), ChainEvent(), operator++(), switchToFile(), and to().

edm::propagate_const<std::shared_ptr<edm::EDProductGetter> > fwlite::ChainEvent::getter_
private

Definition at line 136 of file ChainEvent.h.