15 #include "Reflex/Type.h"
16 #include "Reflex/Object.h"
17 #include "Reflex/Member.h"
23 #include "TTreeCache.h"
33 #define TTCACHE_SIZE 20*1024*1024
55 typedef std::map<internal::DataKey, boost::shared_ptr<internal::Data> >
DataMap;
63 boost::shared_ptr<HistoryGetterBase> historyGetter,
64 boost::shared_ptr<BranchMapReader> branchMap,
65 boost::shared_ptr<edm::EDProductGetter> getter,
67 branchMap_(branchMap),
68 historyGetter_(historyGetter),
74 throw cms::Exception(
"NoTree")<<
"The TTree pointer passed to the constructor was null";
80 tcache_.reset(dynamic_cast<TTreeCache*>(iFile->GetCacheRead()));
81 iFile->SetCacheRead(0);
121 TBranch*
findBranch(TTree* iTree, std::string
const& iMainLabels, std::string
const& iProcess) {
122 std::string branchName(iMainLabels);
123 branchName+=iProcess;
126 return iTree->GetBranch(branchName.c_str());
139 Reflex::Object
obj = iData.
obj_;
140 iData.
obj_ = iData.
obj_.TypeOf().Construct();
151 iData.
branch_->GetEntry(index);
159 tree_->LoadTree(index);
160 iData.
branch_->GetEntry(index);
168 char const* iModuleLabel,
169 char const* iProductInstanceLabel,
170 char const* iProcessLabel)
const
175 boost::shared_ptr<internal::Data> theData;
176 DataMap::iterator itFind =
data_.find(key);
177 if(itFind ==
data_.end()) {
179 std::string
const sep(
"_");
183 name +=sep+std::string(key.
product())+sep;
186 std::string foundProcessLabel;
189 if (0==iProcessLabel || iProcessLabel==key.
kEmpty() ||
190 strlen(iProcessLabel)==0) {
191 std::string
const* lastLabel=0;
198 lastLabel = &(iproc->processName());
209 internal::DataKey fullKey(type,iModuleLabel,iProductInstanceLabel,lastLabel->c_str());
210 itFind =
data_.find(fullKey);
211 if(itFind !=
data_.end()) {
213 theData = itFind->second;
216 foundProcessLabel = *lastLabel;
228 size_t moduleLabelLen = strlen(iModuleLabel)+1;
229 char* newModule =
new char[moduleLabelLen];
230 std::strncpy(newModule,iModuleLabel,moduleLabelLen);
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);
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);
249 if(0 == theData.get()) {
255 throw cms::Exception(
"UnknownType")<<
"No Reflex dictionary exists for type "<<iInfo.name();
257 Reflex::Object
obj = rType.Construct();
259 if(obj.Address() == 0) {
260 throw cms::Exception(
"ConstructionFailed")<<
"failed to construct an instance of "<<rType.Name();
263 newData->branch_ = branch;
265 newData->lastProduct_=-1;
266 newData->pObj_ = obj.Address();
268 branch->SetAddress(&(newData->pObj_));
269 newData->interface_ = 0;
270 Reflex::Member getTheInterface = rType.FunctionMemberByName(std::string(
"getInterface"));
271 getTheInterface.Invoke(newData->interface_);
274 itFind =
data_.insert(std::make_pair(newKey, theData)).first;
276 if(foundProcessLabel.size()) {
278 newProcess =
new char[foundProcessLabel.size()+1];
279 std::strcpy(newProcess,foundProcessLabel.c_str());
283 data_.insert(std::make_pair(newKey,theData));
286 return *(itFind->second);
291 char const* iModuleLabel,
292 char const* iProductInstanceLabel,
293 char const* iProcessLabel)
const
299 return std::string(theData.
branch_->GetName());
301 return std::string(
"");
306 char const* iModuleLabel,
307 char const* iProductInstanceLabel,
308 char const* iProcessLabel,
309 void* oData, Long_t
index)
const
312 void** pOData =
reinterpret_cast<void**
>(oData);
323 *pOData = theData.
obj_.Address();
326 if (0 == *pOData)
return false;
332 char const* iModuleLabel,
333 char const* iProductInstanceLabel,
334 char const* iProcessLabel,
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);
381 KeyToDataMap::iterator itData =
data_.find(
k);
382 if(
data_.end() == itData) {
394 assert(itData !=
data_.end());
395 assert(holder.
wrapper() == itData->second->obj_.Address());
397 itFound =
idToData_.insert(std::make_pair(theID,itData->second)).first;
399 if(index != itFound->second->lastProduct_) {
403 if(0==itFound->second->pProd_) {
404 itFound->second->pProd_ = itFound->second->obj_.Address();
406 if(0==itFound->second->pProd_) {
427 <<
"'\n productInstance='"<<((0!=iProduct)?iProduct:
"")<<
"'\n process='"<<((0!=iProcess)?iProcess:
"")<<
"'\n"
428 "but no data is available for this Lumi";
const_reverse_iterator rbegin() const
static TBranch * findBranch(TTree *iTree, std::string const &iMainLabels, std::string const &iProcess)
std::map< std::pair< edm::ProductID, edm::BranchListIndexes >, boost::shared_ptr< internal::Data > > idToData_
std::vector< char const * > labels_
collection_type::const_reverse_iterator const_reverse_iterator
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
std::string const & processName() const
char const * product() const
char const * kEmpty() const
char const * module() const
const edm::ProcessHistory & history() const
boost::shared_ptr< edm::EDProductGetter > getter_
std::map< internal::DataKey, boost::shared_ptr< internal::Data > > DataMap
const_reverse_iterator rend() const
std::string const & moduleLabel() const
std::string const & productInstanceName() const
static void throwProductNotFoundException(std::type_info const &, char const *, char const *, char const *)
static internal::Data branchNotFound
edm::WrapperInterfaceBase * interface_
std::auto_ptr< TTreeCache > tcache_
BranchID const & branchID() const
virtual ~DataGetterHelper()
std::string className() const
std::string const & fullClassName() const
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
std::string wrappedClassName(std::string const &iFullName)
void getBranchData(edm::EDProductGetter *, Long64_t, internal::Data &) const
char const * process() const
internal::Data & getBranchDataFor(std::type_info const &, char const *, char const *, char const *) const
boost::shared_ptr< BranchMapReader > branchMap_
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *, Long_t) const
withTCache(TFile *file, TTreeCache *tc)
void const * wrapper() const
edm::WrapperHolder getByProductID(edm::ProductID const &, Long_t) const
boost::shared_ptr< fwlite::HistoryGetterBase > historyGetter_
std::string friendlyClassName() const