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
 
const std::string 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::OptionalThinnedKey getThinnedKeyFrom (edm::ProductID const &parent, unsigned int key, edm::ProductID const &thinned) const
 
std::optional< std::tuple< edm::WrapperBase const *, unsigned int > > 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 (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)
 
bool to (Long64_t iIndex)
 Go to the event at index iIndex. More...
 
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<>
bool getByLabel (edm::InputTag const &tag, Handle< FWGenericObject > &result) const
 Specialize the getByLabel method to work with a Handle<FWGenericObject> More...
 
template<typename T >
bool getByLabel (InputTag const &, Handle< T > &) const
 
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() [1/2]

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

Definition at line 35 of file ChainEvent.cc.

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  if (nullptr == tfilePtr) {
44  throw cms::Exception("FileOpenFailed") << "TFile::Open of " << fileName << " failed";
45  }
46  file_ = std::shared_ptr<TFile>(tfilePtr);
47  gROOT->GetListOfFiles()->Remove(tfilePtr);
48  TTree* tree = dynamic_cast<TTree*>(file_->Get(edm::poolNames::eventTreeName().c_str()));
49  if (nullptr == tree) {
50  throw cms::Exception("NotEdmFile")
51  << "The file " << fileName << " has no 'Events' TTree and therefore is not an EDM ROOT file";
52  }
53  Long64_t nEvents = tree->GetEntries();
54  if (nEvents > 0) { // skip empty files
55  fileNames_.push_back(fileName);
56  // accumulatedSize_ is the entry # at the beginning of this file
57  accumulatedSize_.push_back(summedSize);
58  summedSize += nEvents;
59  }
60  }
61  // total accumulated size (last enry + 1) at the end of last file
62  accumulatedSize_.push_back(summedSize);
63 
64  if (!fileNames_.empty())
65  switchToFile(0);
66  }

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

◆ ~ChainEvent()

ChainEvent::~ChainEvent ( )
override

Definition at line 73 of file ChainEvent.cc.

73 {}

◆ ChainEvent() [2/2]

fwlite::ChainEvent::ChainEvent ( Event const &  )
private

Member Function Documentation

◆ atEnd()

bool ChainEvent::atEnd ( ) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 244 of file ChainEvent.cc.

244  {
245  if (!size())
246  return true;
247  if (eventIndex_ == static_cast<Long64_t>(fileNames_.size()) - 1) {
248  return event_->atEnd();
249  }
250  return false;
251  }

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

◆ event()

Event const* fwlite::ChainEvent::event ( ) const
inline

Definition at line 98 of file ChainEvent.h.

98 { return &*event_; }

References event_.

Referenced by Types.EventID::cppID(), and to().

◆ eventAuxiliary()

edm::EventAuxiliary const & ChainEvent::eventAuxiliary ( ) const
overridevirtual

Implements edm::EventBase.

Definition at line 206 of file ChainEvent.cc.

206 { return event_->eventAuxiliary(); }

References event_.

◆ eventIndex()

Long64_t fwlite::ChainEvent::eventIndex ( ) const
inline

Definition at line 93 of file ChainEvent.h.

93 { return eventIndex_; }

References eventIndex_.

◆ fileIndex()

Long64_t fwlite::ChainEvent::fileIndex ( ) const
inlineoverridevirtual

Reimplemented from fwlite::EventBase.

Definition at line 94 of file ChainEvent.h.

94 { return eventIndex_; }

References eventIndex_.

Referenced by python.Events::fileIndicies().

◆ fillParameterSetRegistry()

void ChainEvent::fillParameterSetRegistry ( ) const

Definition at line 263 of file ChainEvent.cc.

263 { event_->fillParameterSetRegistry(); }

References event_.

◆ findSizes()

void fwlite::ChainEvent::findSizes ( )
private

◆ getBranchDescriptions()

std::vector< edm::BranchDescription > const & ChainEvent::getBranchDescriptions ( ) const

Definition at line 198 of file ChainEvent.cc.

198  {
199  return event_->getBranchDescriptions();
200  }

References event_.

◆ getBranchNameFor()

const std::string ChainEvent::getBranchNameFor ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess 
) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 191 of file ChainEvent.cc.

194  {
195  return event_->getBranchNameFor(iType, iModule, iInstance, iProcess);
196  }

References event_.

◆ getByLabel()

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 212 of file ChainEvent.cc.

216  {
217  return event_->getByLabel(iType, iModule, iInstance, iProcess, iValue);
218  }

References event_.

◆ getByProductID()

edm::WrapperBase const * ChainEvent::getByProductID ( edm::ProductID const &  iID) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 220 of file ChainEvent.cc.

220  {
221  return event_->getByProductID(iID);
222  }

References event_.

◆ getLuminosityBlock()

fwlite::LuminosityBlock const & ChainEvent::getLuminosityBlock ( )

Definition at line 208 of file ChainEvent.cc.

208 { return event_->getLuminosityBlock(); }

References event_.

◆ getProcessHistory()

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

Definition at line 202 of file ChainEvent.cc.

202 { return event_->getProcessHistory(); }

References event_.

◆ getRun()

fwlite::Run const & ChainEvent::getRun ( )

Definition at line 210 of file ChainEvent.cc.

210 { return event_->getRun(); }

References event_.

◆ getTFile()

TFile* fwlite::ChainEvent::getTFile ( ) const
inline

Definition at line 85 of file ChainEvent.h.

85 { return event_->getTFile(); }

References event_.

◆ getThinnedKeyFrom()

edm::OptionalThinnedKey ChainEvent::getThinnedKeyFrom ( edm::ProductID const &  parent,
unsigned int  key,
edm::ProductID const &  thinned 
) const

Definition at line 235 of file ChainEvent.cc.

237  {
238  return event_->getThinnedKeyFrom(parent, key, thinned);
239  }

References event_, crabWrapper::key, and class-composition::parent.

◆ getThinnedProduct()

std::optional< std::tuple< edm::WrapperBase const *, unsigned int > > ChainEvent::getThinnedProduct ( edm::ProductID const &  pid,
unsigned int  key 
) const

Definition at line 224 of file ChainEvent.cc.

225  {
226  return event_->getThinnedProduct(pid, key);
227  }

References event_, and crabWrapper::key.

◆ getThinnedProducts()

void ChainEvent::getThinnedProducts ( edm::ProductID const &  pid,
std::vector< edm::WrapperBase const * > &  foundContainers,
std::vector< unsigned int > &  keys 
) const

Definition at line 229 of file ChainEvent.cc.

231  {
232  event_->getThinnedProducts(pid, foundContainers, keys);
233  }

References event_, and relativeConstraints::keys.

◆ isValid()

bool ChainEvent::isValid ( void  ) const

Definition at line 241 of file ChainEvent.cc.

241 { return event_->isValid(); }

References event_.

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

◆ operator bool()

ChainEvent::operator bool ( ) const

Definition at line 242 of file ChainEvent.cc.

242 { return *event_; }

References event_().

◆ operator++()

ChainEvent const & ChainEvent::operator++ ( )
overridevirtual

Implements fwlite::EventBase.

Definition at line 91 of file ChainEvent.cc.

91  {
92  if (eventIndex_ != static_cast<Long64_t>(fileNames_.size()) - 1) {
93  ++(*event_);
94  if (event_->atEnd()) {
96  }
97  } else {
98  if (*event_) {
99  ++(*event_);
100  }
101  }
102  return *this;
103  }

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

◆ operator=()

ChainEvent const& fwlite::ChainEvent::operator= ( Event const &  )
private

◆ parameterSet()

edm::ParameterSet const * ChainEvent::parameterSet ( edm::ParameterSetID const &  psID) const
overridevirtual

Implements edm::EventBase.

Definition at line 259 of file ChainEvent.cc.

259  {
260  return event_->parameterSet(psID);
261  }

References event_.

◆ processHistory()

edm::ProcessHistory const & ChainEvent::processHistory ( ) const
overridevirtual

Implements edm::EventBase.

Definition at line 204 of file ChainEvent.cc.

204 { return event_->processHistory(); }

References event_.

◆ setGetter()

void fwlite::ChainEvent::setGetter ( std::shared_ptr< edm::EDProductGetter const >  getter)
inline

Definition at line 96 of file ChainEvent.h.

96 { event_->setGetter(getter); }

References event_.

◆ size()

Long64_t ChainEvent::size ( void  ) const

Definition at line 253 of file ChainEvent.cc.

253 { return accumulatedSize_.empty() ? 0 : accumulatedSize_.back(); }

References accumulatedSize_.

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

◆ switchToFile()

void ChainEvent::switchToFile ( Long64_t  iIndex)
private

Definition at line 180 of file ChainEvent.cc.

180  {
181  eventIndex_ = iIndex;
182  TFile* tfilePtr = TFile::Open(fileNames_[iIndex].c_str());
183  file_ = std::shared_ptr<TFile>(tfilePtr);
184  gROOT->GetListOfFiles()->Remove(tfilePtr);
185  event_ = std::make_shared<Event>(file_.get());
186  }

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

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

◆ throwProductNotFoundException()

void ChainEvent::throwProductNotFoundException ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess 
)
static

Definition at line 272 of file ChainEvent.cc.

275  {
276  Event::throwProductNotFoundException(iType, iModule, iInstance, iProcess);
277  }

References fwlite::Event::throwProductNotFoundException().

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

◆ to() [1/4]

bool ChainEvent::to ( const edm::EventID id)

Go to event with event id "id".

Definition at line 133 of file ChainEvent.cc.

133 { return to(id.run(), id.luminosityBlock(), id.event()); }

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

◆ to() [2/4]

bool ChainEvent::to ( edm::RunNumber_t  run,
edm::EventNumber_t  event 
)

Definition at line 166 of file ChainEvent.cc.

166 { return to(run, 0U, event); }

References writedatasetfile::run, to(), and mitigatedMETSequence_cff::U.

◆ to() [3/4]

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 137 of file ChainEvent.cc.

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

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

◆ to() [4/4]

bool ChainEvent::to ( Long64_t  iIndex)

Go to the event at index iIndex.

Definition at line 106 of file ChainEvent.cc.

106  {
107  if (iIndex >= accumulatedSize_.back()) {
108  // if we're here, then iIndex was not valid
109  return false;
110  }
111 
112  Long64_t offsetIndex = eventIndex_;
113 
114  // we're going backwards, so start from the beginning
115  if (iIndex < accumulatedSize_[offsetIndex]) {
116  offsetIndex = 0;
117  }
118 
119  // is it past the end of this file?
120  while (iIndex >= accumulatedSize_[offsetIndex + 1]) {
121  ++offsetIndex;
122  }
123 
124  if (offsetIndex != eventIndex_) {
125  switchToFile(eventIndex_ = offsetIndex);
126  }
127 
128  // adjust to entry # in this file
129  return event_->to(iIndex - accumulatedSize_[offsetIndex]);
130  }

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

Referenced by to().

◆ toBegin()

ChainEvent const & ChainEvent::toBegin ( )
overridevirtual

Go to the very first Event

Implements fwlite::EventBase.

Definition at line 170 of file ChainEvent.cc.

170  {
171  if (!size())
172  return *this;
173  if (eventIndex_ != 0) {
174  switchToFile(0);
175  }
176  event_->toBegin();
177  return *this;
178  }

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

◆ triggerNames()

edm::TriggerNames const & ChainEvent::triggerNames ( edm::TriggerResults const &  triggerResults) const
overridevirtual

Implements edm::EventBase.

Definition at line 255 of file ChainEvent.cc.

255  {
256  return event_->triggerNames(triggerResults);
257  }

References event_, and triggerResults.

◆ triggerResultsByName()

edm::TriggerResultsByName ChainEvent::triggerResultsByName ( edm::TriggerResults const &  triggerResults) const
overridevirtual

Implements edm::EventBase.

Definition at line 265 of file ChainEvent.cc.

265  {
266  return event_->triggerResultsByName(triggerResults);
267  }

References event_, and triggerResults.

Friends And Related Function Documentation

◆ MultiChainEvent

friend class MultiChainEvent
friend

Definition at line 127 of file ChainEvent.h.

Member Data Documentation

◆ accumulatedSize_

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

Definition at line 140 of file ChainEvent.h.

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

◆ event_

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

◆ eventIndex_

Long64_t fwlite::ChainEvent::eventIndex_
private

Definition at line 139 of file ChainEvent.h.

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

◆ file_

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

Definition at line 137 of file ChainEvent.h.

Referenced by ChainEvent(), and switchToFile().

◆ fileNames_

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

Definition at line 136 of file ChainEvent.h.

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

◆ getter_

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

Definition at line 141 of file ChainEvent.h.

edm::poolNames::eventTreeName
std::string const & eventTreeName()
Definition: BranchType.cc:220
fwlite::ChainEvent::event
Event const * event() const
Definition: ChainEvent.h:98
tree
Definition: tree.py:1
triggerResults
static const std::string triggerResults
Definition: EdmProvDump.cc:45
edm::propagate_const::get
constexpr element_type const * get() const
Definition: propagate_const.h:64
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
fwlite::ChainEvent::switchToFile
void switchToFile(Long64_t)
Definition: ChainEvent.cc:180
fwlite::ChainEvent::event_
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:138
fwlite::ChainEvent::fileNames_
std::vector< std::string > fileNames_
Definition: ChainEvent.h:136
compare_using_db.ifile
ifile
Definition: compare_using_db.py:251
fwlite::ChainEvent::accumulatedSize_
std::vector< Long64_t > accumulatedSize_
Definition: ChainEvent.h:140
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
fwlite::ChainEvent::file_
edm::propagate_const< std::shared_ptr< TFile > > file_
Definition: ChainEvent.h:137
edm::EventBase::luminosityBlock
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
fwlite::ChainEvent::to
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: ChainEvent.cc:106
fwlite::ChainEvent::eventIndex_
Long64_t eventIndex_
Definition: ChainEvent.h:139
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Exception
Definition: hltDiff.cc:245
fwlite::ChainEvent::size
Long64_t size() const
Definition: ChainEvent.cc:253
event
Definition: event.py:1
nEvents
UInt_t nEvents
Definition: hcalCalib.cc:40
crabWrapper.key
key
Definition: crabWrapper.py:19
lumi
Definition: LumiSectionData.h:20
class-composition.parent
parent
Definition: class-composition.py:98
fwlite::Event::throwProductNotFoundException
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
Definition: Event.cc:492