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.

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

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  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::map< std::string, const CachingVariable * > leaves_
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::string treeName_
std::map< std::string, const CachingVariable * >::const_iterator iterator
bool useTFileService_
Definition: NTupler.h:29

Member Function Documentation

◆ callBack()

void VariableNTupler::callBack ( )
inline

Definition at line 121 of file VariableNTupler.h.

Referenced by CompleteNTupler::fill().

121 {}

◆ fill()

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

Implements NTupler.

Definition at line 96 of file VariableNTupler.h.

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().

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  }
std::map< std::string, const CachingVariable * >::iterator iterator
TTree * tree_
Definition: NTupler.h:30
std::map< std::string, const CachingVariable * > leaves_
def replace(string, replacements)
int iEvent
Definition: GenABIO.cc:224
bool useTFileService_
Definition: NTupler.h:29
def move(src, dest)
Definition: eostools.py:511

◆ registerleaves()

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

Implements NTupler.

Definition at line 51 of file VariableNTupler.h.

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

Referenced by CompleteNTupler::registerleaves().

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  }
std::map< std::string, const CachingVariable * >::iterator iterator
TTree * tree_
Definition: NTupler.h:30
std::map< std::string, const CachingVariable * > leaves_
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
def replace(string, replacements)
std::string treeName_
bool useTFileService_
Definition: NTupler.h:29

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().