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
VariableNTupler Class Reference

#include <VariableNTupler.h>

Inheritance diagram for VariableNTupler:
NTupler

Public Member Functions

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

Protected Types

typedef std::map< std::string,
const CachingVariable * >
::iterator 
iterator
 

Protected Attributes

double * dataHolder_
 
std::map< std::string, const
CachingVariable * > 
leaves_
 
bool ownTheTree_
 
std::string treeName_
 
- Protected Attributes inherited from NTupler
TTree * tree_
 
bool useTFileService_
 

Detailed Description

Definition at line 23 of file VariableNTupler.h.

Member Typedef Documentation

typedef std::map<std::string, const CachingVariable *>::iterator VariableNTupler::iterator
protected

Definition at line 129 of file VariableNTupler.h.

Constructor & Destructor Documentation

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

Definition at line 25 of file VariableNTupler.h.

References edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), i, leaves_, ownTheTree_, AlCaHLTBitMon_QueryRunRegistry::string, treeName_, NTupler::useTFileService_, and findQualityFiles::v.

25  {
26  ownTheTree_=false;
27  edm::ParameterSet variablePSet=iConfig.getParameter<edm::ParameterSet>("variablesPSet");
28  if (variablePSet.getParameter<bool>("allVariables"))
29  {
32  for(;v!=v_end;++v){
33  leaves_[v->second->name()]=v->second;
34  }
35  }
36  else{
37  std::vector<std::string> leaves=variablePSet.getParameter<std::vector<std::string> >("leaves");
38  for (uint i=0;i!=leaves.size();++i){
39  leaves_[leaves[i]]= edm::Service<VariableHelperService>()->get().variable(leaves[i]);
40  }
41  }
42  if (variablePSet.exists("useTFileService"))
43  useTFileService_=variablePSet.getParameter<bool>("useTFileService");
44  else
45  useTFileService_=iConfig.getParameter<bool>("useTFileService");
46 
47  if (useTFileService_){
48  if (variablePSet.exists("treeName"))
49  treeName_=variablePSet.getParameter<std::string>("treeName");
50  else
51  treeName_=iConfig.getParameter<std::string>("treeName");
52  }
53  }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string treeName_
std::map< std::string, const CachingVariable * > leaves_
bool useTFileService_
Definition: NTupler.h:29
std::map< std::string, const CachingVariable * >::const_iterator iterator

Member Function Documentation

void VariableNTupler::callBack ( )
inline

Definition at line 126 of file VariableNTupler.h.

Referenced by CompleteNTupler::fill().

126 {}
void VariableNTupler::fill ( edm::Event iEvent)
inlinevirtual

Implements NTupler.

Definition at line 101 of file VariableNTupler.h.

References dataHolder_, i, leaves_, ownTheTree_, edm::Event::put(), python.rootplot.root2matplotlib::replace(), AlCaHLTBitMon_QueryRunRegistry::string, NTupler::tree_, and NTupler::useTFileService_.

Referenced by CompleteNTupler::fill().

101  {
102  if (useTFileService_){
103  //fill the data holder
104  iterator i=leaves_.begin();
105  iterator i_end=leaves_.end();
106  uint iInDataHolder=0;
107  for(;i!=i_end;++i,++iInDataHolder){
108  dataHolder_[iInDataHolder]=(*i->second)(iEvent);
109  }
110  //fill into root;
111  if (ownTheTree_) {
112  tree_->Fill();
113  }
114  }else{
115  //other leaves
116  iterator i=leaves_.begin();
117  iterator i_end=leaves_.end();
118  for(;i!=i_end;++i){
119  std::auto_ptr<double> leafValue(new double((*i->second)(iEvent)));
120  std::string lName(i->first);
121  std::replace(lName.begin(), lName.end(),'_','0');
122  iEvent.put(leafValue, lName.c_str());
123  }
124  }
125  }
int i
Definition: DBlmapReader.cc:9
TTree * tree_
Definition: NTupler.h:30
std::map< std::string, const CachingVariable * >::iterator iterator
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
std::map< std::string, const CachingVariable * > leaves_
bool useTFileService_
Definition: NTupler.h:29
uint VariableNTupler::registerleaves ( edm::ProducerBase producer)
inlinevirtual

Implements NTupler.

Definition at line 55 of file VariableNTupler.h.

References dataHolder_, TFileService::file(), i, leaves_, TFileService::make(), dbtoconf::object, ownTheTree_, edm::ProductRegistryHelper::produces(), python.rootplot.root2matplotlib::replace(), AlCaHLTBitMon_QueryRunRegistry::string, NTupler::tree_, treeName_, and NTupler::useTFileService_.

Referenced by CompleteNTupler::registerleaves().

55  {
56  uint nLeaves=0;
57  if (useTFileService_){
58  //loop the leaves registered
59  nLeaves=leaves_.size();
60  // make arrays of pointer to the actual values
61  dataHolder_=new double[nLeaves];
62  iterator i=leaves_.begin();
63  iterator i_end= leaves_.end();
65  if (ownTheTree_){
66  ownTheTree_=true;
67  tree_=fs->make<TTree>(treeName_.c_str(),"VariableNTupler tree");
68  }else{
69  TObject * object = fs->file().Get(treeName_.c_str());
70  if (!object){
71  ownTheTree_=true;
72  tree_=fs->make<TTree>(treeName_.c_str(),"VariableNTupler tree");
73  }
74  else{
75  tree_=dynamic_cast<TTree*>(object);
76  if (!tree_){
77  ownTheTree_=true;
78  tree_=fs->make<TTree>(treeName_.c_str(),"VariableNTupler tree");
79  }
80  else ownTheTree_=false;
81  }
82  }
83  uint iInDataHolder=0;
84  for(;i!=i_end;++i,++iInDataHolder){
85  tree_->Branch(i->first.c_str(), &(dataHolder_[iInDataHolder]), (i->first+"/D").c_str());
86  }
87  }else{
88  //loop the leaves registered
89  iterator i=leaves_.begin();
90  iterator i_end= leaves_.end();
91  for(;i!=i_end;++i){
92  nLeaves++;
93  std::string lName(i->first);
94  std::replace(lName.begin(), lName.end(), '_','0');
95  producer->produces<double>(lName.c_str()).setBranchAlias(i->first);
96  }
97  }
98  return nLeaves;
99  }
int i
Definition: DBlmapReader.cc:9
TTree * tree_
Definition: NTupler.h:30
std::string treeName_
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::map< std::string, const CachingVariable * >::iterator iterator
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
std::map< std::string, const CachingVariable * > leaves_
list object
Definition: dbtoconf.py:77
bool useTFileService_
Definition: NTupler.h:29

Member Data Documentation

double* VariableNTupler::dataHolder_
protected

Definition at line 134 of file VariableNTupler.h.

Referenced by fill(), and registerleaves().

std::map<std::string, const CachingVariable *> VariableNTupler::leaves_
protected

Definition at line 130 of file VariableNTupler.h.

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

bool VariableNTupler::ownTheTree_
protected

Definition at line 132 of file VariableNTupler.h.

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

std::string VariableNTupler::treeName_
protected

Definition at line 133 of file VariableNTupler.h.

Referenced by registerleaves(), and VariableNTupler().