CMS 3D CMS Logo

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) override
 
uint registerleaves (edm::ProducesCollector producesCollector) override
 
 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 21 of file VariableNTupler.h.

Member Typedef Documentation

◆ iterator

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

Definition at line 124 of file VariableNTupler.h.

Constructor & Destructor Documentation

◆ VariableNTupler()

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

Definition at line 23 of file VariableNTupler.h.

23  {
24  ownTheTree_ = false;
25  edm::ParameterSet variablePSet = iConfig.getParameter<edm::ParameterSet>("variablesPSet");
26  if (variablePSet.getParameter<bool>("allVariables")) {
29  for (; v != v_end; ++v) {
30  leaves_[v->second->name()] = v->second;
31  }
32  } else {
33  std::vector<std::string> leaves = variablePSet.getParameter<std::vector<std::string> >("leaves");
34  for (uint i = 0; i != leaves.size(); ++i) {
35  leaves_[leaves[i]] = edm::Service<VariableHelperService>()->get().variable(leaves[i]);
36  }
37  }
38  if (variablePSet.exists("useTFileService"))
39  useTFileService_ = variablePSet.getParameter<bool>("useTFileService");
40  else
41  useTFileService_ = iConfig.getParameter<bool>("useTFileService");
42 
43  if (useTFileService_) {
44  if (variablePSet.exists("treeName"))
45  treeName_ = variablePSet.getParameter<std::string>("treeName");
46  else
47  treeName_ = iConfig.getParameter<std::string>("treeName");
48  }
49  }

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

Member Function Documentation

◆ callBack()

void VariableNTupler::callBack ( )
inline

Definition at line 121 of file VariableNTupler.h.

121 {}

Referenced by CompleteNTupler::fill().

◆ fill()

void VariableNTupler::fill ( edm::Event iEvent)
inlineoverridevirtual

Implements NTupler.

Definition at line 96 of file VariableNTupler.h.

96  {
97  if (useTFileService_) {
98  //fill the data holder
99  iterator i = leaves_.begin();
100  iterator i_end = leaves_.end();
101  uint iInDataHolder = 0;
102  for (; i != i_end; ++i, ++iInDataHolder) {
103  dataHolder_[iInDataHolder] = (*i->second)(iEvent);
104  }
105  //fill into root;
106  if (ownTheTree_) {
107  tree_->Fill();
108  }
109  } else {
110  //other leaves
111  iterator i = leaves_.begin();
112  iterator i_end = leaves_.end();
113  for (; i != i_end; ++i) {
114  auto leafValue = std::make_unique<double>((*i->second)(iEvent));
115  std::string lName(i->first);
116  std::replace(lName.begin(), lName.end(), '_', '0');
117  iEvent.put(std::move(leafValue), lName);
118  }
119  }
120  }

References dataHolder_, mps_fire::i, iEvent, leaves_, simpleEdmComparison::lName, eostools::move(), ownTheTree_, python.rootplot.root2matplotlib::replace(), AlCaHLTBitMon_QueryRunRegistry::string, NTupler::tree_, parallelization::uint, and NTupler::useTFileService_.

Referenced by CompleteNTupler::fill().

◆ registerleaves()

uint VariableNTupler::registerleaves ( edm::ProducesCollector  producesCollector)
inlineoverridevirtual

Implements NTupler.

Definition at line 51 of file VariableNTupler.h.

51  {
52  uint nLeaves = 0;
53  if (useTFileService_) {
54  //loop the leaves registered
55  nLeaves = leaves_.size();
56  // make arrays of pointer to the actual values
57  dataHolder_ = new double[nLeaves];
58  iterator i = leaves_.begin();
59  iterator i_end = leaves_.end();
61  if (ownTheTree_) {
62  ownTheTree_ = true;
63  tree_ = fs->make<TTree>(treeName_.c_str(), "VariableNTupler tree");
64  } else {
65  TObject* object = fs->file().Get(treeName_.c_str());
66  if (!object) {
67  ownTheTree_ = true;
68  tree_ = fs->make<TTree>(treeName_.c_str(), "VariableNTupler tree");
69  } else {
70  tree_ = dynamic_cast<TTree*>(object);
71  if (!tree_) {
72  ownTheTree_ = true;
73  tree_ = fs->make<TTree>(treeName_.c_str(), "VariableNTupler tree");
74  } else
75  ownTheTree_ = false;
76  }
77  }
78  uint iInDataHolder = 0;
79  for (; i != i_end; ++i, ++iInDataHolder) {
80  tree_->Branch(i->first.c_str(), &(dataHolder_[iInDataHolder]), (i->first + "/D").c_str());
81  }
82  } else {
83  //loop the leaves registered
84  iterator i = leaves_.begin();
85  iterator i_end = leaves_.end();
86  for (; i != i_end; ++i) {
87  nLeaves++;
88  std::string lName(i->first);
89  std::replace(lName.begin(), lName.end(), '_', '0');
90  producesCollector.produces<double>(lName).setBranchAlias(i->first);
91  }
92  }
93  return nLeaves;
94  }

References dataHolder_, TFileService::file(), mps_fire::i, leaves_, simpleEdmComparison::lName, TFileService::make(), ownTheTree_, edm::ProducesCollector::produces(), python.rootplot.root2matplotlib::replace(), AlCaHLTBitMon_QueryRunRegistry::string, NTupler::tree_, treeName_, parallelization::uint, and NTupler::useTFileService_.

Referenced by CompleteNTupler::registerleaves().

Member Data Documentation

◆ dataHolder_

double* VariableNTupler::dataHolder_
protected

Definition at line 129 of file VariableNTupler.h.

Referenced by fill(), and registerleaves().

◆ leaves_

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

Definition at line 125 of file VariableNTupler.h.

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

◆ ownTheTree_

bool VariableNTupler::ownTheTree_
protected

Definition at line 127 of file VariableNTupler.h.

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

◆ treeName_

std::string VariableNTupler::treeName_
protected

Definition at line 128 of file VariableNTupler.h.

Referenced by registerleaves(), and VariableNTupler().

mps_fire.i
i
Definition: mps_fire.py:355
VariableNTupler::ownTheTree_
bool ownTheTree_
Definition: VariableNTupler.h:127
TFileService::file
TFile & file() const
return opened TFile
Definition: TFileService.h:37
VariableNTupler::dataHolder_
double * dataHolder_
Definition: VariableNTupler.h:129
findQualityFiles.v
v
Definition: findQualityFiles.py:179
parallelization.uint
uint
Definition: parallelization.py:124
VariableHelper::iterator
std::map< std::string, const CachingVariable * >::const_iterator iterator
Definition: VariableHelper.h:19
simpleEdmComparison.lName
lName
Definition: simpleEdmComparison.py:125
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:674
edm::ParameterSet
Definition: ParameterSet.h:36
edm::Service
Definition: Service.h:30
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::ProducesCollector::produces
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
Definition: ProducesCollector.h:52
VariableNTupler::iterator
std::map< std::string, const CachingVariable * >::iterator iterator
Definition: VariableNTupler.h:124
NTupler::tree_
TTree * tree_
Definition: NTupler.h:30
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
NTupler::useTFileService_
bool useTFileService_
Definition: NTupler.h:29
eostools.move
def move(src, dest)
Definition: eostools.py:511
VariableNTupler::leaves_
std::map< std::string, const CachingVariable * > leaves_
Definition: VariableNTupler.h:125
VariableNTupler::treeName_
std::string treeName_
Definition: VariableNTupler.h:128
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444