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  std::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_ = std::shared_ptr<RunFactory>(new RunFactory());
89 }
90 
91  LuminosityBlock::LuminosityBlock(std::shared_ptr<BranchMapReader> branchMap, std::shared_ptr<RunFactory> runFactory):
92  branchMap_(branchMap),
93  pAux_(&aux_),
94  pOldAux_(0),
95  fileVersion_(-1),
96  dataHelper_(branchMap_->getLuminosityBlockTree(),
97  std::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 
237 {
238  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
239  updateAux(luminosityBlockIndex);
240  return aux_;
241 }
242 
243 void
244 LuminosityBlock::updateAux(Long_t luminosityBlockIndex) const
245 {
246  if(auxBranch_->GetEntryNumber() != luminosityBlockIndex) {
247  auxBranch_->GetEntry(luminosityBlockIndex);
248  //handling dealing with old version
249  if(0 != pOldAux_) {
251  }
252  }
253 }
254 
255 
256 const edm::ProcessHistory&
258 {
259  edm::ProcessHistoryID processHistoryID;
260 
261  bool newFormat = false;//(fileVersion_ >= 5);
262 
263  Long_t lumiIndex = branchMap_->getLuminosityBlockEntry();
264  updateAux(lumiIndex);
265  if (!newFormat) {
266  processHistoryID = aux_.processHistoryID();
267  }
268 
269  if(historyMap_.empty() || newFormat) {
270  procHistoryNames_.clear();
271  TTree *meta = dynamic_cast<TTree*>(branchMap_->getFile()->Get(edm::poolNames::metaDataTreeName().c_str()));
272  if(0==meta) {
273  throw cms::Exception("NoMetaTree")<<"The TFile does not appear to contain a TTree named "
275  }
276  if (historyMap_.empty()) {
277  if (fileVersion_ < 11) {
279  TBranch* b = meta->GetBranch(edm::poolNames::processHistoryMapBranchName().c_str());
280  b->SetAddress(&pPhm);
281  b->GetEntry(0);
282  } else {
283  edm::ProcessHistoryVector historyVector;
284  edm::ProcessHistoryVector* pPhv=&historyVector;
285  TBranch* b = meta->GetBranch(edm::poolNames::processHistoryBranchName().c_str());
286  b->SetAddress(&pPhv);
287  b->GetEntry(0);
288  for (auto& history : historyVector) {
289  historyMap_.insert(std::make_pair(history.setProcessHistoryID(), history));
290  }
291  }
292  }
293 // if (newFormat) {
294 // if (fileVersion_ >= 7) {
295 // edm::History history;
296 // edm::History* pHistory = &history;
297 // TBranch* eventHistoryBranch = eventHistoryTree_->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
298 // if (!eventHistoryBranch)
299 // throw edm::Exception(edm::errors::FatalRootError)
300 // << "Failed to find history branch in event history tree";
301 // eventHistoryBranch->SetAddress(&pHistory);
302 // eventHistoryTree_->GetEntry(lumiIndex);
303 // processHistoryID = history.processHistoryID();
304 // } else {
305 // std::vector<edm::EventProcessHistoryID> *pEventProcessHistoryIDs = &eventProcessHistoryIDs_;
306 // TBranch* b = meta->GetBranch(edm::poolNames::eventHistoryBranchName().c_str());
307 // b->SetAddress(&pEventProcessHistoryIDs);
308 // b->GetEntry(0);
309 // edm::EventProcessHistoryID target(aux_.id(), edm::ProcessHistoryID());
310 // processHistoryID = std::lower_bound(eventProcessHistoryIDs_.begin(), eventProcessHistoryIDs_.end(), target)->processHistoryID_;
311 // }
312 // }
313 
314  }
315  return historyMap_[processHistoryID];
316 }
317 
318 
319 edm::WrapperBase const*
321  Long_t luminosityBlockIndex = branchMap_->getLuminosityBlockEntry();
322  return dataHelper_.getByProductID(iID, luminosityBlockIndex);
323 }
324 
325 
326 //
327 // static member functions
328 //
329 void
330 LuminosityBlock::throwProductNotFoundException(std::type_info const& iType, char const* iModule, char const* iProduct, char const* iProcess)
331 {
332  edm::TypeID type(iType);
333  throw edm::Exception(edm::errors::ProductNotFound)<<"A branch was found for \n type ='"<<type.className()<<"'\n module='"<<iModule
334  <<"'\n productInstance='"<<((0!=iProduct)?iProduct:"")<<"'\n process='"<<((0!=iProcess)?iProcess:"")<<"'\n"
335  "but no data is available for this LuminosityBlock";
336 }
337 
338 
339 namespace {
340  struct NoDelete {
341  void operator()(void*){}
342  };
343 }
344 
346  run_ = runFactory_->makeRun(std::shared_ptr<BranchMapReader>(&*branchMap_,NoDelete()));
348  run_->to(run);
349  return *run_;
350 }
351 
352 }
std::vector< ProcessHistory > ProcessHistoryVector
type
Definition: HCALResponse.h:21
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:115
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.
edm::LuminosityBlockAuxiliary aux_
ProcessHistoryID const & processHistoryID() const
virtual std::string const getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const
edm::WrapperBase const * getByProductID(edm::ProductID const &) const
LuminosityBlock(TFile *iFile)
ProcessHistoryID setProcessHistoryID()
std::string const & luminosityBlockTreeName()
Definition: BranchType.cc:271
edm::LuminosityBlockAux * pOldAux_
unsigned int LuminosityBlockNumber_t
std::vector< char const * > labels_
virtual bool atEnd() const
std::string const & processHistoryMapBranchName()
Definition: BranchType.cc:193
Long64_t size() const
edm::WrapperBase const * getByProductID(edm::ProductID const &pid, Long_t eventEntry) 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::shared_ptr< fwlite::Run > run_
edm::LuminosityBlockAuxiliary * pAux_
std::vector< std::string > procHistoryNames_
RunNumber_t run() const
void fillIndex(BranchMapReader const &branchMap)
Definition: EntryFinder.cc:108
std::string const & metaDataTreeName()
Definition: BranchType.cc:168
const edm::ProcessHistory & history() const
const LuminosityBlock & operator++()
static EntryNumber_t const invalidEntry
Definition: EntryFinder.h:40
std::string const & processHistoryBranchName()
Definition: BranchType.cc:198
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
std::string const & className() const
Definition: TypeID.cc:46
std::shared_ptr< BranchMapReader > branchMap_
unsigned int RunNumber_t
virtual edm::LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const
std::shared_ptr< RunFactory > runFactory_
std::map< ProcessHistoryID, ProcessHistory > ProcessHistoryMap
EntryNumber_t findLumi(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi) const
Definition: EntryFinder.cc:74