CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
BareRootProductGetter Class Reference

#include <FWCore/FWLite/interface/BareRootProductGetter.h>

Inheritance diagram for BareRootProductGetter:
edm::EDProductGetter

Classes

struct  Buffer
 

Public Member Functions

 BareRootProductGetter ()
 
virtual edm::WrapperBase const * getIt (edm::ProductID const &) const override
 
virtual ~BareRootProductGetter ()
 
- Public Member Functions inherited from edm::EDProductGetter
 EDProductGetter ()
 
unsigned int transitionIndex () const
 
virtual ~EDProductGetter ()
 

Private Types

typedef std::map
< edm::ProductID, Buffer
IdToBuffers
 

Private Member Functions

 BareRootProductGetter (BareRootProductGetter const &)
 
BuffercreateNewBuffer (edm::ProductID const &) const
 
TBranch * findBranch (edm::ProductID const &) const
 
BareRootProductGetter const & operator= (BareRootProductGetter const &)
 
void setupNewFile (TFile *) const
 
virtual unsigned int transitionIndex_ () const override
 

Private Attributes

fwlite::BranchMapReader branchMap_
 
IdToBuffers idToBuffers_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDProductGetter
static void assignEDProductGetter (EDProductGetter const *&)
 
static EDProductGetter const * switchProductGetter (EDProductGetter const *)
 These can only be used internally by the framework. More...
 

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 35 of file BareRootProductGetter.h.

Member Typedef Documentation

Definition at line 81 of file BareRootProductGetter.h.

Constructor & Destructor Documentation

BareRootProductGetter::BareRootProductGetter ( )

Definition at line 41 of file BareRootProductGetter.cc.

41  {
42 }
BareRootProductGetter::~BareRootProductGetter ( )
virtual

Definition at line 48 of file BareRootProductGetter.cc.

48  {
49 }
BareRootProductGetter::BareRootProductGetter ( BareRootProductGetter const &  )
private

Member Function Documentation

BareRootProductGetter::Buffer * BareRootProductGetter::createNewBuffer ( edm::ProductID const &  iID) const
private

Definition at line 159 of file BareRootProductGetter.cc.

References b, branchMap_, edm::BranchDescription::branchName(), edm::TypeWithDict::byName(), edm::BranchDescription::className(), compareJSON::const, edm::hlt::Exception, newFWLiteAna::fullName, fwlite::BranchMapReader::getEventTree(), idToBuffers_, parseEventContent::prod, fwlite::BranchMapReader::productToBranch(), AlCaHLTBitMon_QueryRunRegistry::string, and edm::wrappedClassName().

Referenced by getIt().

159  {
160  //find the branch
162 
163  TBranch* branch= branchMap_.getEventTree()->GetBranch(bdesc.branchName().c_str());
164  if(nullptr == branch) {
165  //we do not thrown on missing branches since 'getIt' should not throw under that condition
166  return nullptr;
167  }
168  //find the class type
170  edm::TypeWithDict classType(edm::TypeWithDict::byName(fullName));
171  if(!bool(classType)) {
172  cms::Exception("MissingDictionary")
173  << "could not find dictionary for type '" << fullName << "'"
174  << "\n Please make sure all the necessary libraries are available.";
175  return nullptr;
176  }
177 
178  TClass* rootClassType = TClass::GetClass(classType.typeInfo());
179  if(nullptr == rootClassType) {
180  throw cms::Exception("MissingRootDictionary")
181  << "could not find a ROOT dictionary for type '" << fullName << "'"
182  << "\n Please make sure all the necessary libraries are available.";
183  return nullptr;
184  }
185  void* address = rootClassType->New();
186 
187  static TClass const* edproductTClass = TClass::GetClass(typeid(edm::WrapperBase));
188  edm::WrapperBase const* prod = reinterpret_cast<edm::WrapperBase const*>( rootClassType->DynamicCast(edproductTClass,address,true));
189  if(nullptr == prod) {
190  cms::Exception("FailedConversion")
191  << "failed to convert a '" << fullName
192  << "' to a edm::WrapperBase."
193  << "Please contact developers since something is very wrong.";
194  }
195 
196  //connect the instance to the branch
197  //void* address = wrapperObj.Address();
198  Buffer b(prod, branch, address, rootClassType);
199  idToBuffers_[iID] = b;
200 
201  //As of 5.13 ROOT expects the memory address held by the pointer passed to
202  // SetAddress to be valid forever
203  address = &(idToBuffers_[iID].address_);
204  branch->SetAddress(address);
205 
206  return &(idToBuffers_[iID]);
207 }
std::string const & branchName() const
static TypeWithDict byName(std::string const &className)
TTree * getEventTree() const
std::string const & className() const
const edm::BranchDescription & productToBranch(const edm::ProductID &pid)
string fullName
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
fwlite::BranchMapReader branchMap_
TBranch* BareRootProductGetter::findBranch ( edm::ProductID const &  ) const
private
edm::WrapperBase const * BareRootProductGetter::getIt ( edm::ProductID const &  iID) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 70 of file BareRootProductGetter.cc.

References BareRootProductGetter::Buffer::address_, BareRootProductGetter::Buffer::branch_, branchMap_, BareRootProductGetter::Buffer::class_, compareJSON::const, createNewBuffer(), BareRootProductGetter::Buffer::eventEntry_, edm::poolNames::eventTreeName(), edm::hlt::Exception, fwlite::BranchMapReader::getEventTree(), fwlite::BranchMapReader::getFile(), idToBuffers_, parseEventContent::prod, BareRootProductGetter::Buffer::product_, fwlite::BranchMapReader::updateEvent(), and fwlite::BranchMapReader::updateFile().

70  {
71  // std::cout << "getIt called" << std::endl;
72  TFile* currentFile = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->Last());
73  if(0 == currentFile) {
74  throw cms::Exception("FileNotFound")
75  << "unable to find the TFile '" << gROOT->GetListOfFiles()->Last() << "'\n"
76  << "retrieved by calling 'gROOT->GetListOfFiles()->Last()'\n"
77  << "Please check the list of files.";
78  }
79  if(branchMap_.updateFile(currentFile)) {
80  idToBuffers_.clear();
81  }
82  TTree* eventTree = branchMap_.getEventTree();
83  // std::cout << "eventTree " << eventTree << std::endl;
84  if(0 == eventTree) {
85  throw cms::Exception("NoEventsTree")
86  << "unable to find the TTree '" << edm::poolNames::eventTreeName() << "' in the last open file, \n"
87  << "file: '" << branchMap_.getFile()->GetName()
88  << "'\n Please check that the file is a standard CMS ROOT format.\n"
89  << "If the above is not the file you expect then please open your data file after all other files.";
90  }
91  Long_t eventEntry = eventTree->GetReadEntry();
92  // std::cout << "eventEntry " << eventEntry << std::endl;
93  branchMap_.updateEvent(eventEntry);
94  if(eventEntry < 0) {
95  throw cms::Exception("GetEntryNotCalled")
96  << "please call GetEntry for the 'Events' TTree for each event in order to make edm::Ref's work."
97  << "\n Also be sure to call 'SetAddress' for all Branches after calling the GetEntry."
98  ;
99  }
100 
101  Buffer* buffer = nullptr;
102  IdToBuffers::iterator itBuffer = idToBuffers_.find(iID);
103  // std::cout << "Buffers" << std::endl;
104  if(itBuffer == idToBuffers_.end()) {
105  buffer = createNewBuffer(iID);
106  // std::cout << "buffer " << buffer << std::endl;
107  if(nullptr == buffer) {
108  return nullptr;
109  }
110  } else {
111  buffer = &(itBuffer->second);
112  }
113  if(nullptr == buffer) {
114  throw cms::Exception("NullBuffer")
115  << "Found a null buffer which is supposed to hold the data item."
116  << "\n Please contact developers since this message should not happen.";
117  }
118  if(nullptr == buffer->branch_) {
119  throw cms::Exception("NullBranch")
120  << "The TBranch which should hold the data item is null."
121  << "\n Please contact the developers since this message should not happen.";
122  }
123  if(buffer->eventEntry_ != eventEntry) {
124  //NOTE: Need to reset address because user could have set the address themselves
125  //std::cout << "new event" << std::endl;
126 
127  //ROOT WORKAROUND: Create new objects so any internal data cache will get cleared
128  void* address = buffer->class_->New();
129 
130  static TClass const* edproductTClass = TClass::GetClass(typeid(edm::WrapperBase));
131  edm::WrapperBase const* prod = static_cast<edm::WrapperBase const*>(buffer->class_->DynamicCast(edproductTClass,address,true));
132 
133  if(nullptr == prod) {
134  cms::Exception("FailedConversion")
135  << "failed to convert a '" << buffer->class_->GetName()
136  << "' to a edm::WrapperBase."
137  << "Please contact developers since something is very wrong.";
138  }
139  buffer->address_ = address;
140  buffer->product_ = std::shared_ptr<edm::WrapperBase const>(prod);
141  //END WORKAROUND
142 
143  address = &(buffer->address_);
144  buffer->branch_->SetAddress(address);
145 
146  buffer->branch_->GetEntry(eventEntry);
147  buffer->eventEntry_ = eventEntry;
148  }
149  if(!buffer->product_) {
150  throw cms::Exception("BranchGetEntryFailed")
151  << "Calling GetEntry with index " << eventEntry
152  << "for branch " << buffer->branch_->GetName() << " failed.";
153  }
154 
155  return buffer->product_.get();
156 }
bool updateEvent(Long_t eventEntry)
bool updateFile(TFile *file)
TFile * getFile() const
TTree * getEventTree() const
Buffer * createNewBuffer(edm::ProductID const &) const
string const
Definition: compareJSON.py:14
std::string const & eventTreeName()
Definition: BranchType.cc:254
fwlite::BranchMapReader branchMap_
BareRootProductGetter const& BareRootProductGetter::operator= ( BareRootProductGetter const &  )
private
void BareRootProductGetter::setupNewFile ( TFile *  ) const
private
virtual unsigned int BareRootProductGetter::transitionIndex_ ( ) const
inlineoverrideprivatevirtual

Implements edm::EDProductGetter.

Definition at line 49 of file BareRootProductGetter.h.

49  {
50  return 0u;
51  }

Member Data Documentation

fwlite::BranchMapReader BareRootProductGetter::branchMap_
mutableprivate

Definition at line 83 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().

IdToBuffers BareRootProductGetter::idToBuffers_
mutableprivate

Definition at line 82 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().