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
47 
48 // system include files
49 #include "TBranch.h"
50 #include "TChain.h"
51 #include "TFile.h"
52 #include "TTree.h"
53 #include "Reflex/Type.h"
54 
55 namespace edm {
56  namespace root {
58  public:
59  FWLiteDelayedReader() : entry_(-1), eventTree_(0), reg_() {}
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:
64  virtual WrapperOwningHolder getProduct_(BranchKey const& k, WrapperInterfaceBase const* interface, EDProductGetter const* ep) const;
65  virtual std::auto_ptr<EventEntryDescription> getProvenance_(BranchKey const&) const {
66  return std::auto_ptr<EventEntryDescription>();
67  }
68  virtual void mergeReaders_(DelayedReader*) {}
69  virtual void reset_() {}
70  Long64_t entry_;
71  TTree* eventTree_;
72  boost::shared_ptr<ProductRegistry const>(reg_);
73  };
74 
76  FWLiteDelayedReader::getProduct_(BranchKey const& k, WrapperInterfaceBase const* /*interface*/, EDProductGetter const* /*ep*/) const {
77  ProductRegistry::ProductList::const_iterator itFind= reg_->productList().find(k);
78  if(itFind == reg_->productList().end()) {
79  throw Exception(errors::ProductNotFound) << "could not find entry for product " << k;
80  }
81  BranchDescription const& bDesc = itFind->second;
82 
83  TBranch* branch= eventTree_->GetBranch(bDesc.branchName().c_str());
84  if(0 == branch) {
85  throw cms::Exception("MissingBranch")
86  << "could not find branch named '" << bDesc.branchName() << "'"
87  << "\n Perhaps the data being requested was not saved in this file?";
88  }
89  //find the class type
90  std::string const fullName = wrappedClassName(bDesc.className());
91  Reflex::Type classType = Reflex::Type::ByName(fullName);
92  if(classType == Reflex::Type()) {
93  throw cms::Exception("MissingDictionary")
94  << "could not find dictionary for type '" << fullName << "'"
95  << "\n Please make sure all the necessary libraries are available.";
96  }
97 
98  //use reflex to create an instance of it
99  Reflex::Object wrapperObj = classType.Construct();
100  if(0 == wrapperObj.Address()) {
101  throw cms::Exception("FailedToCreate") << "could not create an instance of '" << fullName << "'";
102  }
103  void* address = wrapperObj.Address();
104  branch->SetAddress(&address);
105 
106 
107  branch->GetEntry(entry_);
108  return WrapperOwningHolder(address, bDesc.getInterface());
109  }
110 
113  tree_(0),
114  reg_(new ProductRegistry()),
115  processNames_(),
117  prov_(),
119  mapper_(new edm::BranchMapper) {
120  reader_->set(reg_);
121  }
122  void setTree(TTree* iTree) {
123  tree_ = iTree;
124  reader_->setTree(iTree);
125  }
126  TTree* tree_;
127  boost::shared_ptr<ProductRegistry> reg_;
129  boost::shared_ptr<FWLiteDelayedReader> reader_;
130  std::vector<EventEntryDescription> prov_;
131  std::vector<EventEntryDescription*> pointerToBranchBuffer_;
133 
134  boost::shared_ptr<edm::BranchMapper> mapper_;
136  boost::shared_ptr<edm::EventPrincipal> ep_;
138  };
139  }
140 }
141 
142 
143 //
144 // constants, enums and typedefs
145 //
146 
147 //
148 // static data member definitions
149 //
150 
151 //
152 // constructors and destructor
153 //
154 TFWLiteSelectorBasic::TFWLiteSelectorBasic() : m_(new edm::root::TFWLiteSelectorMembers),
155  everythingOK_(false) {
156 }
157 
158 // TFWLiteSelectorBasic::TFWLiteSelectorBasic(TFWLiteSelectorBasic const& rhs)
159 // {
160 // // do actual copying here;
161 // }
162 
164 }
165 
166 //
167 // assignment operators
168 //
169 // TFWLiteSelectorBasic const& TFWLiteSelectorBasic::operator=(TFWLiteSelectorBasic const& rhs)
170 // {
171 // //An exception safe implementation is
172 // TFWLiteSelectorBasic temp(rhs);
173 // swap(rhs);
174 //
175 // return *this;
176 // }
177 
178 //
179 // member functions
180 //
181 void
183  Init(iTree);
184  begin(fInput);
185 }
186 
187 void
189  Init(iTree);
190  preProcessing(fInput, *fOutput);
191 }
192 
193 void
195  if(iTree == 0) return;
196  m_->setTree(iTree);
197 }
198 
199 
200 Bool_t
202  //std::cout << "Notify start" << std::endl;
203  //we have switched to a new file
204  //get new file from Tree
205  if(0 == m_->tree_) {
206  std::cout << "No tree" << std::endl;
207  return kFALSE;
208  }
209  TFile* file = m_->tree_->GetCurrentFile();
210  if(0 == file) {
211  //When in Rome, do as the Romans
212  TChain* chain = dynamic_cast<TChain*>(m_->tree_);
213  if(0 == chain) {
214  std::cout << "No file" << std::endl;
215  return kFALSE;
216  }
217  file = chain->GetFile();
218  if(0 == file) {
219  std::cout << "No file" << std::endl;
220  return kFALSE;
221  }
222  }
223  setupNewFile(*file);
224  return everythingOK_ ? kTRUE: kFALSE;
225 }
226 
227 namespace {
228  struct Operate {
229  Operate(edm::EDProductGetter const* iGetter): old_(setRefCoreStreamer(iGetter)) {
230  }
231 
232  ~Operate() {setRefCoreStreamer(old_);}
233  private:
234  edm::EDProductGetter const* old_;
235  };
236 }
237 
238 Bool_t
240  //std::cout << "Process start" << std::endl;
241  if(everythingOK_) {
242  std::auto_ptr<edm::EventAuxiliary> eaux(new edm::EventAuxiliary());
243  edm::EventAuxiliary& aux = *eaux;
244  edm::EventAuxiliary* pAux= eaux.get();
245  TBranch* branch = m_->tree_->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InEvent).c_str());
246 
247  branch->SetAddress(&pAux);
248  branch->GetEntry(iEntry);
249 
250 //NEW m_->processNames_ = aux.processHistory();
251 
252 // std::cout << "ProcessNames\n";
253 // for(edm::ProcessNameList::const_iterator itName = m_->processNames_.begin(),
254 // itNameEnd = m_->processNames_.end();
255 // itName != itNameEnd;
256 // ++itName) {
257 // std::cout << " " << *itName << std::endl;
258 // }
259 
260  boost::shared_ptr<edm::EventSelectionIDVector> eventSelectionIDs_(new edm::EventSelectionIDVector);
261  edm::EventSelectionIDVector* pEventSelectionIDVector = eventSelectionIDs_.get();
262  TBranch* eventSelectionsBranch = m_->tree_->GetBranch(edm::poolNames::eventSelectionsBranchName().c_str());
263  if(!eventSelectionsBranch) {
265  << "Failed to find event Selections branch in event tree";
266  }
267  eventSelectionsBranch->SetAddress(&pEventSelectionIDVector);
268  eventSelectionsBranch->GetEntry(iEntry);
269 
270  boost::shared_ptr<edm::BranchListIndexes> branchListIndexes_(new edm::BranchListIndexes);
271  edm::BranchListIndexes* pBranchListIndexes = branchListIndexes_.get();
272  TBranch* branchListIndexBranch = m_->tree_->GetBranch(edm::poolNames::branchListIndexesBranchName().c_str());
273  if(!branchListIndexBranch) {
275  << "Failed to find branch list index branch in event tree";
276  }
277  branchListIndexBranch->SetAddress(&pBranchListIndexes);
278  branchListIndexBranch->GetEntry(iEntry);
280 
281  try {
282  m_->reader_->setEntry(iEntry);
283  boost::shared_ptr<edm::RunAuxiliary> runAux(new edm::RunAuxiliary(aux.run(), aux.time(), aux.time()));
284  boost::shared_ptr<edm::RunPrincipal> rp(new edm::RunPrincipal(runAux, m_->reg_, m_->pc_));
285  boost::shared_ptr<edm::LuminosityBlockAuxiliary> lumiAux(
286  new edm::LuminosityBlockAuxiliary(rp->run(), 1, aux.time(), aux.time()));
287  boost::shared_ptr<edm::LuminosityBlockPrincipal>lbp(
288  new edm::LuminosityBlockPrincipal(lumiAux, m_->reg_, m_->pc_, rp));
289  m_->ep_->fillEventPrincipal(*eaux, lbp, eventSelectionIDs_, branchListIndexes_, m_->mapper_, m_->reader_.get());
290  m_->processNames_ = m_->ep_->processHistory();
291 
292  edm::Event event(*m_->ep_, m_->md_);
293 
294  //Make the event principal accessible to edm::Ref's
295  Operate sentry(m_->ep_->prodGetter());
296  process(event);
297  } catch(std::exception const& iEx) {
298  std::cout << "While processing entry " << iEntry << " the following exception was caught \n"
299  << iEx.what() << std::endl;
300  } catch(...) {
301  std::cout << "While processing entry " << iEntry << " an unknown exception was caught" << std::endl;
302  }
303  }
304  return everythingOK_ ? kTRUE: kFALSE;
305 }
306 
307 void
309  postProcessing(*fOutput);
310 }
311 
312 void
314  terminate(*fOutput);
315 }
316 
317 void
319  //look up meta-data
320  //get product registry
321 
322  //std::vector<edm::EventProcessHistoryID> eventProcessHistoryIDs_;
323  TTree* metaDataTree = dynamic_cast<TTree*>(iFile.Get(edm::poolNames::metaDataTreeName().c_str()));
324  if(!metaDataTree) {
325  std::cout << "could not find TTree " << edm::poolNames::metaDataTreeName() << std::endl;
326  everythingOK_ = false;
327  return;
328  }
329  edm::FileFormatVersion* fftPtr = &(m_->fileFormatVersion_);
330  if(metaDataTree->FindBranch(edm::poolNames::fileFormatVersionBranchName().c_str()) != 0) {
331  metaDataTree->SetBranchAddress(edm::poolNames::fileFormatVersionBranchName().c_str(), &fftPtr);
332  }
333 
334 
335  edm::ProductRegistry* pReg = &(*m_->reg_);
336  metaDataTree->SetBranchAddress(edm::poolNames::productDescriptionBranchName().c_str(), &(pReg));
337 
338  m_->reg_->setFrozen();
339 
340  typedef std::map<edm::ParameterSetID, edm::ParameterSetBlob> PsetMap;
341  PsetMap psetMap;
342  PsetMap *psetMapPtr = &psetMap;
343  if(metaDataTree->FindBranch(edm::poolNames::parameterSetMapBranchName().c_str()) != 0) {
344  metaDataTree->SetBranchAddress(edm::poolNames::parameterSetMapBranchName().c_str(), &psetMapPtr);
345  } else {
346  TTree* psetTree = dynamic_cast<TTree *>(iFile.Get(edm::poolNames::parameterSetsTreeName().c_str()));
347  if(0 == psetTree) {
349  << " in the input file.\n";
350  }
351  typedef std::pair<edm::ParameterSetID, edm::ParameterSetBlob> IdToBlobs;
352  IdToBlobs idToBlob;
353  IdToBlobs* pIdToBlob = &idToBlob;
354  psetTree->SetBranchAddress(edm::poolNames::idToParameterSetBlobsBranchName().c_str(), &pIdToBlob);
355  for(long long i = 0; i != psetTree->GetEntries(); ++i) {
356  psetTree->GetEntry(i);
357  psetMap.insert(idToBlob);
358  }
359  }
360 
362  edm::ProcessHistoryRegistry::vector_type *pHistVectorPtr = &pHistVector;
363  if(metaDataTree->FindBranch(edm::poolNames::processHistoryBranchName().c_str()) != 0) {
364  metaDataTree->SetBranchAddress(edm::poolNames::processHistoryBranchName().c_str(), &pHistVectorPtr);
365  }
366 
367 
368  edm::ProcessConfigurationVector procConfigVector;
369  edm::ProcessConfigurationVector* procConfigVectorPtr = &procConfigVector;
370  if(metaDataTree->FindBranch(edm::poolNames::processConfigurationBranchName().c_str()) != 0) {
371  metaDataTree->SetBranchAddress(edm::poolNames::processConfigurationBranchName().c_str(), &procConfigVectorPtr);
372  }
373 
374  std::auto_ptr<edm::BranchIDListRegistry::collection_type> branchIDListsAPtr(new edm::BranchIDListRegistry::collection_type);
375  edm::BranchIDListRegistry::collection_type *branchIDListsPtr = branchIDListsAPtr.get();
376  if(metaDataTree->FindBranch(edm::poolNames::branchIDListBranchName().c_str()) != 0) {
377  metaDataTree->SetBranchAddress(edm::poolNames::branchIDListBranchName().c_str(), &branchIDListsPtr);
378  }
379 
380  metaDataTree->GetEntry(0);
381 
382  // Merge into the registries. For now, we do NOT merge the product registry.
384  for(PsetMap::const_iterator i = psetMap.begin(), iEnd = psetMap.end();
385  i != iEnd; ++i) {
386  edm::ParameterSet pset(i->second.pset());
387  pset.setID(i->first);
388  psetRegistry.insertMapped(pset);
389  }
390 
393 
394  m_->pointerToBranchBuffer_.erase(m_->pointerToBranchBuffer_.begin(),
395  m_->pointerToBranchBuffer_.end());
396 
397  fillProductRegistryTransients(procConfigVector, *m_->reg_);
398  std::auto_ptr<edm::ProductRegistry> newReg(new edm::ProductRegistry());
399 
400  edm::ProductRegistry::ProductList const& prodList = m_->reg_->productList();
401  {
402  for(edm::ProductRegistry::ProductList::const_iterator it = prodList.begin(), itEnd = prodList.end();
403  it != itEnd; ++it) {
404  edm::BranchDescription const& prod = it->second;
405  //std::cout << "productname = " << it->second << " end " << std::endl;
406  std::string newFriendlyName = edm::friendlyname::friendlyName(prod.className());
407  if(newFriendlyName == prod.friendlyClassName()) {
408  newReg->copyProduct(prod);
409  } else {
410  if(m_->fileFormatVersion_.splitProductIDs()) {
412  << "Cannot change friendly class name algorithm without more development work\n"
413  << "to update BranchIDLists. Contact the framework group.\n";
414  }
415  edm::BranchDescription newBD(prod);
416  newBD.updateFriendlyClassName();
417  newReg->copyProduct(newBD);
418  // Need to call init to get old branch name.
419  prod.init();
420  }
421  }
422 
423  newReg->setFrozen();
424  m_->reg_.reset(newReg.release());
425  }
426 
427  edm::ProductRegistry::ProductList const& prodList2 = m_->reg_->productList();
428  std::vector<edm::EventEntryDescription> temp(prodList2.size(), edm::EventEntryDescription());
429  m_->prov_.swap(temp);
430  std::vector<edm::EventEntryDescription>::iterator itB = m_->prov_.begin();
431  m_->pointerToBranchBuffer_.reserve(prodList2.size());
432 
433  for(edm::ProductRegistry::ProductList::const_iterator it = prodList2.begin(), itEnd = prodList2.end();
434  it != itEnd; ++it, ++itB) {
435  edm::BranchDescription const& prod = it->second;
436  if(prod.branchType() == edm::InEvent) {
437  prod.init();
438  //NEED to do this and check to see if branch exists
439  if(m_->tree_->GetBranch(prod.branchName().c_str()) == 0) {
440  prod.setDropped();
441  }
442 
443  //std::cout << "id " << it->first << " branch " << it->second << std::endl;
444  //m_->pointerToBranchBuffer_.push_back(&(*itB));
445  //void* tmp = &(m_->pointerToBranchBuffer_.back());
446  //edm::EventEntryDescription* tmp = &(*itB);
447  //CDJ need to fix provenance and be backwards compatible, for now just don't read the branch
448  //m_->metaTree_->SetBranchAddress(prod.branchName().c_str(), tmp);
449  }
450  }
451  edm::BranchIDListHelper::updateFromInput(*branchIDListsAPtr, "");
452  m_->ep_.reset(new edm::EventPrincipal(m_->reg_, m_->pc_));
453  everythingOK_ = true;
454 }
455 
456 //
457 // const member functions
458 //
459 
460 //
461 // static member functions
462 //
std::string const & idToParameterSetBlobsBranchName()
Definition: BranchType.cc:249
virtual void terminate(TList &out)=0
int i
Definition: DBlmapReader.cc:9
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:114
BranchType const & branchType() const
char * address
Definition: mlp_lapack.h:14
std::vector< EventEntryDescription * > pointerToBranchBuffer_
virtual void preProcessing(const TList *in, TList &out)=0
std::string & branchName() const
std::vector< EventEntryDescription > prov_
std::map< BranchKey, BranchDescription > ProductList
static bool updateFromInput(BranchIDLists const &bidlists, std::string const &fileName)
virtual std::auto_ptr< EventEntryDescription > getProvenance_(BranchKey const &) const
virtual Bool_t Process(Long64_t)
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
static ThreadSafeRegistry * instance()
virtual void postProcessing(TList &out)=0
std::string const & eventSelectionsBranchName()
Definition: BranchType.cc:237
boost::shared_ptr< edm::EventPrincipal > ep_
virtual void process(const edm::Event &event)=0
void fillProductRegistryTransients(std::vector< ProcessConfiguration > const &pcVec, ProductRegistry const &preg, bool okToRegister=false)
static void fixBranchListIndexes(BranchListIndexes &indexes)
std::vector< EventSelectionID > EventSelectionIDVector
std::string const & parameterSetsTreeName()
Definition: BranchType.cc:245
void setID(ParameterSetID const &id) const
ProcessConfigurationRegistry::vector_type ProcessConfigurationVector
std::vector< BranchListIndex > BranchListIndexes
std::string const & className() const
std::string friendlyName(std::string const &iFullName)
virtual void mergeReaders_(DelayedReader *)
std::string const & friendlyClassName() const
WrapperInterfaceBase const * getInterface() const
std::string const & metaDataTreeName()
Definition: BranchType.cc:167
void insertCollection(collection_type const &c)
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 *)
std::string const & productDescriptionBranchName()
Definition: BranchType.cc:172
std::string const & processConfigurationBranchName()
Definition: BranchType.cc:202
boost::shared_ptr< FWLiteDelayedReader > reader_
author Stefano ARGIRO author Bill Tanenbaum
std::vector< value_type > vector_type
tuple cout
Definition: gather_cfg.py:121
std::string const & branchIDListBranchName()
Definition: BranchType.cc:207
std::string const & branchListIndexesBranchName()
Definition: BranchType.cc:241
virtual void Begin(TTree *)
virtual WrapperOwningHolder getProduct_(BranchKey const &k, WrapperInterfaceBase const *interface, EDProductGetter const *ep) const
bool insertMapped(value_type const &v)
virtual void begin(TList *&in)=0
string root
initialization
Definition: dbtoconf.py:70
boost::shared_ptr< edm::BranchMapper > mapper_