CMS 3D CMS Logo

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

#include <DataGetterHelper.h>

Public Member Functions

 DataGetterHelper (TTree *tree, boost::shared_ptr< HistoryGetterBase > historyGetter, boost::shared_ptr< BranchMapReader > branchMap=boost::shared_ptr< BranchMapReader >(), boost::shared_ptr< edm::EDProductGetter > getter=boost::shared_ptr< edm::EDProductGetter >(), bool useCache=false)
 
virtual std::string const getBranchNameFor (std::type_info const &, char const *, char const *, char const *) const
 
virtual bool getByLabel (std::type_info const &, char const *, char const *, char const *, void *, Long_t) const
 
virtual bool getByLabel (std::type_info const &, char const *, char const *, char const *, edm::WrapperHolder &, Long_t) const
 
edm::WrapperHolder getByProductID (edm::ProductID const &, Long_t) const
 
edm::EDProductGettergetter ()
 
void setGetter (boost::shared_ptr< edm::EDProductGetter > getter)
 
virtual ~DataGetterHelper ()
 

Static Public Member Functions

static void throwProductNotFoundException (std::type_info const &, char const *, char const *, char const *)
 

Private Types

typedef std::map
< internal::DataKey,
boost::shared_ptr
< internal::Data > > 
KeyToDataMap
 

Private Member Functions

 DataGetterHelper (const DataGetterHelper &)
 
void getBranchData (edm::EDProductGetter *, Long64_t, internal::Data &) const
 
internal::DatagetBranchDataFor (std::type_info const &, char const *, char const *, char const *) const
 
const edm::ProcessHistoryhistory () const
 
const DataGetterHelperoperator= (const DataGetterHelper &)
 

Private Attributes

boost::shared_ptr
< BranchMapReader
branchMap_
 
KeyToDataMap data_
 
boost::shared_ptr
< edm::EDProductGetter
getter_
 
boost::shared_ptr
< fwlite::HistoryGetterBase
historyGetter_
 
std::map< std::pair
< edm::ProductID,
edm::BranchListIndexes >
, boost::shared_ptr
< internal::Data > > 
idToData_
 
std::vector< char const * > labels_
 
std::auto_ptr< TTreeCache > tcache_
 
bool tcTrained_
 
TTree * tree_
 

Detailed Description

Definition at line 43 of file DataGetterHelper.h.

Member Typedef Documentation

typedef std::map<internal::DataKey, boost::shared_ptr<internal::Data> > fwlite::DataGetterHelper::KeyToDataMap
private

Definition at line 88 of file DataGetterHelper.h.

Constructor & Destructor Documentation

DataGetterHelper::DataGetterHelper ( TTree *  tree,
boost::shared_ptr< HistoryGetterBase historyGetter,
boost::shared_ptr< BranchMapReader branchMap = boost::shared_ptr<BranchMapReader>(),
boost::shared_ptr< edm::EDProductGetter getter = boost::shared_ptr<edm::EDProductGetter>(),
bool  useCache = false 
)

Definition at line 62 of file DataGetterHelper.cc.

References branchMap_, edm::hlt::Exception, tcache_, MainPageGenerator::tree, tree_, and TTCACHE_SIZE.

66  :
67  branchMap_(branchMap),
68  historyGetter_(historyGetter),
69  getter_(getter),
70  tcache_(0),
71  tcTrained_(false)
72  {
73  if(0==tree) {
74  throw cms::Exception("NoTree")<<"The TTree pointer passed to the constructor was null";
75  }
76  tree_ = tree;
77  if (useCache) {
78  tree_->SetCacheSize(TTCACHE_SIZE);
79  TFile* iFile(branchMap_->getFile());
80  tcache_.reset(dynamic_cast<TTreeCache*>(iFile->GetCacheRead()));
81  iFile->SetCacheRead(0);
82  //std::cout << "In const " << iFile << " " << tcache_ << " " << iFile->GetCacheRead() << std::endl;
83  }
84  }
edm::EDProductGetter * getter()
boost::shared_ptr< edm::EDProductGetter > getter_
#define TTCACHE_SIZE
std::auto_ptr< TTreeCache > tcache_
boost::shared_ptr< BranchMapReader > branchMap_
boost::shared_ptr< fwlite::HistoryGetterBase > historyGetter_
DataGetterHelper::~DataGetterHelper ( )
virtual

Definition at line 91 of file DataGetterHelper.cc.

91 { }
fwlite::DataGetterHelper::DataGetterHelper ( const DataGetterHelper )
private

Member Function Documentation

void DataGetterHelper::getBranchData ( edm::EDProductGetter iGetter,
Long64_t  index,
internal::Data iData 
) const
private

Definition at line 130 of file DataGetterHelper.cc.

References fwlite::internal::Data::branch_, branchMap_, getHLTprescales::index, fwlite::internal::Data::lastProduct_, getGTfromDQMFile::obj, fwlite::internal::Data::obj_, fwlite::internal::Data::pObj_, fwlite::internal::Data::pProd_, tcache_, tcTrained_, and tree_.

Referenced by getByLabel(), and getByProductID().

133  {
134  GetterOperate op(iGetter);
135 
136  //WORK AROUND FOR ROOT!!
137  //Create a new instance so that we can clear any cache the object uses
138  //this slows the code down
139  Reflex::Object obj = iData.obj_;
140  iData.obj_ = iData.obj_.TypeOf().Construct();
141  iData.pObj_ = iData.obj_.Address();
142  iData.branch_->SetAddress(&(iData.pObj_));
143  //If a REF to this was requested in the past, we might as well do the work now
144  if(0!=iData.pProd_) {
145  iData.pProd_ = iData.obj_.Address();
146  }
147  obj.Destruct();
148  //END OF WORK AROUND
149 
150  if (0 == tcache_.get()) {
151  iData.branch_->GetEntry(index);
152  } else {
153  if (!tcTrained_) {
154  tcache_->SetLearnEntries(100);
155  tcache_->SetEntryRange(0, tree_->GetEntries());
156  tcTrained_ = true;
157  }
158  withTCache tcguard(branchMap_->getFile(), tcache_.get());
159  tree_->LoadTree(index);
160  iData.branch_->GetEntry(index);
161  }
162  iData.lastProduct_=index;
163  }
std::auto_ptr< TTreeCache > tcache_
boost::shared_ptr< BranchMapReader > branchMap_
internal::Data & DataGetterHelper::getBranchDataFor ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel 
) const
private

Definition at line 167 of file DataGetterHelper.cc.

References fwlite::branchNotFound, data_, edm::hlt::Exception, fwlite::findBranch(), edm::TypeID::friendlyClassName(), h, history(), fwlite::internal::DataKey::kEmpty(), combine::key, labels_, fwlite::internal::DataKey::module(), mergeVDriftHistosByStation::name, getGTfromDQMFile::obj, fwlite::internal::DataKey::process(), fwlite::internal::DataKey::product(), edm::ProcessHistory::rbegin(), edm::ProcessHistory::rend(), and tree_.

Referenced by getBranchNameFor(), and getByLabel().

171  {
172  edm::TypeID type(iInfo);
173  internal::DataKey key(type, iModuleLabel, iProductInstanceLabel, iProcessLabel);
174 
175  boost::shared_ptr<internal::Data> theData;
176  DataMap::iterator itFind = data_.find(key);
177  if(itFind == data_.end()) {
178  //see if such a branch actually exists
179  std::string const sep("_");
180  //CHANGE: If this fails, need to lookup the the friendly name which was used to write the file
181  std::string name(type.friendlyClassName());
182  name +=sep+std::string(key.module());
183  name +=sep+std::string(key.product())+sep;
184 
185  //if we have to lookup the process label, remember it and register the product again
186  std::string foundProcessLabel;
187  TBranch* branch = 0;
188 
189  if (0==iProcessLabel || iProcessLabel==key.kEmpty() ||
190  strlen(iProcessLabel)==0) {
191  std::string const* lastLabel=0;
192  //have to search in reverse order since newest are on the bottom
194  for (edm::ProcessHistory::const_reverse_iterator iproc = h.rbegin(), eproc = h.rend();
195  iproc != eproc;
196  ++iproc) {
197 
198  lastLabel = &(iproc->processName());
199  branch=findBranch(tree_,name,iproc->processName());
200  if(0!=branch) {
201  break;
202  }
203  }
204  if(0==branch) {
205  return branchNotFound;
206  }
207  //do we already have this one?
208  if(0!=lastLabel) {
209  internal::DataKey fullKey(type,iModuleLabel,iProductInstanceLabel,lastLabel->c_str());
210  itFind = data_.find(fullKey);
211  if(itFind != data_.end()) {
212  //remember the data we've found
213  theData = itFind->second;
214  } else {
215  //only set this if we don't already have it since it this string is not empty we re-register
216  foundProcessLabel = *lastLabel;
217  }
218  }
219  } else {
220  //we have all the pieces
221  branch = findBranch(tree_,name,key.process());
222  if(0==branch){
223  return branchNotFound;
224  }
225  }
226 
227  //cache the info
228  size_t moduleLabelLen = strlen(iModuleLabel)+1;
229  char* newModule = new char[moduleLabelLen];
230  std::strncpy(newModule,iModuleLabel,moduleLabelLen);
231  labels_.push_back(newModule);
232 
233  char* newProduct = const_cast<char*>(key.product());
234  if(newProduct[0] != 0) {
235  size_t newProductLen = strlen(newProduct)+1;
236  newProduct = new char[newProductLen];
237  std::strncpy(newProduct,key.product(),newProductLen);
238  labels_.push_back(newProduct);
239  }
240  char* newProcess = const_cast<char*>(key.process());
241  if(newProcess[0]!=0) {
242  size_t newProcessLen = strlen(newProcess)+1;
243  newProcess = new char[newProcessLen];
244  std::strncpy(newProcess,key.process(),newProcessLen);
245  labels_.push_back(newProcess);
246  }
247  internal::DataKey newKey(edm::TypeID(iInfo),newModule,newProduct,newProcess);
248 
249  if(0 == theData.get()) {
250  //We do not already have this data as another key
251 
252  //Use Reflex to create an instance of the object to be used as a buffer
253  Reflex::Type rType = Reflex::Type::ByTypeInfo(iInfo);
254  if(rType == Reflex::Type()) {
255  throw cms::Exception("UnknownType")<<"No Reflex dictionary exists for type "<<iInfo.name();
256  }
257  Reflex::Object obj = rType.Construct();
258 
259  if(obj.Address() == 0) {
260  throw cms::Exception("ConstructionFailed")<<"failed to construct an instance of "<<rType.Name();
261  }
262  boost::shared_ptr<internal::Data> newData(new internal::Data());
263  newData->branch_ = branch;
264  newData->obj_ = obj;
265  newData->lastProduct_=-1;
266  newData->pObj_ = obj.Address();
267  newData->pProd_ = 0;
268  branch->SetAddress(&(newData->pObj_));
269  newData->interface_ = 0;
270  Reflex::Member getTheInterface = rType.FunctionMemberByName(std::string("getInterface"));
271  getTheInterface.Invoke(newData->interface_);
272  theData = newData;
273  }
274  itFind = data_.insert(std::make_pair(newKey, theData)).first;
275 
276  if(foundProcessLabel.size()) {
277  //also remember it with the process label
278  newProcess = new char[foundProcessLabel.size()+1];
279  std::strcpy(newProcess,foundProcessLabel.c_str());
280  labels_.push_back(newProcess);
281  internal::DataKey newKey(edm::TypeID(iInfo),newModule,newProduct,newProcess);
282 
283  data_.insert(std::make_pair(newKey,theData));
284  }
285  }
286  return *(itFind->second);
287  }
const_reverse_iterator rbegin() const
static TBranch * findBranch(TTree *iTree, std::string const &iMainLabels, std::string const &iProcess)
type
Definition: HCALResponse.h:22
std::vector< char const * > labels_
collection_type::const_reverse_iterator const_reverse_iterator
const edm::ProcessHistory & history() const
const_reverse_iterator rend() const
static internal::Data branchNotFound
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
list key
Definition: combine.py:13
std::string const DataGetterHelper::getBranchNameFor ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel 
) const
virtual

Definition at line 290 of file DataGetterHelper.cc.

References fwlite::internal::Data::branch_, and getBranchDataFor().

Referenced by fwlite::Run::getBranchNameFor(), fwlite::LuminosityBlock::getBranchNameFor(), and fwlite::Event::getBranchNameFor().

294  {
295  internal::Data& theData =
296  DataGetterHelper::getBranchDataFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
297 
298  if (0 != theData.branch_) {
299  return std::string(theData.branch_->GetName());
300  }
301  return std::string("");
302  }
internal::Data & getBranchDataFor(std::type_info const &, char const *, char const *, char const *) const
bool DataGetterHelper::getByLabel ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel,
void *  oData,
Long_t  index 
) const
virtual

Definition at line 305 of file DataGetterHelper.cc.

References fwlite::internal::Data::branch_, getBranchData(), getBranchDataFor(), getter_, getHLTprescales::index, fwlite::internal::Data::lastProduct_, and fwlite::internal::Data::obj_.

Referenced by fwlite::Run::getByLabel(), fwlite::LuminosityBlock::getByLabel(), fwlite::Event::getByLabel(), and getByProductID().

310  {
311  // Maintain atEnd() check in parent classes
312  void** pOData = reinterpret_cast<void**>(oData);
313  *pOData = 0;
314 
315  internal::Data& theData =
316  DataGetterHelper::getBranchDataFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
317 
318  if (0 != theData.branch_) {
319  if(index != theData.lastProduct_) {
320  //haven't gotten the data for this event
321  getBranchData(getter_.get(), index, theData);
322  }
323  *pOData = theData.obj_.Address();
324  }
325 
326  if (0 == *pOData) return false;
327  else return true;
328  }
boost::shared_ptr< edm::EDProductGetter > getter_
void getBranchData(edm::EDProductGetter *, Long64_t, internal::Data &) const
internal::Data & getBranchDataFor(std::type_info const &, char const *, char const *, char const *) const
bool DataGetterHelper::getByLabel ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel,
edm::WrapperHolder holder,
Long_t  index 
) const
virtual

Definition at line 331 of file DataGetterHelper.cc.

References fwlite::internal::Data::branch_, getBranchData(), getBranchDataFor(), getter_, getHLTprescales::index, fwlite::internal::Data::interface_, edm::WrapperHolder::isValid(), fwlite::internal::Data::lastProduct_, and fwlite::internal::Data::obj_.

335  {
336 
337  // Maintain atEnd() check in parent classes
338 
339  internal::Data& theData =
340  DataGetterHelper::getBranchDataFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
341 
342  if(0 != theData.branch_) {
343  if(index != theData.lastProduct_) {
344  //haven't gotten the data for this event
345  getBranchData(getter_.get(), index, theData);
346  }
347  }
348 
349  holder = edm::WrapperHolder(theData.obj_.Address(), theData.interface_);
350  return holder.isValid();
351  }
boost::shared_ptr< edm::EDProductGetter > getter_
void getBranchData(edm::EDProductGetter *, Long64_t, internal::Data &) const
internal::Data & getBranchDataFor(std::type_info const &, char const *, char const *, char const *) const
bool isValid() const
Definition: WrapperHolder.h:27
edm::WrapperHolder DataGetterHelper::getByProductID ( edm::ProductID const &  iID,
Long_t  index 
) const

Definition at line 354 of file DataGetterHelper.cc.

References edm::BranchDescription::branchID(), branchMap_, data_, edm::BranchDescription::fullClassName(), getBranchData(), getByLabel(), getter_, idToData_, getHLTprescales::index, edm::BranchID::isValid(), edm::WrapperHolder::isValid(), gen::k, edm::BranchDescription::moduleLabel(), edm::BranchDescription::processName(), edm::BranchDescription::productInstanceName(), edm::wrappedClassName(), and edm::WrapperHolder::wrapper().

Referenced by fwlite::Run::getByProductID(), fwlite::LuminosityBlock::getByProductID(), and fwlite::Event::getByProductID().

355  {
356  typedef std::pair<edm::ProductID,edm::BranchListIndexes> IDPair;
357  IDPair theID = std::make_pair(iID, branchMap_->branchListIndexes());
358  std::map<IDPair,boost::shared_ptr<internal::Data> >::const_iterator itFound = idToData_.find(theID);
359  if(itFound == idToData_.end()) {
360  edm::BranchDescription const& bDesc = branchMap_->productToBranch(iID);
361 
362  if (!bDesc.branchID().isValid()) {
363  return edm::WrapperHolder();
364  }
365 
366  //Calculate the key from the branch description
367  Reflex::Type type(Reflex::Type::ByName(edm::wrappedClassName(bDesc.fullClassName())));
368  assert(Reflex::Type() != type) ;
369 
370  //Only the product instance label may be empty
371  char const* pIL = bDesc.productInstanceName().c_str();
372  if(pIL[0] == 0) {
373  pIL = 0;
374  }
375  internal::DataKey k(edm::TypeID(type.TypeInfo()),
376  bDesc.moduleLabel().c_str(),
377  pIL,
378  bDesc.processName().c_str());
379 
380  //has this already been gotten?
381  KeyToDataMap::iterator itData = data_.find(k);
382  if(data_.end() == itData) {
383  //ask for the data
384  edm::WrapperHolder holder;
385  getByLabel(type.TypeInfo(),
386  k.module(),
387  k.product(),
388  k.process(),
389  holder, index);
390  if(!holder.isValid()) {
391  return holder;
392  }
393  itData = data_.find(k);
394  assert(itData != data_.end());
395  assert(holder.wrapper() == itData->second->obj_.Address());
396  }
397  itFound = idToData_.insert(std::make_pair(theID,itData->second)).first;
398  }
399  if(index != itFound->second->lastProduct_) {
400  //haven't gotten the data for this event
401  getBranchData(getter_.get(), index, *(itFound->second));
402  }
403  if(0==itFound->second->pProd_) {
404  itFound->second->pProd_ = itFound->second->obj_.Address();
405 
406  if(0==itFound->second->pProd_) {
407  return edm::WrapperHolder();
408  }
409  }
410  //return itFound->second->pProd_;
411  return edm::WrapperHolder(itFound->second->pProd_, itFound->second->interface_);
412  }
type
Definition: HCALResponse.h:22
std::map< std::pair< edm::ProductID, edm::BranchListIndexes >, boost::shared_ptr< internal::Data > > idToData_
std::string const & processName() const
bool isValid() const
Definition: BranchID.h:24
boost::shared_ptr< edm::EDProductGetter > getter_
std::string const & moduleLabel() const
std::string const & productInstanceName() const
BranchID const & branchID() const
std::string const & fullClassName() const
int k[5][pyjets_maxn]
std::string wrappedClassName(std::string const &iFullName)
void getBranchData(edm::EDProductGetter *, Long64_t, internal::Data &) const
boost::shared_ptr< BranchMapReader > branchMap_
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *, Long_t) const
bool isValid() const
Definition: WrapperHolder.h:27
void const * wrapper() const
Definition: WrapperHolder.h:76
edm::EDProductGetter* fwlite::DataGetterHelper::getter ( )
inline

Definition at line 74 of file DataGetterHelper.h.

References getter_.

Referenced by fwlite::Event::draw(), fwlite::Event::scan(), and setGetter().

74  {
75  return getter_.get();
76  }
boost::shared_ptr< edm::EDProductGetter > getter_
const edm::ProcessHistory & DataGetterHelper::history ( ) const
private

Definition at line 414 of file DataGetterHelper.cc.

References historyGetter_.

Referenced by getBranchDataFor().

414  {
415  return historyGetter_->history();
416  }
boost::shared_ptr< fwlite::HistoryGetterBase > historyGetter_
const DataGetterHelper& fwlite::DataGetterHelper::operator= ( const DataGetterHelper )
private
void fwlite::DataGetterHelper::setGetter ( boost::shared_ptr< edm::EDProductGetter getter)
inline

Definition at line 70 of file DataGetterHelper.h.

References getter(), and getter_.

Referenced by fwlite::Event::setGetter().

70  {
71  getter_ = getter;
72  }
edm::EDProductGetter * getter()
boost::shared_ptr< edm::EDProductGetter > getter_
void DataGetterHelper::throwProductNotFoundException ( std::type_info const &  iType,
char const *  iModule,
char const *  iProduct,
char const *  iProcess 
)
static

Definition at line 423 of file DataGetterHelper.cc.

References edm::TypeID::className(), edm::hlt::Exception, and edm::errors::ProductNotFound.

424  {
425  edm::TypeID type(iType);
426  throw edm::Exception(edm::errors::ProductNotFound)<<"A branch was found for \n type ='"<<type.className()<<"'\n module='"<<iModule
427  <<"'\n productInstance='"<<((0!=iProduct)?iProduct:"")<<"'\n process='"<<((0!=iProcess)?iProcess:"")<<"'\n"
428  "but no data is available for this Lumi";
429  }
type
Definition: HCALResponse.h:22

Member Data Documentation

boost::shared_ptr<BranchMapReader> fwlite::DataGetterHelper::branchMap_
mutableprivate

Definition at line 87 of file DataGetterHelper.h.

Referenced by DataGetterHelper(), getBranchData(), and getByProductID().

KeyToDataMap fwlite::DataGetterHelper::data_
mutableprivate

Definition at line 89 of file DataGetterHelper.h.

Referenced by getBranchDataFor(), and getByProductID().

boost::shared_ptr<edm::EDProductGetter> fwlite::DataGetterHelper::getter_
private

Definition at line 95 of file DataGetterHelper.h.

Referenced by getByLabel(), getByProductID(), getter(), and setGetter().

boost::shared_ptr<fwlite::HistoryGetterBase> fwlite::DataGetterHelper::historyGetter_
private

Definition at line 94 of file DataGetterHelper.h.

Referenced by history().

std::map<std::pair<edm::ProductID, edm::BranchListIndexes>,boost::shared_ptr<internal::Data> > fwlite::DataGetterHelper::idToData_
mutableprivate

Definition at line 93 of file DataGetterHelper.h.

Referenced by getByProductID().

std::vector<char const*> fwlite::DataGetterHelper::labels_
mutableprivate

Definition at line 90 of file DataGetterHelper.h.

Referenced by getBranchDataFor().

std::auto_ptr<TTreeCache> fwlite::DataGetterHelper::tcache_
mutableprivate

Definition at line 96 of file DataGetterHelper.h.

Referenced by DataGetterHelper(), and getBranchData().

bool fwlite::DataGetterHelper::tcTrained_
mutableprivate

Definition at line 97 of file DataGetterHelper.h.

Referenced by getBranchData().

TTree* fwlite::DataGetterHelper::tree_
private

Definition at line 86 of file DataGetterHelper.h.

Referenced by DataGetterHelper(), getBranchData(), and getBranchDataFor().