CMS 3D CMS Logo

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 edm::WrapperBase const * getThinnedProduct (edm::ProductID const &, unsigned int &key) const override
 
virtual void getThinnedProducts (edm::ProductID const &, std::vector< edm::WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const override
 
virtual ~BareRootProductGetter ()
 
- Public Member Functions inherited from edm::EDProductGetter
 EDProductGetter ()
 
 EDProductGetter (EDProductGetter const &)=delete
 
EDProductGetter const & operator= (EDProductGetter const &)=delete
 
unsigned int transitionIndex () const
 
virtual ~EDProductGetter ()
 

Private Types

typedef std::map< edm::BranchID, BufferIdToBuffers
 

Private Member Functions

 BareRootProductGetter (BareRootProductGetter const &)
 
BuffercreateNewBuffer (edm::BranchID const &) const
 
edm::WrapperBase const * getIt (edm::BranchID const &, Long_t eventEntry) const
 
edm::ThinnedAssociation const * getThinnedAssociation (edm::BranchID const &branchID, Long_t eventEntry) const
 
BareRootProductGetter const & operator= (BareRootProductGetter 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 43 of file BareRootProductGetter.h.

Member Typedef Documentation

Definition at line 111 of file BareRootProductGetter.h.

Constructor & Destructor Documentation

BareRootProductGetter::BareRootProductGetter ( )

Definition at line 44 of file BareRootProductGetter.cc.

44  {
45 }
BareRootProductGetter::~BareRootProductGetter ( )
virtual

Definition at line 51 of file BareRootProductGetter.cc.

51  {
52 }
BareRootProductGetter::BareRootProductGetter ( BareRootProductGetter const &  )
private

Member Function Documentation

BareRootProductGetter::Buffer * BareRootProductGetter::createNewBuffer ( edm::BranchID const &  branchID) const
private

Definition at line 284 of file BareRootProductGetter.cc.

References b, MicroEventContent_cff::branch, fwlite::BranchMapReader::branchIDToBranch(), branchMap_, edm::BranchDescription::branchName(), edm::TypeWithDict::byName(), edm::BranchDescription::className(), Exception, fwlite::BranchMapReader::getEventTree(), idToBuffers_, eostools::move(), parseEventContent::prod, AlCaHLTBitMon_QueryRunRegistry::string, and edm::wrappedClassName().

Referenced by getIt().

284  {
285  //find the branch
286  edm::BranchDescription const& bdesc = branchMap_.branchIDToBranch(branchID);
287 
288  TBranch* branch= branchMap_.getEventTree()->GetBranch(bdesc.branchName().c_str());
289  if(nullptr == branch) {
290  //we do not thrown on missing branches since 'getIt' should not throw under that condition
291  return nullptr;
292  }
293  //find the class type
294  std::string const fullName = edm::wrappedClassName(bdesc.className());
295  edm::TypeWithDict classType(edm::TypeWithDict::byName(fullName));
296  if(!bool(classType)) {
297  throw cms::Exception("MissingDictionary")
298  << "could not find dictionary for type '" << fullName << "'"
299  << "\n Please make sure all the necessary libraries are available.";
300  return nullptr;
301  }
302 
303  TClass* rootClassType = TClass::GetClass(classType.typeInfo());
304  if(nullptr == rootClassType) {
305  throw cms::Exception("MissingRootDictionary")
306  << "could not find a ROOT dictionary for type '" << fullName << "'"
307  << "\n Please make sure all the necessary libraries are available.";
308  return nullptr;
309  }
310  void* address = rootClassType->New();
311 
312  static TClass const* edproductTClass = TClass::GetClass(typeid(edm::WrapperBase));
313  edm::WrapperBase const* prod = static_cast<edm::WrapperBase const*>( rootClassType->DynamicCast(edproductTClass,address,true));
314  if(nullptr == prod) {
315  throw cms::Exception("FailedConversion")
316  << "failed to convert a '" << fullName
317  << "' to a edm::WrapperBase."
318  << "Please contact developers since something is very wrong.";
319  }
320 
321  //connect the instance to the branch
322  //void* address = wrapperObj.Address();
323  Buffer b(prod, branch, address, rootClassType);
324  idToBuffers_[branchID] = std::move(b);
325 
326  //As of 5.13 ROOT expects the memory address held by the pointer passed to
327  // SetAddress to be valid forever
328  address = &(idToBuffers_[branchID].address_);
329  branch->SetAddress(address);
330 
331  return &(idToBuffers_[branchID]);
332 }
std::string const & branchName() const
const edm::BranchDescription & branchIDToBranch(const edm::BranchID &bid) const
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:60
std::string const & className() const
TTree const * getEventTree() const
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:120
fwlite::BranchMapReader branchMap_
def move(src, dest)
Definition: eostools.py:510
edm::WrapperBase const * BareRootProductGetter::getIt ( edm::ProductID const &  pid) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 73 of file BareRootProductGetter.cc.

References branchMap_, edm::poolNames::eventTreeName(), Exception, fwlite::BranchMapReader::getEventTree(), fwlite::BranchMapReader::getFile(), idToBuffers_, fwlite::BranchMapReader::productToBranchID(), fwlite::BranchMapReader::updateEvent(), and fwlite::BranchMapReader::updateFile().

Referenced by getThinnedAssociation(), getThinnedProduct(), and getThinnedProducts().

73  {
74  // std::cout << "getIt called " << pid << std::endl;
75  TFile* currentFile = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->Last());
76  if(nullptr == currentFile) {
77  throw cms::Exception("FileNotFound")
78  << "unable to find the TFile '" << gROOT->GetListOfFiles()->Last() << "'\n"
79  << "retrieved by calling 'gROOT->GetListOfFiles()->Last()'\n"
80  << "Please check the list of files.";
81  }
82  if(branchMap_.updateFile(currentFile)) {
83  idToBuffers_.clear();
84  }
85  TTree* eventTree = branchMap_.getEventTree();
86  // std::cout << "eventTree " << eventTree << std::endl;
87  if(nullptr == eventTree) {
88  throw cms::Exception("NoEventsTree")
89  << "unable to find the TTree '" << edm::poolNames::eventTreeName() << "' in the last open file, \n"
90  << "file: '" << branchMap_.getFile()->GetName()
91  << "'\n Please check that the file is a standard CMS ROOT format.\n"
92  << "If the above is not the file you expect then please open your data file after all other files.";
93  }
94  Long_t eventEntry = eventTree->GetReadEntry();
95  // std::cout << "eventEntry " << eventEntry << std::endl;
96  branchMap_.updateEvent(eventEntry);
97  if(eventEntry < 0) {
98  throw cms::Exception("GetEntryNotCalled")
99  << "please call GetEntry for the 'Events' TTree for each event in order to make edm::Ref's work."
100  << "\n Also be sure to call 'SetAddress' for all Branches after calling the GetEntry."
101  ;
102  }
103 
105 
106  return getIt(branchID, eventEntry);
107 }
bool updateEvent(Long_t eventEntry)
TFile const * getFile() const
bool updateFile(TFile *file)
virtual edm::WrapperBase const * getIt(edm::ProductID const &) const override
TTree const * getEventTree() const
std::string const & eventTreeName()
Definition: BranchType.cc:260
fwlite::BranchMapReader branchMap_
edm::BranchID productToBranchID(const edm::ProductID &pid)
edm::WrapperBase const * BareRootProductGetter::getIt ( edm::BranchID const &  branchID,
Long_t  eventEntry 
) const
private

Definition at line 110 of file BareRootProductGetter.cc.

References BareRootProductGetter::Buffer::address_, BareRootProductGetter::Buffer::branch_, edmScanValgrind::buffer, BareRootProductGetter::Buffer::class_, createNewBuffer(), BareRootProductGetter::Buffer::eventEntry_, Exception, idToBuffers_, parseEventContent::prod, and BareRootProductGetter::Buffer::product_.

110  {
111 
112  Buffer* buffer = nullptr;
113  IdToBuffers::iterator itBuffer = idToBuffers_.find(branchID);
114 
115  // std::cout << "Buffers" << std::endl;
116  if(itBuffer == idToBuffers_.end()) {
117  buffer = createNewBuffer(branchID);
118  // std::cout << "buffer " << buffer << std::endl;
119  if(nullptr == buffer) {
120  return nullptr;
121  }
122  } else {
123  buffer = &(itBuffer->second);
124  }
125  if(nullptr == buffer) {
126  throw cms::Exception("NullBuffer")
127  << "Found a null buffer which is supposed to hold the data item."
128  << "\n Please contact developers since this message should not happen.";
129  }
130  if(nullptr == buffer->branch_) {
131  throw cms::Exception("NullBranch")
132  << "The TBranch which should hold the data item is null."
133  << "\n Please contact the developers since this message should not happen.";
134  }
135  if(buffer->eventEntry_ != eventEntry) {
136  //NOTE: Need to reset address because user could have set the address themselves
137  //std::cout << "new event" << std::endl;
138 
139  //ROOT WORKAROUND: Create new objects so any internal data cache will get cleared
140  void* address = buffer->class_->New();
141 
142  static TClass const* edproductTClass = TClass::GetClass(typeid(edm::WrapperBase));
143  edm::WrapperBase const* prod = static_cast<edm::WrapperBase const*>(buffer->class_->DynamicCast(edproductTClass,address,true));
144 
145  if(nullptr == prod) {
146  cms::Exception("FailedConversion")
147  << "failed to convert a '" << buffer->class_->GetName()
148  << "' to a edm::WrapperBase."
149  << "Please contact developers since something is very wrong.";
150  }
151  buffer->address_ = address;
152  buffer->product_ = std::shared_ptr<edm::WrapperBase const>(prod);
153  //END WORKAROUND
154 
155  address = &(buffer->address_);
156  buffer->branch_->SetAddress(address);
157 
158  buffer->branch_->GetEntry(eventEntry);
159  buffer->eventEntry_ = eventEntry;
160  }
161  if(!buffer->product_) {
162  throw cms::Exception("BranchGetEntryFailed")
163  << "Calling GetEntry with index " << eventEntry
164  << "for branch " << buffer->branch_->GetName() << " failed.";
165  }
166 
167  return buffer->product_.get();
168 }
Buffer * createNewBuffer(edm::BranchID const &) const
edm::ThinnedAssociation const * BareRootProductGetter::getThinnedAssociation ( edm::BranchID const &  branchID,
Long_t  eventEntry 
) const
private

Definition at line 335 of file BareRootProductGetter.cc.

References edm::WrapperBase::dynamicTypeInfo(), Exception, getIt(), edm::errors::LogicError, and wrapper.

Referenced by getThinnedProduct(), and getThinnedProducts().

335  {
336 
337  edm::WrapperBase const* wrapperBase = getIt(branchID, eventEntry);
338  if(wrapperBase == nullptr) {
340  << "BareRootProductGetter::getThinnedAssociation, product ThinnedAssociation not found.\n";
341  }
342  if(!(typeid(edm::ThinnedAssociation) == wrapperBase->dynamicTypeInfo())) {
344  << "BareRootProductGetter::getThinnedAssociation, product has wrong type, not a ThinnedAssociation.\n";
345  }
347  static_cast<edm::Wrapper<edm::ThinnedAssociation> const*>(wrapperBase);
348 
349  edm::ThinnedAssociation const* thinnedAssociation = wrapper->product();
350  return thinnedAssociation;
351 }
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
virtual edm::WrapperBase const * getIt(edm::ProductID const &) const override
static HepMC::HEPEVT_Wrapper wrapper
edm::WrapperBase const * BareRootProductGetter::getThinnedProduct ( edm::ProductID const &  pid,
unsigned int &  key 
) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 171 of file BareRootProductGetter.cc.

References branchMap_, fwlite::BranchMapReader::getEventTree(), getIt(), getThinnedAssociation(), edm::ThinnedAssociation::hasParentIndex(), edm::BranchID::isValid(), class-composition::parent, edm::ThinnedAssociationsHelper::parentBegin(), edm::ThinnedAssociation::parentCollectionID(), edm::ThinnedAssociationsHelper::parentEnd(), fwlite::BranchMapReader::productToBranchID(), fwlite::BranchMapReader::thinnedAssociationsHelper(), and edm::ThinnedAssociation::thinnedCollectionID().

171  {
172 
173  Long_t eventEntry = branchMap_.getEventTree()->GetReadEntry();
175  if(!parent.isValid()) return nullptr;
176  edm::ThinnedAssociationsHelper const& thinnedAssociationsHelper = branchMap_.thinnedAssociationsHelper();
177 
178  // Loop over thinned containers which were made by selecting elements from the parent container
179  for(auto associatedBranches = thinnedAssociationsHelper.parentBegin(parent),
180  iEnd = thinnedAssociationsHelper.parentEnd(parent);
181  associatedBranches != iEnd; ++associatedBranches) {
182 
183  edm::ThinnedAssociation const* thinnedAssociation =
184  getThinnedAssociation(associatedBranches->association(), eventEntry);
185  if(thinnedAssociation == nullptr) continue;
186 
187  if(associatedBranches->parent() != branchMap_.productToBranchID(thinnedAssociation->parentCollectionID())) {
188  continue;
189  }
190 
191  unsigned int thinnedIndex = 0;
192  // Does this thinned container have the element referenced by key?
193  // If yes, thinnedIndex is set to point to it in the thinned container
194  if(!thinnedAssociation->hasParentIndex(key, thinnedIndex)) {
195  continue;
196  }
197  // Get the thinned container and return a pointer if we can find it
198  edm::ProductID const& thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
199  edm::WrapperBase const* thinnedCollection = getIt(thinnedCollectionPID);
200  if(thinnedCollection == nullptr) {
201  // Thinned container is not found, try looking recursively in thinned containers
202  // which were made by selecting elements from this thinned container.
203  edm::WrapperBase const* thinnedFromRecursiveCall = getThinnedProduct(thinnedCollectionPID, thinnedIndex);
204  if(thinnedFromRecursiveCall != nullptr) {
205  key = thinnedIndex;
206  return thinnedFromRecursiveCall;
207  } else {
208  continue;
209  }
210  }
211  key = thinnedIndex;
212  return thinnedCollection;
213  }
214  return nullptr;
215 }
virtual edm::WrapperBase const * getIt(edm::ProductID const &) const override
bool isValid() const
Definition: BranchID.h:24
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
TTree const * getEventTree() const
ProductID const & thinnedCollectionID() const
const edm::ThinnedAssociationsHelper & thinnedAssociationsHelper() const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
virtual edm::WrapperBase const * getThinnedProduct(edm::ProductID const &, unsigned int &key) const override
fwlite::BranchMapReader branchMap_
ProductID const & parentCollectionID() const
bool hasParentIndex(unsigned int parentIndex, unsigned int &thinnedIndex) const
edm::BranchID productToBranchID(const edm::ProductID &pid)
void BareRootProductGetter::getThinnedProducts ( edm::ProductID const &  pid,
std::vector< edm::WrapperBase const * > &  foundContainers,
std::vector< unsigned int > &  keys 
) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 218 of file BareRootProductGetter.cc.

References branchMap_, fwlite::BranchMapReader::getEventTree(), getIt(), getThinnedAssociation(), edm::ThinnedAssociation::hasParentIndex(), edm::BranchID::isValid(), gen::k, hpstanc_transforms::max, class-composition::parent, edm::ThinnedAssociationsHelper::parentBegin(), edm::ThinnedAssociation::parentCollectionID(), edm::ThinnedAssociationsHelper::parentEnd(), fwlite::BranchMapReader::productToBranchID(), fwlite::BranchMapReader::thinnedAssociationsHelper(), and edm::ThinnedAssociation::thinnedCollectionID().

220  {
221 
222  Long_t eventEntry = branchMap_.getEventTree()->GetReadEntry();
224  if(!parent.isValid()) return;
225  edm::ThinnedAssociationsHelper const& thinnedAssociationsHelper = branchMap_.thinnedAssociationsHelper();
226 
227  // Loop over thinned containers which were made by selecting elements from the parent container
228  for(auto associatedBranches = thinnedAssociationsHelper.parentBegin(parent),
229  iEnd = thinnedAssociationsHelper.parentEnd(parent);
230  associatedBranches != iEnd; ++associatedBranches) {
231 
232  edm::ThinnedAssociation const* thinnedAssociation =
233  getThinnedAssociation(associatedBranches->association(), eventEntry);
234  if(thinnedAssociation == nullptr) continue;
235 
236  if(associatedBranches->parent() != branchMap_.productToBranchID(thinnedAssociation->parentCollectionID())) {
237  continue;
238  }
239 
240  unsigned int nKeys = keys.size();
241  unsigned int doNotLookForThisIndex = std::numeric_limits<unsigned int>::max();
242  std::vector<unsigned int> thinnedIndexes(nKeys, doNotLookForThisIndex);
243  bool hasAny = false;
244  for(unsigned k = 0; k < nKeys; ++k) {
245  // Already found this one
246  if(foundContainers[k] != nullptr) continue;
247  // Already know this one is not in this thinned container
248  if(keys[k] == doNotLookForThisIndex) continue;
249  // Does the thinned container hold the entry of interest?
250  // Modifies thinnedIndexes[k] only if it returns true and
251  // sets it to the index in the thinned collection.
252  if(thinnedAssociation->hasParentIndex(keys[k], thinnedIndexes[k])) {
253  hasAny = true;
254  }
255  }
256  if(!hasAny) {
257  continue;
258  }
259  // Get the thinned container and set the pointers and indexes into
260  // it (if we can find it)
261  edm::ProductID thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
262  edm::WrapperBase const* thinnedCollection = getIt(thinnedCollectionPID);
263 
264  if(thinnedCollection == nullptr) {
265  // Thinned container is not found, try looking recursively in thinned containers
266  // which were made by selecting elements from this thinned container.
267  getThinnedProducts(thinnedCollectionPID, foundContainers, thinnedIndexes);
268  for(unsigned k = 0; k < nKeys; ++k) {
269  if(foundContainers[k] == nullptr) continue;
270  if(thinnedIndexes[k] == doNotLookForThisIndex) continue;
271  keys[k] = thinnedIndexes[k];
272  }
273  } else {
274  for(unsigned k = 0; k < nKeys; ++k) {
275  if(thinnedIndexes[k] == doNotLookForThisIndex) continue;
276  keys[k] = thinnedIndexes[k];
277  foundContainers[k] = thinnedCollection;
278  }
279  }
280  }
281 }
virtual edm::WrapperBase const * getIt(edm::ProductID const &) const override
bool isValid() const
Definition: BranchID.h:24
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
virtual void getThinnedProducts(edm::ProductID const &, std::vector< edm::WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys) const override
TTree const * getEventTree() const
ProductID const & thinnedCollectionID() const
int k[5][pyjets_maxn]
const edm::ThinnedAssociationsHelper & thinnedAssociationsHelper() const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
fwlite::BranchMapReader branchMap_
ProductID const & parentCollectionID() const
bool hasParentIndex(unsigned int parentIndex, unsigned int &thinnedIndex) const
edm::BranchID productToBranchID(const edm::ProductID &pid)
BareRootProductGetter const& BareRootProductGetter::operator= ( BareRootProductGetter const &  )
private
virtual unsigned int BareRootProductGetter::transitionIndex_ ( ) const
inlineoverrideprivatevirtual

Implements edm::EDProductGetter.

Definition at line 82 of file BareRootProductGetter.h.

82  {
83  return 0u;
84  }

Member Data Documentation

fwlite::BranchMapReader BareRootProductGetter::branchMap_
mutableprivate
IdToBuffers BareRootProductGetter::idToBuffers_
mutableprivate

Definition at line 112 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().