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  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  }

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

◆ ~ChainEvent()

ChainEvent::~ChainEvent ( )
override

Definition at line 70 of file ChainEvent.cc.

70 {}

◆ ChainEvent() [2/2]

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

Member Function Documentation

◆ atEnd()

bool ChainEvent::atEnd ( ) const
overridevirtual

Implements fwlite::EventBase.

Definition at line 241 of file ChainEvent.cc.

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

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

203 { 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 260 of file ChainEvent.cc.

260 { event_->fillParameterSetRegistry(); }

References event_.

◆ findSizes()

void fwlite::ChainEvent::findSizes ( )
private

◆ getBranchDescriptions()

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

Definition at line 195 of file ChainEvent.cc.

195  {
196  return event_->getBranchDescriptions();
197  }

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

191  {
192  return event_->getBranchNameFor(iType, iModule, iInstance, iProcess);
193  }

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

213  {
214  return event_->getByLabel(iType, iModule, iInstance, iProcess, iValue);
215  }

References event_.

◆ getByProductID()

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

Implements fwlite::EventBase.

Definition at line 217 of file ChainEvent.cc.

217  {
218  return event_->getByProductID(iID);
219  }

References event_.

◆ getLuminosityBlock()

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

Definition at line 205 of file ChainEvent.cc.

205 { return event_->getLuminosityBlock(); }

References event_.

◆ getProcessHistory()

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

Definition at line 199 of file ChainEvent.cc.

199 { return event_->getProcessHistory(); }

References event_.

◆ getRun()

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

Definition at line 207 of file ChainEvent.cc.

207 { 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 232 of file ChainEvent.cc.

234  {
235  return event_->getThinnedKeyFrom(parent, key, thinned);
236  }

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

222  {
223  return event_->getThinnedProduct(pid, key);
224  }

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

228  {
229  event_->getThinnedProducts(pid, foundContainers, keys);
230  }

References event_, and relativeConstraints::keys.

◆ isValid()

bool ChainEvent::isValid ( void  ) const

Definition at line 238 of file ChainEvent.cc.

238 { return event_->isValid(); }

References event_.

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

◆ operator bool()

ChainEvent::operator bool ( ) const

Definition at line 239 of file ChainEvent.cc.

239 { return *event_; }

References event_().

◆ operator++()

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

Implements fwlite::EventBase.

Definition at line 88 of file ChainEvent.cc.

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  }

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

256  {
257  return event_->parameterSet(psID);
258  }

References event_.

◆ processHistory()

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

Implements edm::EventBase.

Definition at line 201 of file ChainEvent.cc.

201 { 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 250 of file ChainEvent.cc.

250 { 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 177 of file ChainEvent.cc.

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  }

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

272  {
273  Event::throwProductNotFoundException(iType, iModule, iInstance, iProcess);
274  }

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

130 { 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 163 of file ChainEvent.cc.

163 { 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 134 of file ChainEvent.cc.

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  }

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

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  }

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

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

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

◆ triggerNames()

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

Implements edm::EventBase.

Definition at line 252 of file ChainEvent.cc.

252  {
253  return event_->triggerNames(triggerResults);
254  }

References event_, and triggerResults.

◆ triggerResultsByName()

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

Implements edm::EventBase.

Definition at line 262 of file ChainEvent.cc.

262  {
263  return event_->triggerResultsByName(triggerResults);
264  }

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:208
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:177
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:103
fwlite::ChainEvent::eventIndex_
Long64_t eventIndex_
Definition: ChainEvent.h:139
writedatasetfile.run
run
Definition: writedatasetfile.py:27
Exception
Definition: hltDiff.cc:246
fwlite::ChainEvent::size
Long64_t size() const
Definition: ChainEvent.cc:250
event
Definition: event.py:1
nEvents
UInt_t nEvents
Definition: hcalCalib.cc:41
crabWrapper.key
key
Definition: crabWrapper.py:19
lumi
Definition: LumiSectionData.h:20
class-composition.parent
parent
Definition: class-composition.py:88
fwlite::Event::throwProductNotFoundException
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
Definition: Event.cc:492