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
 
virtual ~BareRootProductGetter ()
 
- Public Member Functions inherited from edm::EDProductGetter
 EDProductGetter ()
 
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
 

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 77 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::BranchDescription::className(), edm::hlt::Exception, newFWLiteAna::fullName, fwlite::BranchMapReader::getEventTree(), edm::BranchDescription::getInterface(), idToBuffers_, edm::WrapperHolder::isValid(), parseEventContent::prod, fwlite::BranchMapReader::productToBranch(), 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
166  std::string const fullName = edm::wrappedClassName(bdesc.className());
167  Reflex::Type classType = Reflex::Type::ByName(fullName);
168  if(classType == Reflex::Type()) {
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  //We can't use reflex to create the instance since Reflex uses 'malloc' instead of new
176  /*
177  //use reflex to create an instance of it
178  Reflex::Object wrapperObj = classType.Construct();
179  if(0 == wrapperObj.Address()) {
180  cms::Exception("FailedToCreate") << "could not create an instance of '" << fullName << "'";
181  return 0;
182  }
183 
184  Reflex::Object edProdObj = wrapperObj.CastObject(Reflex::Type::ByName("edm::WrapperHolder"));
185 
186  edm::WrapperHolder* prod = reinterpret_cast<edm::WrapperHolder*>(edProdObj.Address());
187  */
188  TClass* rootClassType = TClass::GetClass(classType.TypeInfo());
189  if(0 == rootClassType) {
190  throw cms::Exception("MissingRootDictionary")
191  << "could not find a ROOT dictionary for type '" << fullName << "'"
192  << "\n Please make sure all the necessary libraries are available.";
193  return 0;
194  }
195  void* address = rootClassType->New();
196 
197  //static TClass* edproductTClass = TClass::GetClass(typeid(edm::WrapperHolder));
198  //edm::WrapperHolder* prod = reinterpret_cast<edm::WrapperHolder*>(rootClassType->DynamicCast(edproductTClass, address, true));
200  if(!prod.isValid()) {
201  cms::Exception("FailedConversion")
202  << "failed to convert a '" << fullName
203  << "' to a edm::WrapperOwningHolder."
204  << "Please contact developers since something is very wrong.";
205  }
206 
207  //connect the instance to the branch
208  //void* address = wrapperObj.Address();
209  Buffer b(prod, branch, address, rootClassType);
210  idToBuffers_[iID] = b;
211 
212  //As of 5.13 ROOT expects the memory address held by the pointer passed to
213  // SetAddress to be valid forever
214  address = &(idToBuffers_[iID].address_);
215  branch->SetAddress(address);
216 
217  return &(idToBuffers_[iID]);
218 }
char * address
Definition: mlp_lapack.h:14
std::string & branchName() const
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
virtual

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 }
char * address
Definition: mlp_lapack.h:14
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

Member Data Documentation

fwlite::BranchMapReader BareRootProductGetter::branchMap_
mutableprivate

Definition at line 79 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().

IdToBuffers BareRootProductGetter::idToBuffers_
mutableprivate

Definition at line 78 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().