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::WrapperHolder 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 36 of file BareRootProductGetter.h.

Member Typedef Documentation

Definition at line 82 of file BareRootProductGetter.h.

Constructor & Destructor Documentation

BareRootProductGetter::BareRootProductGetter ( )

Definition at line 39 of file BareRootProductGetter.cc.

39  {
40 }
BareRootProductGetter::~BareRootProductGetter ( )
virtual

Definition at line 46 of file BareRootProductGetter.cc.

46  {
47 }
BareRootProductGetter::BareRootProductGetter ( BareRootProductGetter const &  )
private

Member Function Documentation

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

Definition at line 156 of file BareRootProductGetter.cc.

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

Referenced by getIt().

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

Implements edm::EDProductGetter.

Definition at line 68 of file BareRootProductGetter.cc.

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

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

50  {
51  return 0u;
52  }

Member Data Documentation

fwlite::BranchMapReader BareRootProductGetter::branchMap_
mutableprivate

Definition at line 84 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().

IdToBuffers BareRootProductGetter::idToBuffers_
mutableprivate

Definition at line 83 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().