CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LuminosityBlock.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DataFormats/FWLite
4 // Class : LuminosityBlock
5 //
14 //
15 // Original Author: Eric Vaandering
16 // Created: Wed Jan 13 15:01:20 EDT 2007
17 //
18 
19 // system include files
20 #include <iostream>
21 
22 // user include files
24 #include "TFile.h"
25 #include "TTree.h"
29 
33 
34 //used for backwards compatability
36 
37 //
38 // constants, enums and typedefs
39 //
40 namespace fwlite {
41 
42 //
43 // constructors and destructor
44 //
46  branchMap_(new BranchMapReader(iFile)),
47  pAux_(&aux_),
48  pOldAux_(0),
49  fileVersion_(-1),
50  dataHelper_(branchMap_->getLuminosityBlockTree(),
51  boost::shared_ptr<HistoryGetterBase>(new LumiHistoryGetter(this)),
52  branchMap_)
53  {
54  if(0==iFile) {
55  throw cms::Exception("NoFile")<<"The TFile pointer passed to the constructor was null";
56  }
57 
58  if(0==branchMap_->getLuminosityBlockTree()) {
59  throw cms::Exception("NoLumiTree")<<"The TFile contains no TTree named " <<edm::poolNames::luminosityBlockTreeName();
60  }
61  //need to know file version in order to determine how to read the basic product info
62  fileVersion_ = branchMap_->getFileVersion(iFile);
63 
64  //got this logic from IOPool/Input/src/RootFile.cc
65 
66  TTree* luminosityBlockTree = branchMap_->getLuminosityBlockTree();
67  if(fileVersion_ >= 3) {
68  auxBranch_ = luminosityBlockTree->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InLumi).c_str());
69  if(0==auxBranch_) {
70  throw cms::Exception("NoLuminosityBlockAuxilliary")<<"The TTree "
72  <<" does not contain a branch named 'LuminosityBlockAuxiliary'";
73  }
74  auxBranch_->SetAddress(&pAux_);
75  } else {
76  throw cms::Exception("OldFileVersion")<<"The FWLite Luminosity Block code des not support old file versions";
77 // This code commented from fwlite::Event. May be portable if needed.
78 // pOldAux_ = new edm::EventAux();
79 // auxBranch_ = luminosityBlockTree->GetBranch(edm::BranchTypeToAuxBranchName(edm::InLuminosityBlock).c_str());
80 // if(0==auxBranch_) {
81 // throw cms::Exception("NoLuminosityBlockAux")<<"The TTree "
82 // <<edm::poolNames::luminosityBlockTreeName()
83 // <<" does not contain a branch named 'LuminosityBlockAux'";
84 // }
85 // auxBranch_->SetAddress(&pOldAux_);
86  }
87  branchMap_->updateLuminosityBlock(0);
88  runFactory_ = boost::shared_ptr<RunFactory>(new RunFactory());
89 }
90 
91  LuminosityBlock::LuminosityBlock(boost::shared_ptr<BranchMapReader> branchMap, boost::shared_ptr<RunFactory> runFactory):
92  branchMap_(branchMap),
93  pAux_(&aux_),
94  pOldAux_(0),
95  fileVersion_(-1),
96  dataHelper_(branchMap_->getLuminosityBlockTree(),
97  boost::shared_ptr<HistoryGetterBase>(new LumiHistoryGetter(this)),
98  branchMap_),
99  runFactory_(runFactory)
100  {
101 
102  if(0==branchMap_->getLuminosityBlockTree()) {
103  throw cms::Exception("NoLumiTree")<<"The TFile contains no TTree named " <<edm::poolNames::luminosityBlockTreeName();
104  }
105  //need to know file version in order to determine how to read the basic event info
106  fileVersion_ = branchMap_->getFileVersion();
107  //got this logic from IOPool/Input/src/RootFile.cc
108 
109  TTree* luminosityBlockTree = branchMap_->getLuminosityBlockTree();
110  if(fileVersion_ >= 3) {
111  auxBranch_ = luminosityBlockTree->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InLumi).c_str());
112  if(0==auxBranch_) {
113  throw cms::Exception("NoLuminosityBlockAuxilliary")<<"The TTree "
115  <<" does not contain a branch named 'LuminosityBlockAuxiliary'";
116  }
117  auxBranch_->SetAddress(&pAux_);
118  } else {
119  throw cms::Exception("OldFileVersion")<<"The FWLite Luminosity Block code des not support old file versions";
120 /* pOldAux_ = new edm::EventAux();
121  auxBranch_ = luminosityBlockTree->GetBranch(edm::BranchTypeToAuxBranchName(edm::InLuminosityBlock).c_str());
122  if(0==auxBranch_) {
123  throw cms::Exception("NoLuminosityBlockAux")<<"The TTree "
124  <<edm::poolNames::luminosityBlockTreeName()
125  <<" does not contain a branch named 'LuminosityBlockAux'";
126  }
127  auxBranch_->SetAddress(&pOldAux_);*/
128  }
129  branchMap_->updateLuminosityBlock(0);
130 
131 // if(fileVersion_ >= 7) {
132 // eventHistoryTree_ = dynamic_cast<TTree*>(iFile->Get(edm::poolNames::eventHistoryTreeName().c_str()));
133 // }
134 
135 }
136 
138 {
139  for(std::vector<char const*>::iterator it = labels_.begin(), itEnd=labels_.end();
140  it != itEnd;
141  ++it) {
142  delete [] *it;
143  }
144  delete pOldAux_;
145 }
146 
147 //
148 // member functions
149 //
150 
151 const LuminosityBlock&
153 {
154  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
155  if(luminosityBlockIndex < size())
156  {
157  branchMap_->updateLuminosityBlock(++luminosityBlockIndex);
158  }
159  return *this;
160 }
161 
162 
163 bool
165 {
167  EntryFinder::EntryNumber_t entry = entryFinder_.findLumi(run, luminosityBlock);
168  if (entry == EntryFinder::invalidEntry) {
169  return false;
170  }
171  return branchMap_->updateLuminosityBlock(entry);
172 }
173 
174 const LuminosityBlock&
176 {
177  branchMap_->updateLuminosityBlock(0);
178  return *this;
179 }
180 
181 //
182 // const member functions
183 //
184 Long64_t
186 {
187  return branchMap_->getLuminosityBlockTree()->GetEntries();
188 }
189 
190 bool
192 {
193  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
194  return luminosityBlockIndex!=-1 and luminosityBlockIndex < size();
195 }
196 
197 
199 {
200  return isValid();
201 }
202 
203 bool
205 {
206  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
207  return luminosityBlockIndex==-1 or luminosityBlockIndex == size();
208 }
209 
210 
211 std::string const
212 LuminosityBlock::getBranchNameFor(std::type_info const& iInfo,
213  char const* iModuleLabel,
214  char const* iProductInstanceLabel,
215  char const* iProcessLabel) const
216 {
217  return dataHelper_.getBranchNameFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
218 }
219 
220 
221 bool
223  std::type_info const& iInfo,
224  char const* iModuleLabel,
225  char const* iProductInstanceLabel,
226  char const* iProcessLabel,
227  void* oData) const {
228  if(atEnd()) {
229  throw cms::Exception("OffEnd")<<"You have requested data past the last lumi";
230  }
231  Long_t lumiIndex = branchMap_->getLuminosityBlockEntry();
232  return dataHelper_.getByLabel(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel, oData, lumiIndex);
233 }
234 
235 bool
236 LuminosityBlock::getByLabel(std::type_info const& iInfo,
237  char const* iModuleLabel,
238  char const* iProductInstanceLabel,
239  char const* iProcessLabel,
240  edm::WrapperHolder& holder) const {
241  if(atEnd()) {
242  throw cms::Exception("OffEnd") << "You have requested data past the last lumi";
243  }
244  Long_t lumiIndex = branchMap_->getLuminosityBlockEntry();
245  return dataHelper_.getByLabel(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel, holder, lumiIndex);
246 }
247 
250 {
251  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
252  updateAux(luminosityBlockIndex);
253  return aux_;
254 }
255 
256 void
257 LuminosityBlock::updateAux(Long_t luminosityBlockIndex) const
258 {
259  if(auxBranch_->GetEntryNumber() != luminosityBlockIndex) {
260  auxBranch_->GetEntry(luminosityBlockIndex);
261  //handling dealing with old version
262  if(0 != pOldAux_) {
264  }
265  }
266 }
267 
268 
269 const edm::ProcessHistory&
271 {
272  edm::ProcessHistoryID processHistoryID;
273 
274  bool newFormat = false;//(fileVersion_ >= 5);
275 
276  Long_t lumiIndex = branchMap_->getLuminosityBlockEntry();
277  updateAux(lumiIndex);
278  if (!newFormat) {
279  processHistoryID = aux_.processHistoryID();
280  }
281 
282  if(historyMap_.empty() || newFormat) {
283  procHistoryNames_.clear();
284  TTree *meta = dynamic_cast<TTree*>(branchMap_->getFile()->Get(edm::poolNames::metaDataTreeName().c_str()));
285  if(0==meta) {
286  throw cms::Exception("NoMetaTree")<<"The TFile does not appear to contain a TTree named "
288  }
289  if (historyMap_.empty()) {
290  if (fileVersion_ < 11) {
292  TBranch* b = meta->GetBranch(edm::poolNames::processHistoryMapBranchName().c_str());
293  b->SetAddress(&pPhm);
294  b->GetEntry(0);
295  } else {
296  edm::ProcessHistoryVector historyVector;
297  edm::ProcessHistoryVector* pPhv=&historyVector;
298  TBranch* b = meta->GetBranch(edm::poolNames::processHistoryBranchName().c_str());
299  b->SetAddress(&pPhv);
300  b->GetEntry(0);
301  for (edm::ProcessHistoryVector::const_iterator i = historyVector.begin(), e = historyVector.end();
302  i != e; ++i) {
303  historyMap_.insert(std::make_pair(i->id(), *i));
304  }
305  }
306  }
307 // if (newFormat) {
308 // if (fileVersion_ >= 7) {
309 // edm::History history;
310 // edm::History* pHistory = &history;
311 // TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
312 // if (!eventHistoryBranch)
313 // throw edm::Exception(edm::errors::FatalRootError)
314 // << "Failed to find history branch in event history tree";
315 // eventHistoryBranch->SetAddress(&pHistory);
316 // eventHistoryTree_->GetEntry(lumiIndex);
317 // processHistoryID = history.processHistoryID();
318 // } else {
319 // std::vector<edm::EventProcessHistoryID> *pEventProcessHistoryIDs = &eventProcessHistoryIDs_;
320 // TBranch* b = meta->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
321 // b->SetAddress(&pEventProcessHistoryIDs);
322 // b->GetEntry(0);
323 // edm::EventProcessHistoryID target(aux_.id(), edm::ProcessHistoryID());
324 // processHistoryID = std::lower_bound(eventProcessHistoryIDs_.begin(), eventProcessHistoryIDs_.end(), target)->processHistoryID_;
325 // }
326 // }
327 
328  }
329  return historyMap_[processHistoryID];
330 }
331 
332 
335  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
336  return dataHelper_.getByProductID(iID, luminosityBlockIndex);
337 }
338 
339 
340 //
341 // static member functions
342 //
343 void
344 LuminosityBlock::throwProductNotFoundException(std::type_info const& iType, char const* iModule, char const* iProduct, char const* iProcess)
345 {
346  edm::TypeID type(iType);
347  throw edm::Exception(edm::errors::ProductNotFound)<<"A branch was found for \n type ='"<<type.className()<<"'\n module='"<<iModule
348  <<"'\n productInstance='"<<((0!=iProduct)?iProduct:"")<<"'\n process='"<<((0!=iProcess)?iProcess:"")<<"'\n"
349  "but no data is available for this LuminosityBlock";
350 }
351 
352 
353 namespace {
354  struct NoDelete {
355  void operator()(void*){}
356  };
357 }
358 
360  run_ = runFactory_->makeRun(boost::shared_ptr<BranchMapReader>(&*branchMap_,NoDelete()));
362  run_->to(run);
363  return *run_;
364 }
365 
366 }
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:114
DataGetterHelper dataHelper_
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
bool to(edm::RunNumber_t run, edm::LuminosityBlockNumber_t lumi)
Go to event by Run &amp; LuminosityBlock number.
boost::shared_ptr< fwlite::Run > run_
edm::LuminosityBlockAuxiliary aux_
ProcessHistoryID const & processHistoryID() const
virtual std::string const getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const
ProcessHistoryRegistry::collection_type ProcessHistoryMap
LuminosityBlock(TFile *iFile)
std::string const & luminosityBlockTreeName()
Definition: BranchType.cc:265
edm::LuminosityBlockAux * pOldAux_
unsigned int LuminosityBlockNumber_t
Definition: EventID.h:31
std::vector< char const * > labels_
boost::shared_ptr< RunFactory > runFactory_
edm::WrapperHolder getByProductID(edm::ProductID const &) const
virtual bool atEnd() const
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:192
Long64_t size() const
edm::IndexIntoFile::EntryNumber_t EntryNumber_t
Definition: EntryFinder.h:34
virtual std::string const getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const
fwlite::Run const & getRun() const
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
edm::LuminosityBlockAuxiliary * pAux_
std::vector< std::string > procHistoryNames_
RunNumber_t run() const
ProcessHistoryRegistry::vector_type ProcessHistoryVector
void fillIndex(BranchMapReader const &branchMap)
Definition: EntryFinder.cc:108
std::string const & metaDataTreeName()
Definition: BranchType.cc:167
std::string className() const
Definition: TypeID.cc:51
const edm::ProcessHistory & history() const
const LuminosityBlock & operator++()
static EntryNumber_t const invalidEntry
Definition: EntryFinder.h:40
std::string const & processHistoryBranchName()
Definition: BranchType.cc:197
void updateAux(Long_t lumiIndex) const
void conversion(EventAux const &from, EventAuxiliary &to)
Definition: EventAux.cc:9
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *) const
double b
Definition: hdecay.h:120
edm::ProcessHistoryMap historyMap_
const LuminosityBlock & toBegin()
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *, Long_t) const
unsigned int RunNumber_t
Definition: EventRange.h:32
virtual edm::LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
edm::WrapperHolder getByProductID(edm::ProductID const &, Long_t) const
boost::shared_ptr< BranchMapReader > branchMap_
EntryNumber_t findLumi(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi) const
Definition: EntryFinder.cc:74