CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TFWLiteSelectorBasic.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 //
4 // Package: TFWLiteSelector
5 // Class : TFWLiteSelectorBasic
6 //
7 // Implementation:
8 // <Notes on implementation>
9 //
10 // Original Author: Chris Jones
11 // Created: Tue Jun 27 17:58:10 EDT 2006
12 //
13 
14 // user include files
16 
26 #include "DataFormats/Provenance/interface/EventEntryDescription.h" // kludge to allow compilation
48 
49 // system include files
50 #include "TBranch.h"
51 #include "TChain.h"
52 #include "TFile.h"
53 #include "TTree.h"
54 
55 namespace edm {
56  namespace root {
58  public:
60  void setEntry(Long64_t iEntry) { entry_ = iEntry; }
61  void setTree(TTree* iTree) {eventTree_ = iTree;}
62  void set(boost::shared_ptr<ProductRegistry const> iReg) { reg_ = iReg;}
63  private:
65  virtual WrapperOwningHolder getProduct_(BranchKey const& k, WrapperInterfaceBase const* interface, EDProductGetter const* ep) const override;
66  virtual std::auto_ptr<EventEntryDescription> getProvenance_(BranchKey const&) const {
67  return std::auto_ptr<EventEntryDescription>();
68  }
69  virtual void mergeReaders_(DelayedReader*) override {}
70  virtual void reset_() override {}
71  Long64_t entry_;
72  TTree* eventTree_;
73  boost::shared_ptr<ProductRegistry const>(reg_);
74  };
75 
77  FWLiteDelayedReader::getProduct_(BranchKey const& k, WrapperInterfaceBase const* /*interface*/, EDProductGetter const* /*ep*/) const {
78  return getTheProduct(k);
79  }
80 
83  ProductRegistry::ProductList::const_iterator itFind= reg_->productList().find(k);
84  if(itFind == reg_->productList().end()) {
85  throw Exception(errors::ProductNotFound) << "could not find entry for product " << k;
86  }
87  BranchDescription const& bDesc = itFind->second;
88 
89  TBranch* branch= eventTree_->GetBranch(bDesc.branchName().c_str());
90  if(nullptr == branch) {
91  throw cms::Exception("MissingBranch")
92  << "could not find branch named '" << bDesc.branchName() << "'"
93  << "\n Perhaps the data being requested was not saved in this file?";
94  }
95  //find the class type
97  TypeWithDict classType = TypeWithDict::byName(fullName);
98  if(!bool(classType)) {
99  throw cms::Exception("MissingDictionary")
100  << "could not find dictionary for type '" << fullName << "'"
101  << "\n Please make sure all the necessary libraries are available.";
102  }
103 
104  //create an instance of it
105  void const* address = classType.construct().address();
106  if(nullptr == address) {
107  throw cms::Exception("FailedToCreate") << "could not create an instance of '" << fullName << "'";
108  }
109  branch->SetAddress(&address);
110 
111  branch->GetEntry(entry_);
112  return WrapperOwningHolder(address, bDesc.getInterface());
113  }
114 
117  tree_(nullptr),
118  reg_(new ProductRegistry()),
121  processNames_(),
123  prov_(),
126  reader_->set(reg_);
127  }
128  void setTree(TTree* iTree) {
129  tree_ = iTree;
130  reader_->setTree(iTree);
131  }
132  TTree* tree_;
133  boost::shared_ptr<ProductRegistry> reg_;
134  boost::shared_ptr<ProcessHistoryRegistry> phreg_;
135  boost::shared_ptr<BranchIDListHelper> branchIDListHelper_;
137  boost::shared_ptr<FWLiteDelayedReader> reader_;
138  std::vector<EventEntryDescription> prov_;
139  std::vector<EventEntryDescription*> pointerToBranchBuffer_;
141 
142  boost::shared_ptr<edm::ProductProvenanceRetriever> provRetriever_;
144  boost::shared_ptr<edm::EventPrincipal> ep_;
146  };
147  }
148 }
149 
150 
151 //
152 // constants, enums and typedefs
153 //
154 
155 //
156 // static data member definitions
157 //
158 
159 //
160 // constructors and destructor
161 //
162 TFWLiteSelectorBasic::TFWLiteSelectorBasic() : m_(new edm::root::TFWLiteSelectorMembers),
163  everythingOK_(false) {
164 }
165 
166 // TFWLiteSelectorBasic::TFWLiteSelectorBasic(TFWLiteSelectorBasic const& rhs)
167 // {
168 // // do actual copying here;
169 // }
170 
172 }
173 
174 //
175 // assignment operators
176 //
177 // TFWLiteSelectorBasic const& TFWLiteSelectorBasic::operator=(TFWLiteSelectorBasic const& rhs)
178 // {
179 // //An exception safe implementation is
180 // TFWLiteSelectorBasic temp(rhs);
181 // swap(rhs);
182 //
183 // return *this;
184 // }
185 
186 //
187 // member functions
188 //
189 void
191  Init(iTree);
192  begin(fInput);
193 }
194 
195 void
197  Init(iTree);
198  preProcessing(fInput, *fOutput);
199 }
200 
201 void
203  if(iTree == nullptr) return;
204  m_->setTree(iTree);
205 }
206 
207 
208 Bool_t
210  //std::cout << "Notify start" << std::endl;
211  //we have switched to a new file
212  //get new file from Tree
213  if(nullptr == m_->tree_) {
214  std::cout << "No tree" << std::endl;
215  return kFALSE;
216  }
217  TFile* file = m_->tree_->GetCurrentFile();
218  if(nullptr == file) {
219  //When in Rome, do as the Romans
220  TChain* chain = dynamic_cast<TChain*>(m_->tree_);
221  if(nullptr == chain) {
222  std::cout << "No file" << std::endl;
223  return kFALSE;
224  }
225  file = chain->GetFile();
226  if(nullptr == file) {
227  std::cout << "No file" << std::endl;
228  return kFALSE;
229  }
230  }
231  setupNewFile(*file);
232  return everythingOK_ ? kTRUE: kFALSE;
233 }
234 
235 namespace {
236  struct Operate {
237  Operate(edm::EDProductGetter const* iGetter): old_(setRefCoreStreamer(iGetter)) {
238  }
239 
240  ~Operate() {setRefCoreStreamer(old_);}
241  private:
242  edm::EDProductGetter const* old_;
243  };
244 }
245 
246 Bool_t
248  //std::cout << "Process start" << std::endl;
249  if(everythingOK_) {
250  std::auto_ptr<edm::EventAuxiliary> eaux(new edm::EventAuxiliary());
251  edm::EventAuxiliary& aux = *eaux;
252  edm::EventAuxiliary* pAux= eaux.get();
253  TBranch* branch = m_->tree_->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InEvent).c_str());
254 
255  branch->SetAddress(&pAux);
256  branch->GetEntry(iEntry);
257 
258 //NEW m_->processNames_ = aux.processHistory();
259 
260 // std::cout << "ProcessNames\n";
261 // for(auto const& name : m_->processNames_) {
262 // std::cout << " " << name << std::endl;
263 // }
264 
265  edm::EventSelectionIDVector eventSelectionIDs;
266  edm::EventSelectionIDVector* pEventSelectionIDVector = &eventSelectionIDs;
267  TBranch* eventSelectionsBranch = m_->tree_->GetBranch(edm::poolNames::eventSelectionsBranchName().c_str());
268  if(!eventSelectionsBranch) {
270  << "Failed to find event Selections branch in event tree";
271  }
272  eventSelectionsBranch->SetAddress(&pEventSelectionIDVector);
273  eventSelectionsBranch->GetEntry(iEntry);
274 
275  edm::BranchListIndexes branchListIndexes;
276  edm::BranchListIndexes* pBranchListIndexes = &branchListIndexes;
277  TBranch* branchListIndexBranch = m_->tree_->GetBranch(edm::poolNames::branchListIndexesBranchName().c_str());
278  if(!branchListIndexBranch) {
280  << "Failed to find branch list index branch in event tree";
281  }
282  branchListIndexBranch->SetAddress(&pBranchListIndexes);
283  branchListIndexBranch->GetEntry(iEntry);
284  m_->branchIDListHelper_->fixBranchListIndexes(branchListIndexes);
285 
286  try {
287  m_->reader_->setEntry(iEntry);
288  boost::shared_ptr<edm::RunAuxiliary> runAux(new edm::RunAuxiliary(aux.run(), aux.time(), aux.time()));
289  boost::shared_ptr<edm::RunPrincipal> rp(new edm::RunPrincipal(runAux, m_->reg_, m_->pc_, nullptr, 0));
290  boost::shared_ptr<edm::LuminosityBlockAuxiliary> lumiAux(
291  new edm::LuminosityBlockAuxiliary(rp->run(), 1, aux.time(), aux.time()));
292  boost::shared_ptr<edm::LuminosityBlockPrincipal>lbp(
293  new edm::LuminosityBlockPrincipal(lumiAux, m_->reg_, m_->pc_, nullptr, 0));
294  m_->ep_->fillEventPrincipal(*eaux,
295  *m_->phreg_,
296  std::move(eventSelectionIDs),
297  std::move(branchListIndexes),
298  *(m_->provRetriever_),
299  m_->reader_.get());
300  lbp->setRunPrincipal(rp);
301  m_->ep_->setLuminosityBlockPrincipal(lbp);
302  m_->processNames_ = m_->ep_->processHistory();
303 
304  edm::Event event(*m_->ep_, m_->md_, nullptr);
305 
306  //Make the event principal accessible to edm::Ref's
307  Operate sentry(m_->ep_->prodGetter());
308  process(event);
309  } catch(std::exception const& iEx) {
310  std::cout << "While processing entry " << iEntry << " the following exception was caught \n"
311  << iEx.what() << std::endl;
312  } catch(...) {
313  std::cout << "While processing entry " << iEntry << " an unknown exception was caught" << std::endl;
314  }
315  }
316  return everythingOK_ ? kTRUE: kFALSE;
317 }
318 
319 void
321  postProcessing(*fOutput);
322 }
323 
324 void
326  terminate(*fOutput);
327 }
328 
329 void
331  //look up meta-data
332  //get product registry
333 
334  //std::vector<edm::EventProcessHistoryID> eventProcessHistoryIDs_;
335  TTree* metaDataTree = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::metaDataTreeName().c_str()));
336  if(!metaDataTree) {
337  std::cout << "could not find TTree " << edm::poolNames::metaDataTreeName() << std::endl;
338  everythingOK_ = false;
339  return;
340  }
341  edm::FileFormatVersion* fftPtr = &(m_->fileFormatVersion_);
342  if(metaDataTree->FindBranch(edm::poolNames::fileFormatVersionBranchName().c_str()) != nullptr) {
343  metaDataTree->SetBranchAddress(edm::poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
344  }
345 
346 
347  edm::ProductRegistry* pReg = &(*m_->reg_);
348  metaDataTree->SetBranchAddress(edm::poolNames::productDescriptionBranchName().c_str(), &(pReg));
349 
350  typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> PsetMap;
351  PsetMap psetMap;
352  PsetMap *psetMapPtr = &psetMap;
353  if(metaDataTree->FindBranch(edm::poolNames::parameterSetMapBranchName().c_str()) != nullptr) {
354  metaDataTree->SetBranchAddress(edm::poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
355  } else {
356  TTree* psetTree = dynamic_cast<TTree *>(iFile.Get(edm::poolNames::parameterSetsTreeName().c_str()));
357  if(nullptr == psetTree) {
359  << " in the input file.\n";
360  }
361  typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
362  IdToBlobs idToBlob;
363  IdToBlobs* pIdToBlob = &idToBlob;
364  psetTree->SetBranchAddress(edm::poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
365  for(long long i = 0; i != psetTree->GetEntries(); ++i) {
366  psetTree->GetEntry(i);
367  psetMap.insert(idToBlob);
368  }
369  }
370 
372  edm::ProcessHistoryRegistry::vector_type *pHistVectorPtr = &pHistVector;
373  if(metaDataTree->FindBranch(edm::poolNames::processHistoryBranchName().c_str()) != nullptr) {
374  metaDataTree->SetBranchAddress(edm::poolNames::processHistoryBranchName().c_str(), &pHistVectorPtr);
375  }
376 
377 
378  edm::ProcessConfigurationVector procConfigVector;
379  edm::ProcessConfigurationVector* procConfigVectorPtr = &procConfigVector;
380  if(metaDataTree->FindBranch(edm::poolNames::processConfigurationBranchName().c_str()) != nullptr) {
381  metaDataTree->SetBranchAddress(edm::poolNames::processConfigurationBranchName().c_str(), &procConfigVectorPtr);
382  }
383 
384  boost::shared_ptr<edm::BranchIDListHelper> branchIDListsHelper(new edm::BranchIDListHelper);
385  edm::BranchIDLists const* branchIDListsPtr = &branchIDListsHelper->branchIDLists();
386  if(metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != nullptr) {
387  metaDataTree->SetBranchAddress(edm::poolNames::branchIDListBranchName().c_str(), &branchIDListsPtr);
388  }
389 
390  metaDataTree->GetEntry(0);
391 
392  for(auto& prod : m_->reg_->productListUpdator()) {
393  prod.second.init();
394  }
395 
396  // Merge into the registries. For now, we do NOT merge the product registry.
398  for(auto const& entry : psetMap) {
399  edm::ParameterSet pset(entry.second.pset());
400  pset.setID(entry.first);
401  psetRegistry.insertMapped(pset);
402  }
403 
404  for(auto const& ph : pHistVector) {
405  m_->phreg_->registerProcessHistory(ph);
406  }
407 
408  m_->pointerToBranchBuffer_.erase(m_->pointerToBranchBuffer_.begin(),
409  m_->pointerToBranchBuffer_.end());
410 
411  std::auto_ptr<edm::ProductRegistry> newReg(new edm::ProductRegistry());
412 
413  edm::ProductRegistry::ProductList& prodList = m_->reg_->productListUpdator();
414  {
415  for(auto& item : prodList) {
416  edm::BranchDescription& prod = item.second;
417  //std::cout << "productname = " << item.second << " end " << std::endl;
418  std::string newFriendlyName = edm::friendlyname::friendlyName(prod.className());
419  if(newFriendlyName == prod.friendlyClassName()) {
420  newReg->copyProduct(prod);
421  } else {
422  if(m_->fileFormatVersion_.splitProductIDs()) {
424  << "Cannot change friendly class name algorithm without more development work\n"
425  << "to update BranchIDLists. Contact the framework group.\n";
426  }
427  edm::BranchDescription newBD(prod);
428  newBD.updateFriendlyClassName();
429  newReg->copyProduct(newBD);
430  }
431  prod.init();
432  }
433 
434  m_->reg_.reset(newReg.release());
435  }
436 
437  edm::ProductRegistry::ProductList& prodList2 = m_->reg_->productListUpdator();
438  std::vector<edm::EventEntryDescription> temp(prodList2.size(), edm::EventEntryDescription());
439  m_->prov_.swap(temp);
440  std::vector<edm::EventEntryDescription>::iterator itB = m_->prov_.begin();
441  m_->pointerToBranchBuffer_.reserve(prodList2.size());
442 
443  for(auto& item : prodList2) {
444  edm::BranchDescription& prod = item.second;
445  if(prod.branchType() == edm::InEvent) {
446  prod.init();
447  //NEED to do this and check to see if branch exists
448  if(m_->tree_->GetBranch(prod.branchName().c_str()) == nullptr) {
449  prod.setDropped(true);
450  }
451 
452  //std::cout << "id " << it->first << " branch " << it->second << std::endl;
453  //m_->pointerToBranchBuffer_.push_back(&(*itB));
454  //void* tmp = &(m_->pointerToBranchBuffer_.back());
455  //edm::EventEntryDescription* tmp = &(*itB);
456  //CDJ need to fix provenance and be backwards compatible, for now just don't read the branch
457  //m_->metaTree_->SetBranchAddress(prod.branchName().c_str(), tmp);
458  }
459  }
460  m_->branchIDListHelper_->updateFromInput(*branchIDListsPtr);
461  m_->reg_->setFrozen();
462  m_->ep_.reset(new edm::EventPrincipal(m_->reg_, m_->branchIDListHelper_, m_->pc_, nullptr));
463  everythingOK_ = true;
464 }
465 
466 //
467 // const member functions
468 //
469 
470 //
471 // static member functions
472 //
void setID(ParameterSetID const &id)
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:249
virtual void terminate(TList &out)=0
std::vector< ProcessConfiguration > ProcessConfigurationVector
virtual void mergeReaders_(DelayedReader *) override
int i
Definition: DBlmapReader.cc:9
std::string const & branchName() const
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:114
BranchType const & branchType() const
static TypeWithDict byName(std::string const &className)
std::vector< BranchIDList > BranchIDLists
Definition: BranchIDList.h:19
boost::shared_ptr< BranchIDListHelper > branchIDListHelper_
std::vector< EventEntryDescription * > pointerToBranchBuffer_
virtual void preProcessing(const TList *in, TList &out)=0
std::vector< EventEntryDescription > prov_
std::map< BranchKey, BranchDescription > ProductList
virtual std::auto_ptr< EventEntryDescription > getProvenance_(BranchKey const &) const
virtual Bool_t Process(Long64_t)
#define nullptr
boost::shared_ptr< ProductRegistry > reg_
Timestamp const & time() const
RunNumber_t run() const
void setRefCoreStreamer(bool resetAll=false)
virtual void SlaveBegin(TTree *)
std::string const & fileFormatVersionBranchName()
Definition: BranchType.cc:212
virtual void postProcessing(TList &out)=0
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:237
WrapperOwningHolder getTheProduct(BranchKey const &k) const
boost::shared_ptr< edm::EventPrincipal > ep_
virtual void process(const edm::Event &event)=0
std::vector< EventSelectionID > EventSelectionIDVector
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:245
virtual WrapperOwningHolder getProduct_(BranchKey const &k, WrapperInterfaceBase const *interface, EDProductGetter const *ep) const override
std::vector< BranchListIndex > BranchListIndexes
std::string const & className() const
std::string friendlyName(std::string const &iFullName)
boost::shared_ptr< edm::ProductProvenanceRetriever > provRetriever_
std::string const & friendlyClassName() const
WrapperInterfaceBase const * getInterface() const
void setDropped(bool isDropped)
std::string const & metaDataTreeName()
Definition: BranchType.cc:167
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
std::string const & parameterSetMapBranchName()
Definition: BranchType.cc:182
std::string const & processHistoryBranchName()
Definition: BranchType.cc:197
boost::shared_ptr< edm::root::TFWLiteSelectorMembers > m_
int k[5][pyjets_maxn]
string fullName
void set(boost::shared_ptr< ProductRegistry const > iReg)
std::string wrappedClassName(std::string const &iFullName)
virtual void Init(TTree *)
boost::shared_ptr< ProcessHistoryRegistry > phreg_
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:172
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:202
boost::shared_ptr< FWLiteDelayedReader > reader_
tuple cout
Definition: gather_cfg.py:121
std::string const & branchIDListBranchName()
Definition: BranchType.cc:207
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:241
volatile std::atomic< bool > shutdown_flag false
virtual void Begin(TTree *)
bool insertMapped(value_type const &v)
Definition: Registry.cc:37
static Registry * instance()
Definition: Registry.cc:14
virtual void begin(TList *&in)=0
string root
initialization
Definition: dbtoconf.py:70