CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

virtual bool atEnd () const
 
 ChainEvent (std::vector< std::string > const &iFileNames)
 
Event const * event () const
 
virtual edm::EventAuxiliary const & eventAuxiliary () const
 
Long64_t eventIndex () const
 
virtual Long64_t fileIndex () const
 
void fillParameterSetRegistry () 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 edm::WrapperBase const * getByProductID (edm::ProductID const &) const
 
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++ ()
 
virtual edm::ProcessHistory const & processHistory () const
 
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 ()
 
virtual edm::TriggerNames const & triggerNames (edm::TriggerResults const &triggerResults) const
 
virtual edm::TriggerResultsByName triggerResultsByName (edm::TriggerResults const &triggerResults) const
 
virtual ~ChainEvent ()
 
- Public Member Functions inherited from fwlite::EventBase
 EventBase ()
 
virtual Long64_t secondaryFileIndex () const
 
virtual ~EventBase ()
 
- 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 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, switchToFile(), and MainPageGenerator::tree.

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

Definition at line 74 of file ChainEvent.cc.

75 {
76 }
fwlite::ChainEvent::ChainEvent ( Event const &  )
private

Member Function Documentation

bool ChainEvent::atEnd ( ) const
virtual

Implements fwlite::EventBase.

Definition at line 301 of file ChainEvent.cc.

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

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

302 {
303  if (!size()) return true;
304  if (eventIndex_ == static_cast<Long64_t>(fileNames_.size())-1) {
305  return event_->atEnd();
306  }
307  return false;
308 }
Long64_t size() const
Definition: ChainEvent.cc:311
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
Long64_t eventIndex_
Definition: ChainEvent.h:143
std::vector< std::string > fileNames_
Definition: ChainEvent.h:140
Event const* fwlite::ChainEvent::event ( ) const
inline

Definition at line 108 of file ChainEvent.h.

References event_.

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

108 { return &*event_; }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
edm::EventAuxiliary const & ChainEvent::eventAuxiliary ( ) const
virtual

Implements edm::EventBase.

Definition at line 250 of file ChainEvent.cc.

References event_.

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

Definition at line 101 of file ChainEvent.h.

References eventIndex_.

101 { return eventIndex_; }
Long64_t eventIndex_
Definition: ChainEvent.h:143
virtual Long64_t fwlite::ChainEvent::fileIndex ( ) const
inlinevirtual

Reimplemented from fwlite::EventBase.

Definition at line 102 of file ChainEvent.h.

References eventIndex_.

Referenced by python.Events::fileIndicies().

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

Definition at line 323 of file ChainEvent.cc.

References event_.

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

Definition at line 232 of file ChainEvent.cc.

References event_.

233 {
234  return event_->getBranchDescriptions();
235 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
std::string const ChainEvent::getBranchNameFor ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess 
) const
virtual

Implements fwlite::EventBase.

Definition at line 223 of file ChainEvent.cc.

References event_.

227 {
228  return event_->getBranchNameFor(iType,iModule,iInstance,iProcess);
229 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
bool ChainEvent::getByLabel ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess,
void *  iValue 
) const
virtual

Implements fwlite::EventBase.

Definition at line 266 of file ChainEvent.cc.

References event_.

271 {
272  return event_->getByLabel(iType, iModule, iInstance, iProcess, iValue);
273 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
edm::WrapperBase const * ChainEvent::getByProductID ( edm::ProductID const &  iID) const
virtual

Implements fwlite::EventBase.

Definition at line 275 of file ChainEvent.cc.

References event_.

276 {
277  return event_->getByProductID(iID);
278 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
fwlite::LuminosityBlock const & ChainEvent::getLuminosityBlock ( )

Definition at line 255 of file ChainEvent.cc.

References event_.

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

Definition at line 238 of file ChainEvent.cc.

References event_.

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

Definition at line 260 of file ChainEvent.cc.

References event_.

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

Definition at line 91 of file ChainEvent.h.

References event_.

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

Definition at line 280 of file ChainEvent.cc.

References event_.

280  {
281  return event_->getThinnedProduct(pid, key);
282 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
tuple pid
Definition: sysUtil.py:22
void ChainEvent::getThinnedProducts ( edm::ProductID const &  pid,
std::vector< edm::WrapperBase const * > &  foundContainers,
std::vector< unsigned int > &  keys 
) const

Definition at line 284 of file ChainEvent.cc.

References event_.

286  {
287  event_->getThinnedProducts(pid, foundContainers, keys);
288 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
tuple pid
Definition: sysUtil.py:22
bool ChainEvent::isValid ( void  ) const

Definition at line 291 of file ChainEvent.cc.

References event_.

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

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

Definition at line 295 of file ChainEvent.cc.

References event_().

296 {
297  return *event_;
298 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
ChainEvent const & ChainEvent::operator++ ( )
virtual

Implements fwlite::EventBase.

Definition at line 95 of file ChainEvent.cc.

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

96 {
97  if(eventIndex_ != static_cast<Long64_t>(fileNames_.size())-1)
98  {
99  ++(*event_);
100  if(event_->atEnd()) {
102  }
103  } else {
104  if(*event_) {
105  ++(*event_);
106  }
107  }
108  return *this;
109 }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:210
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
Long64_t eventIndex_
Definition: ChainEvent.h:143
std::vector< std::string > fileNames_
Definition: ChainEvent.h:140
ChainEvent const& fwlite::ChainEvent::operator= ( Event const &  )
private
edm::ProcessHistory const & ChainEvent::processHistory ( ) const
virtual

Implements edm::EventBase.

Definition at line 244 of file ChainEvent.cc.

References event_.

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

Definition at line 104 of file ChainEvent.h.

References event_.

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

Definition at line 311 of file ChainEvent.cc.

References accumulatedSize_.

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

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

Definition at line 210 of file ChainEvent.cc.

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

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

211 {
212  eventIndex_= iIndex;
213  TFile *tfilePtr = TFile::Open(fileNames_[iIndex].c_str());
214  file_ = std::shared_ptr<TFile>(tfilePtr);
215  gROOT->GetListOfFiles()->Remove(tfilePtr);
216  event_ = std::make_shared<Event>(file_.get());
217 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
Long64_t eventIndex_
Definition: ChainEvent.h:143
element_type const * get() const
edm::propagate_const< std::shared_ptr< TFile > > file_
Definition: ChainEvent.h:141
std::vector< std::string > fileNames_
Definition: ChainEvent.h:140
void ChainEvent::throwProductNotFoundException ( std::type_info const &  iType,
char const *  iModule,
char const *  iInstance,
char const *  iProcess 
)
static

Definition at line 337 of file ChainEvent.cc.

References fwlite::Event::throwProductNotFoundException().

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

340  {
341  Event::throwProductNotFoundException(iType,iModule,iInstance,iProcess);
342 }
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
Definition: Event.cc:510
bool ChainEvent::to ( Long64_t  iIndex)

Go to the event at index iIndex.

Definition at line 113 of file ChainEvent.cc.

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

Referenced by to().

114 {
115  if (iIndex >= accumulatedSize_.back())
116  {
117  // if we're here, then iIndex was not valid
118  return false;
119  }
120 
121  Long64_t offsetIndex = eventIndex_;
122 
123  // we're going backwards, so start from the beginning
124  if (iIndex < accumulatedSize_[offsetIndex]) {
125  offsetIndex = 0;
126  }
127 
128  // is it past the end of this file?
129  while (iIndex >= accumulatedSize_[offsetIndex+1]) {
130  ++offsetIndex;
131  }
132 
133  if(offsetIndex != eventIndex_) {
134  switchToFile(eventIndex_ = offsetIndex);
135  }
136 
137  // adjust to entry # in this file
138  return event_->to(iIndex-accumulatedSize_[offsetIndex]);
139 }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:210
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
Long64_t eventIndex_
Definition: ChainEvent.h:143
std::vector< Long64_t > accumulatedSize_
Definition: ChainEvent.h:144
bool ChainEvent::to ( const edm::EventID id)

Go to event with event id "id".

Definition at line 144 of file ChainEvent.cc.

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

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

Definition at line 190 of file ChainEvent.cc.

References to().

191 {
192  return to(run, 0U, event);
193 }
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: ChainEvent.cc:113
Event const * event() const
Definition: ChainEvent.h:108
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 152 of file ChainEvent.cc.

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

153 {
154 
155  // First try this file
156  if (event_->to(run, lumi, event))
157  {
158  // found it, return
159  return true;
160  }
161  else
162  {
163  // Did not find it, try the other files sequentially.
164  // Someday I can make this smarter. For now... we get something working.
165  Long64_t thisFile = eventIndex_;
166  std::vector<std::string>::const_iterator filesBegin = fileNames_.begin(),
167  filesEnd = fileNames_.end(), ifile = filesBegin;
168  for (; ifile != filesEnd; ++ifile)
169  {
170  // skip the "first" file that we tried
171  if (ifile - filesBegin != thisFile)
172  {
173  // switch to the next file
174  switchToFile(ifile - filesBegin);
175  // check that tree for the desired event
176  if (event_->to(run, lumi, event))
177  {
178  // found it, return
179  return true;
180  }
181  }// end ignore "first" file that we tried
182  }// end loop over files
183 
184  // did not find the event with id "id".
185  return false;
186  }// end if we did not find event id in "first" file
187 }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:210
tuple lumi
Definition: fjr2json.py:35
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
Long64_t eventIndex_
Definition: ChainEvent.h:143
Event const * event() const
Definition: ChainEvent.h:108
std::vector< std::string > fileNames_
Definition: ChainEvent.h:140
ChainEvent const & ChainEvent::toBegin ( )
virtual

Go to the very first Event

Implements fwlite::EventBase.

Definition at line 198 of file ChainEvent.cc.

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

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

199 {
200  if (!size()) return *this;
201  if (eventIndex_ != 0)
202  {
203  switchToFile(0);
204  }
205  event_->toBegin();
206  return *this;
207 }
Long64_t size() const
Definition: ChainEvent.cc:311
void switchToFile(Long64_t)
Definition: ChainEvent.cc:210
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
Long64_t eventIndex_
Definition: ChainEvent.h:143
edm::TriggerNames const & ChainEvent::triggerNames ( edm::TriggerResults const &  triggerResults) const
virtual

Implements edm::EventBase.

Definition at line 317 of file ChainEvent.cc.

References event_.

318 {
319  return event_->triggerNames(triggerResults);
320 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
static std::string const triggerResults
Definition: EdmProvDump.cc:41
edm::TriggerResultsByName ChainEvent::triggerResultsByName ( edm::TriggerResults const &  triggerResults) const
virtual

Implements edm::EventBase.

Definition at line 329 of file ChainEvent.cc.

References event_.

329  {
330  return event_->triggerResultsByName(triggerResults);
331 }
edm::propagate_const< std::shared_ptr< Event > > event_
Definition: ChainEvent.h:142
static std::string const triggerResults
Definition: EdmProvDump.cc:41

Friends And Related Function Documentation

friend class MultiChainEvent
friend

Definition at line 131 of file ChainEvent.h.

Member Data Documentation

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

Definition at line 144 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 143 of file ChainEvent.h.

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

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

Definition at line 141 of file ChainEvent.h.

Referenced by ChainEvent(), and switchToFile().

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

Definition at line 140 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 145 of file ChainEvent.h.