CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Types | Protected Attributes
StringBasedNTupler Class Reference

#include <StringBasedNTupler.h>

Inheritance diagram for StringBasedNTupler:
NTupler

Public Member Functions

void callBack ()
 
void fill (edm::Event &iEvent)
 
uint registerleaves (edm::ProducerBase *producer)
 
 StringBasedNTupler (const edm::ParameterSet &iConfig)
 
 ~StringBasedNTupler ()
 
- Public Member Functions inherited from NTupler
 NTupler ()
 
virtual ~NTupler ()
 

Protected Types

typedef std::map< std::string,
std::vector< TreeBranch > > 
Branches
 

Protected Attributes

Branches branches_
 
uint * bunchCrossing_
 
uint64_t * ev_
 
uint * experimentType_
 
uint * indexDataHolder_
 
uint * lumiblock_
 
std::string * model_params_
 
uint * orbitNumber_
 
bool ownTheTree_
 
uint * run_
 
std::string treeName_
 
float * weight_
 
- Protected Attributes inherited from NTupler
TTree * tree_
 
bool useTFileService_
 

Detailed Description

Definition at line 203 of file StringBasedNTupler.h.

Member Typedef Documentation

typedef std::map<std::string, std::vector<TreeBranch> > StringBasedNTupler::Branches
protected

Definition at line 486 of file StringBasedNTupler.h.

Constructor & Destructor Documentation

StringBasedNTupler::StringBasedNTupler ( const edm::ParameterSet iConfig)
inline

Definition at line 207 of file StringBasedNTupler.h.

References b, branches_, bunchCrossing_, className(), ev_, edm::ParameterSet::exists(), experimentType_, plotBeamSpotDB::first, edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNamesForType(), edm::ParameterSet::getParameterSetNames(), edm::ParameterSet::getUntrackedParameter(), prof2calltree::l, lumiblock_, model_params_, mergeVDriftHistosByStation::name, orbitNumber_, ownTheTree_, run_, edm::second(), corrVsCorr::selection, cmsHarvester::sep, alcazmumu_cfi::src, AlCaHLTBitMon_QueryRunRegistry::string, treeName_, NTupler::useTFileService_, and weight_.

207  {
208 
209 
210 
211  edm::ParameterSet branchesPSet = iConfig.getParameter<edm::ParameterSet>("branchesPSet");
212  std::vector<std::string> branches;
213  branchesPSet.getParameterSetNames(branches);
214  const std::string separator = branchesPSet.getUntrackedParameter<std::string>("separator",":");
215  for (uint b=0;b!=branches.size();++b){
216  edm::ParameterSet bPSet = branchesPSet.getParameter<edm::ParameterSet>(branches[b]);
218  if (bPSet.exists("class"))
219  className=bPSet.getParameter<std::string>("class");
220  else
221  className=bPSet.getParameter<std::string>("Class");
223  edm::ParameterSet leavesPSet=bPSet.getParameter<edm::ParameterSet>("leaves");
224  std::string order = "";
225  if (bPSet.exists("order")) order = bPSet.getParameter<std::string>("order");
226  std::string selection = "";
227  if (bPSet.exists("selection")) selection = bPSet.getParameter<std::string>("selection");
228  // do it one by one with configuration [string x = "x"]
229  std::vector<std::string> leaves=leavesPSet.getParameterNamesForType<std::string>();
230  std::string maxName="N"+branches[b];
231  for (uint l=0;l!=leaves.size();++l){
232  std::string leave_expr=leavesPSet.getParameter<std::string>(leaves[l]);
233  std::string branchAlias=branches[b]+"_"+leaves[l];
234 
235  //add a branch manager for this expression on this collection
236  branches_[maxName].push_back(TreeBranch(className, src, leave_expr, order, selection, maxName, branchAlias));
237  }//loop the provided leaves
238 
239  //do it once with configuration [vstring vars = { "x:x" ,... } ] where ":"=separator
240  if (leavesPSet.exists("vars")){
241  std::vector<std::string> leavesS = leavesPSet.getParameter<std::vector<std::string> >("vars");
242  for (uint l=0;l!=leavesS.size();++l){
243  uint sep=leavesS[l].find(separator);
244  std::string name=leavesS[l].substr(0,sep);
245  //removes spaces from the variable name
246  /*uint*/int space = name.find(" ");
247  while (space!=-1/*std::string::npos*/){
248  std::string first = name.substr(0,space);
249  std::string second = name.substr(space+1);
250  name = first+second;
251  space = name.find(" ");
252  }
253  std::string expr=leavesS[l].substr(sep+1);
254  std::string branchAlias=branches[b]+"_"+name;
255 
256  //add a branch manager for this expression on this collection
257  branches_[maxName].push_back(TreeBranch(className, src, expr, order, selection, maxName, branchAlias));
258  }
259  }
260 
261  }//loop the provided branches
262 
263 
264 
265 
266  ev_ = new uint64_t;
267  run_ = new uint;
268  lumiblock_ = new uint;
269  experimentType_ = new uint;
270  bunchCrossing_ = new uint;
271  orbitNumber_ = new uint;
272  weight_ = new float;
274 
275 
276  if (branchesPSet.exists("useTFileService"))
277  useTFileService_=branchesPSet.getParameter<bool>("useTFileService");
278  else
279  useTFileService_=iConfig.getParameter<bool>("useTFileService");
280 
281  if (useTFileService_){
282  if (branchesPSet.exists("treeName")){
283  treeName_=branchesPSet.getParameter<std::string>("treeName");
284  ownTheTree_=true;
285  }
286  else{
287  treeName_=iConfig.getParameter<std::string>("treeName");
288  ownTheTree_=false;
289  }
290  }
291  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
selection
main part
Definition: corrVsCorr.py:98
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:194
std::string * model_params_
U second(std::pair< T, U > const &p)
unsigned long long uint64_t
Definition: Time.h:15
double b
Definition: hdecay.h:120
bool useTFileService_
Definition: NTupler.h:29
size_t getParameterSetNames(std::vector< std::string > &output, bool trackiness=true) const
std::string className(const T &t)
Definition: ClassName.h:30
StringBasedNTupler::~StringBasedNTupler ( )
inline

Definition at line 473 of file StringBasedNTupler.h.

References bunchCrossing_, ev_, experimentType_, indexDataHolder_, lumiblock_, model_params_, orbitNumber_, run_, and weight_.

473  {
474  delete indexDataHolder_;
475  delete ev_;
476  delete run_;
477  delete lumiblock_;
478  delete experimentType_;
479  delete bunchCrossing_;
480  delete orbitNumber_;
481  delete weight_;
482  delete model_params_;
483  }
std::string * model_params_

Member Function Documentation

void StringBasedNTupler::callBack ( )
inline

Definition at line 456 of file StringBasedNTupler.h.

References b, branches_, TreeBranch::dataHolderPtr(), and NTupler::useTFileService_.

Referenced by CompleteNTupler::fill().

457  {
458  if (useTFileService_){
459  Branches::iterator iB=branches_.begin();
460  Branches::iterator iB_end=branches_.end();
461  //de-allocate memory now: allocated in branch(...) and released to the pointer.
462  for(;iB!=iB_end;++iB){
463  std::vector<TreeBranch>::iterator iL=iB->second.begin();
464  std::vector<TreeBranch>::iterator iL_end=iB->second.end();
465  for(;iL!=iL_end;++iL){
466  TreeBranch & b=*iL;
467  delete b.dataHolderPtr();
468  }
469  }
470  }
471  }
std::vector< float > * dataHolderPtr()
double b
Definition: hdecay.h:120
bool useTFileService_
Definition: NTupler.h:29
void StringBasedNTupler::fill ( edm::Event iEvent)
inlinevirtual

Implements NTupler.

Definition at line 372 of file StringBasedNTupler.h.

References TreeBranch::assignDataHolderPtr(), b, TreeBranch::branch(), branches_, TreeBranch::branchName(), edm::EventBase::bunchCrossing(), bunchCrossing_, ev_, edm::EventID::event(), edm::EventBase::experimentType(), experimentType_, newFWLiteAna::found, edm::Event::getByLabel(), edm::EventBase::id(), indexDataHolder_, edm::EventBase::isRealData(), lumiblock_, edm::EventBase::luminosityBlock(), model_params_, edm::EventBase::orbitNumber(), orbitNumber_, ownTheTree_, edm::Event::put(), edm::EventID::run(), run_, NTupler::tree_, NTupler::useTFileService_, and weight_.

Referenced by CompleteNTupler::fill().

372  {
373  // if (!edm::Service<UpdaterService>()->checkOnce("StringBasedNTupler::fill")) return;
374  //well if you do that, you cannot have two ntupler of the same type in the same job...
375 
376  if (useTFileService_){
377  // loop the automated leafer
378  Branches::iterator iB=branches_.begin();
379  Branches::iterator iB_end=branches_.end();
380  uint indexOfIndexInDataHolder=0;
381  for(;iB!=iB_end;++iB,++indexOfIndexInDataHolder){
382  std::vector<TreeBranch>::iterator iL=iB->second.begin();
383  std::vector<TreeBranch>::iterator iL_end=iB->second.end();
384  uint maxS=0;
385  for(;iL!=iL_end;++iL){
386  TreeBranch & b=*iL;
387  // grab the vector of values from the interpretation of expression for the associated collection
388  std::auto_ptr<std::vector<float> > branch(b.branch(iEvent));
389  // calculate the maximum index size.
390  if (branch->size()>maxS) maxS=branch->size();
391  // transfer of (no copy) pointer to the vector of float from the auto_ptr to the tree data pointer
392  b.assignDataHolderPtr(branch.release());
393  // for memory tracing, object b is holding the data (not auto_ptr) and should delete it for each event (that's not completely optimum)
394  }
395  //assigne the maximum vector size for this collection
396  indexDataHolder_[indexOfIndexInDataHolder]=maxS;
397  }
398 
399  //fill event info.
400  *run_ = iEvent.id().run();
401  *ev_ = iEvent.id().event();
402  // *lumiblock_ = iEvent.id().luminosityBlock();
403  *lumiblock_ = iEvent.luminosityBlock();
404  *experimentType_ = iEvent.experimentType();
405  *bunchCrossing_ = iEvent.bunchCrossing();
406  *orbitNumber_ = iEvent.orbitNumber();
407 
408  *weight_ = 1;
409  if(!iEvent.isRealData()) {
410  edm::Handle<GenEventInfoProduct> wgeneventinfo;
411  iEvent.getByLabel("generator", wgeneventinfo);
412  *weight_ = wgeneventinfo->weight();
413  }
414 
415  typedef std::vector<std::string>::const_iterator comments_const_iterator;
416 // using namespace edm;
417 
419  *model_params_ = "NULL";
420  if(iEvent.getByLabel("source", product)) {
421  comments_const_iterator c_begin = product->comments_begin();
422  comments_const_iterator c_end = product->comments_end();
423 
424  for( comments_const_iterator cit=c_begin; cit!=c_end; ++cit) {
425  size_t found = (*cit).find("model");
426  if( found != std::string::npos) {
427  //std::cout << *cit << std::endl;
428  *model_params_ = *cit;
429  }
430  }
431  }
432 
433 
434  if (ownTheTree_){ tree_->Fill(); }
435  }else{
436  // loop the automated leafer
437  Branches::iterator iB=branches_.begin();
438  Branches::iterator iB_end=branches_.end();
439  for(;iB!=iB_end;++iB){
440  std::vector<TreeBranch>::iterator iL=iB->second.begin();
441  std::vector<TreeBranch>::iterator iL_end=iB->second.end();
442  uint maxS=0;
443  for(;iL!=iL_end;++iL){
444  TreeBranch & b=*iL;
445  std::auto_ptr<std::vector<float> > branch(b.branch(iEvent));
446  if (branch->size()>maxS) maxS=branch->size();
447  iEvent.put(branch, b.branchName());
448  }
449  //index should be put only once per branch. doe not really mattter for edm root files
450  std::auto_ptr<uint> maxN(new uint(maxS));
451  iEvent.put(maxN, iB->first);
452  }
453  }
454  }
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
TTree * tree_
Definition: NTupler.h:30
const std::string branchName() const
value branch(const edm::Event &iEvent)
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
bool isRealData() const
Definition: EventBase.h:64
std::string * model_params_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
int orbitNumber() const
Definition: EventBase.h:67
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
void assignDataHolderPtr(std::vector< float > *data)
double b
Definition: hdecay.h:120
edm::EventID id() const
Definition: EventBase.h:60
edm::EventAuxiliary::ExperimentType experimentType() const
Definition: EventBase.h:65
bool useTFileService_
Definition: NTupler.h:29
uint StringBasedNTupler::registerleaves ( edm::ProducerBase producer)
inlinevirtual

Implements NTupler.

Definition at line 295 of file StringBasedNTupler.h.

References b, beamvalidation::br, TreeBranch::branchAlias(), branches_, TreeBranch::branchName(), TreeBranch::branchTitle(), bunchCrossing_, ev_, experimentType_, TFileService::file(), indexDataHolder_, lumiblock_, TFileService::make(), model_params_, dbtoconf::object, orbitNumber_, ownTheTree_, edm::ProductRegistryHelper::produces(), run_, NTupler::tree_, treeName_, NTupler::useTFileService_, and weight_.

Referenced by CompleteNTupler::registerleaves().

295  {
296  uint nLeaves=0;
297 
298  if (useTFileService_){
300  if (ownTheTree_){
301  ownTheTree_=true;
302  tree_=fs->make<TTree>(treeName_.c_str(),"StringBasedNTupler tree");
303  }else{
304  TObject * object = fs->file().Get(treeName_.c_str());
305  if (!object){
306  ownTheTree_=true;
307  tree_=fs->make<TTree>(treeName_.c_str(),"StringBasedNTupler tree");
308  }
309  else{
310  tree_=dynamic_cast<TTree*>(object);
311  if (!tree_){
312  ownTheTree_=true;
313  tree_=fs->make<TTree>(treeName_.c_str(),"StringBasedNTupler tree");
314  }
315  else ownTheTree_=false;
316  }
317  }
318 
319  //reserve memory for the indexes
320  indexDataHolder_ = new uint[branches_.size()];
321  // loop the automated leafer
322  Branches::iterator iB=branches_.begin();
323  Branches::iterator iB_end=branches_.end();
324  uint indexOfIndexInDataHolder=0;
325  for(;iB!=iB_end;++iB,++indexOfIndexInDataHolder){
326  //create a branch for the index: an integer
327  tree_->Branch(iB->first.c_str(), &(indexDataHolder_[indexOfIndexInDataHolder]),(iB->first+"/i").c_str());
328  //loop on the "leaves"
329  std::vector<TreeBranch>::iterator iL=iB->second.begin();
330  std::vector<TreeBranch>::iterator iL_end=iB->second.end();
331  for(;iL!=iL_end;++iL){
332  TreeBranch & b=*iL;
333  //create a branch for the leaves: vector of floats
334  TBranch * br = tree_->Branch(b.branchAlias().c_str(),"std::vector<float>",iL->dataHolderPtrAdress());
335  br->SetTitle(b.branchTitle().c_str());
336  nLeaves++;
337  }
338  }
339 
340  //extra leaves for event info.
341  tree_->Branch("run",run_,"run/i");
342  tree_->Branch("event",ev_,"event/l");
343  tree_->Branch("lumiblock",lumiblock_,"lumiblock/i");
344  tree_->Branch("experimentType",experimentType_,"experimentType/i");
345  tree_->Branch("bunchCrossing",bunchCrossing_,"bunchCrossing/i");
346  tree_->Branch("orbitNumber",orbitNumber_,"orbitNumber/i");
347  tree_->Branch("weight",weight_,"weight/f");
348  tree_->Branch("model_params",&model_params_);
349 
350  }
351  else{
352  // loop the automated leafer
353  Branches::iterator iB=branches_.begin();
354  Branches::iterator iB_end=branches_.end();
355  for(;iB!=iB_end;++iB){
356  //the index. should produce it only once
357  // a simple uint for the index
358  producer->produces<uint>(iB->first).setBranchAlias(iB->first);
359  std::vector<TreeBranch>::iterator iL=iB->second.begin();
360  std::vector<TreeBranch>::iterator iL_end=iB->second.end();
361  for(;iL!=iL_end;++iL){
362  TreeBranch & b=*iL;
363  //a vector of float for each leave
364  producer->produces<std::vector<float> >(b.branchName()).setBranchAlias(b.branchAlias());
365  nLeaves++;
366  }
367  }
368  }
369  return nLeaves;
370  }
const std::string & branchTitle() const
TTree * tree_
Definition: NTupler.h:30
const std::string & branchAlias() const
const std::string branchName() const
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::string * model_params_
TypeLabelItem const & produces()
declare what type of product will make and with which optional label
TFile & file() const
return opened TFile
Definition: TFileService.h:37
double b
Definition: hdecay.h:120
list object
Definition: dbtoconf.py:77
bool useTFileService_
Definition: NTupler.h:29

Member Data Documentation

Branches StringBasedNTupler::branches_
protected

Definition at line 487 of file StringBasedNTupler.h.

Referenced by callBack(), fill(), registerleaves(), and StringBasedNTupler().

uint* StringBasedNTupler::bunchCrossing_
protected
uint64_t* StringBasedNTupler::ev_
protected
uint* StringBasedNTupler::experimentType_
protected
uint* StringBasedNTupler::indexDataHolder_
protected

Definition at line 491 of file StringBasedNTupler.h.

Referenced by fill(), registerleaves(), and ~StringBasedNTupler().

uint* StringBasedNTupler::lumiblock_
protected
std::string* StringBasedNTupler::model_params_
protected
uint* StringBasedNTupler::orbitNumber_
protected
bool StringBasedNTupler::ownTheTree_
protected

Definition at line 489 of file StringBasedNTupler.h.

Referenced by fill(), registerleaves(), and StringBasedNTupler().

uint* StringBasedNTupler::run_
protected
std::string StringBasedNTupler::treeName_
protected

Definition at line 490 of file StringBasedNTupler.h.

Referenced by registerleaves(), and StringBasedNTupler().

float* StringBasedNTupler::weight_
protected