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 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
 
bool isValid () const
 
 operator bool () const
 
ChainEvent const & operator++ ()
 
virtual edm::ProcessHistory const & processHistory () const
 
void setGetter (boost::shared_ptr< edm::EDProductGetter > 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 (std::string const &process) 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 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_
 
boost::shared_ptr< Eventevent_
 
Long64_t eventIndex_
 
boost::shared_ptr< TFile > file_
 
std::vector< std::string > fileNames_
 
boost::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(), edm::hlt::Exception, file_, 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 (std::vector<std::string>::const_iterator it= iFileNames.begin(), itEnd = iFileNames.end();
47  it!=itEnd;
48  ++it) {
49  TFile *tfilePtr = TFile::Open(it->c_str());
50  file_ = boost::shared_ptr<TFile>(tfilePtr);
51  gROOT->GetListOfFiles()->Remove(tfilePtr);
52  TTree* tree = dynamic_cast<TTree*>(file_->Get(edm::poolNames::eventTreeName().c_str()));
53  if (0 == tree) {
54  throw cms::Exception("NotEdmFile")<<"The file "<<*it<<" has no 'Events' TTree and therefore is not an EDM ROOT file";
55  }
56  Long64_t nEvents = tree->GetEntries();
57  if (nEvents > 0) { // skip empty files
58  fileNames_.push_back(*it);
59  // accumulatedSize_ is the entry # at the beginning of this file
60  accumulatedSize_.push_back(summedSize);
61  summedSize += nEvents;
62  }
63  }
64  // total accumulated size (last enry + 1) at the end of last file
65  accumulatedSize_.push_back(summedSize);
66 
67  if (fileNames_.size() > 0)
68  switchToFile(0);
69 }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:211
Long64_t eventIndex_
Definition: ChainEvent.h:136
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
std::vector< Long64_t > accumulatedSize_
Definition: ChainEvent.h:137
std::string const & eventTreeName()
Definition: BranchType.cc:254
UInt_t nEvents
Definition: hcalCalib.cc:42
boost::shared_ptr< TFile > file_
Definition: ChainEvent.h:134
std::vector< std::string > fileNames_
Definition: ChainEvent.h:133
ChainEvent::~ChainEvent ( )
virtual

Definition at line 76 of file ChainEvent.cc.

77 {
78 }
fwlite::ChainEvent::ChainEvent ( Event const &  )
private

Member Function Documentation

bool ChainEvent::atEnd ( ) const
virtual

Implements fwlite::EventBase.

Definition at line 302 of file ChainEvent.cc.

References event_, eventIndex_, and fileNames_.

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

303 {
304  if (eventIndex_ == static_cast<Long64_t>(fileNames_.size())-1) {
305  return event_->atEnd();
306  }
307  return false;
308 }
Long64_t eventIndex_
Definition: ChainEvent.h:136
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
std::vector< std::string > fileNames_
Definition: ChainEvent.h:133
Event const* fwlite::ChainEvent::event ( ) const
inline

Definition at line 107 of file ChainEvent.h.

References event_.

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

107 { return &*event_; }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
edm::EventAuxiliary const & ChainEvent::eventAuxiliary ( ) const
virtual

Implements edm::EventBase.

Definition at line 251 of file ChainEvent.cc.

References event_.

252 {
253  return event_->eventAuxiliary();
254 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
Long64_t fwlite::ChainEvent::eventIndex ( ) const
inline

Definition at line 100 of file ChainEvent.h.

References eventIndex_.

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

Reimplemented from fwlite::EventBase.

Definition at line 101 of file ChainEvent.h.

References eventIndex_.

Referenced by python.Events::fileIndicies().

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

Definition at line 323 of file ChainEvent.cc.

References event_.

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

Definition at line 233 of file ChainEvent.cc.

References event_.

234 {
235  return event_->getBranchDescriptions();
236 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
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 224 of file ChainEvent.cc.

References event_.

228 {
229  return event_->getBranchNameFor(iType,iModule,iInstance,iProcess);
230 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
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 267 of file ChainEvent.cc.

References event_.

272 {
273  return event_->getByLabel(iType, iModule, iInstance, iProcess, iValue);
274 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
bool ChainEvent::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 277 of file ChainEvent.cc.

References event_.

282 {
283  return event_->getByLabel(iType, iModule, iInstance, iProcess, holder);
284 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
edm::WrapperHolder ChainEvent::getByProductID ( edm::ProductID const &  iID) const

Definition at line 286 of file ChainEvent.cc.

References event_.

287 {
288  return event_->getByProductID(iID);
289 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
fwlite::LuminosityBlock const & ChainEvent::getLuminosityBlock ( )

Definition at line 256 of file ChainEvent.cc.

References event_.

257 {
258  return event_->getLuminosityBlock();
259 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
std::vector< std::string > const & ChainEvent::getProcessHistory ( ) const

Definition at line 239 of file ChainEvent.cc.

References event_.

240 {
241  return event_->getProcessHistory();
242 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
fwlite::Run const & ChainEvent::getRun ( )

Definition at line 261 of file ChainEvent.cc.

References event_.

262 {
263  return event_->getRun();
264 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
TFile* fwlite::ChainEvent::getTFile ( ) const
inline

Definition at line 90 of file ChainEvent.h.

References event_.

90  {
91  return event_->getTFile();
92  }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
bool ChainEvent::isValid ( void  ) const

Definition at line 292 of file ChainEvent.cc.

References event_.

293 {
294  return event_->isValid();
295 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
ChainEvent::operator bool ( ) const

Definition at line 296 of file ChainEvent.cc.

References event_().

297 {
298  return *event_;
299 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
ChainEvent const & ChainEvent::operator++ ( )
virtual

Implements fwlite::EventBase.

Definition at line 97 of file ChainEvent.cc.

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

98 {
99  if(eventIndex_ != static_cast<Long64_t>(fileNames_.size())-1)
100  {
101  ++(*event_);
102  if(event_->atEnd()) {
104  }
105  } else {
106  if(*event_) {
107  ++(*event_);
108  }
109  }
110  return *this;
111 }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:211
Long64_t eventIndex_
Definition: ChainEvent.h:136
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
std::vector< std::string > fileNames_
Definition: ChainEvent.h:133
ChainEvent const& fwlite::ChainEvent::operator= ( Event const &  )
private
edm::ProcessHistory const & ChainEvent::processHistory ( ) const
virtual

Implements edm::EventBase.

Definition at line 245 of file ChainEvent.cc.

References event_.

246 {
247  return event_->processHistory();
248 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
void fwlite::ChainEvent::setGetter ( boost::shared_ptr< edm::EDProductGetter getter)
inline

Definition at line 103 of file ChainEvent.h.

References event_.

103  {
104  event_->setGetter(getter);
105  }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
Long64_t ChainEvent::size ( void  ) const

Definition at line 311 of file ChainEvent.cc.

References accumulatedSize_.

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

Definition at line 211 of file ChainEvent.cc.

References event_, eventIndex_, file_, and fileNames_.

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

212 {
213  eventIndex_= iIndex;
214  TFile *tfilePtr = TFile::Open(fileNames_[iIndex].c_str());
215  file_ = boost::shared_ptr<TFile>(tfilePtr);
216  gROOT->GetListOfFiles()->Remove(tfilePtr);
217  event_ = boost::shared_ptr<Event>(new Event(file_.get()));
218 }
Long64_t eventIndex_
Definition: ChainEvent.h:136
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
boost::shared_ptr< TFile > file_
Definition: ChainEvent.h:134
std::vector< std::string > fileNames_
Definition: ChainEvent.h:133
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:492
bool ChainEvent::to ( Long64_t  iIndex)

Go to the event at index iIndex.

Definition at line 115 of file ChainEvent.cc.

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

Referenced by to().

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

Go to event with event id "id".

Definition at line 146 of file ChainEvent.cc.

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

147 {
148  return to(id.run(), id.luminosityBlock(), id.event());
149 }
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: ChainEvent.cc:115
Event const * event() const
Definition: ChainEvent.h:107
bool ChainEvent::to ( edm::RunNumber_t  run,
edm::EventNumber_t  event 
)

Definition at line 192 of file ChainEvent.cc.

References to().

193 {
194  return to(run, 0U, event);
195 }
bool to(Long64_t iIndex)
Go to the event at index iIndex.
Definition: ChainEvent.cc:115
Event const * event() const
Definition: ChainEvent.h:107
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 154 of file ChainEvent.cc.

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

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

Go to the very first Event

Implements fwlite::EventBase.

Definition at line 200 of file ChainEvent.cc.

References event_, eventIndex_, and switchToFile().

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

201 {
202  if (eventIndex_ != 0)
203  {
204  switchToFile(0);
205  }
206  event_->toBegin();
207  return *this;
208 }
void switchToFile(Long64_t)
Definition: ChainEvent.cc:211
Long64_t eventIndex_
Definition: ChainEvent.h:136
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
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 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
static std::string const triggerResults
Definition: EdmProvDump.cc:41
edm::TriggerResultsByName ChainEvent::triggerResultsByName ( std::string const &  process) const
virtual

Implements edm::EventBase.

Definition at line 329 of file ChainEvent.cc.

References event_.

329  {
330  return event_->triggerResultsByName(process);
331 }
boost::shared_ptr< Event > event_
Definition: ChainEvent.h:135
tuple process
Definition: LaserDQM_cfg.py:3

Friends And Related Function Documentation

friend class MultiChainEvent
friend

Definition at line 124 of file ChainEvent.h.

Member Data Documentation

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

Definition at line 137 of file ChainEvent.h.

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

boost::shared_ptr<Event> fwlite::ChainEvent::event_
private
Long64_t fwlite::ChainEvent::eventIndex_
private

Definition at line 136 of file ChainEvent.h.

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

boost::shared_ptr<TFile> fwlite::ChainEvent::file_
private

Definition at line 134 of file ChainEvent.h.

Referenced by ChainEvent(), and switchToFile().

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

Definition at line 133 of file ChainEvent.h.

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

boost::shared_ptr<edm::EDProductGetter> fwlite::ChainEvent::getter_
private

Definition at line 138 of file ChainEvent.h.