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 19 of file VariableNTupler.h.

Member Typedef Documentation

◆ iterator

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

Definition at line 122 of file VariableNTupler.h.

Constructor & Destructor Documentation

◆ VariableNTupler()

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

Definition at line 21 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.

21  {
22  ownTheTree_ = false;
23  edm::ParameterSet variablePSet = iConfig.getParameter<edm::ParameterSet>("variablesPSet");
24  if (variablePSet.getParameter<bool>("allVariables")) {
27  for (; v != v_end; ++v) {
28  leaves_[v->second->name()] = v->second;
29  }
30  } else {
31  std::vector<std::string> leaves = variablePSet.getParameter<std::vector<std::string> >("leaves");
32  for (uint i = 0; i != leaves.size(); ++i) {
33  leaves_[leaves[i]] = edm::Service<VariableHelperService>()->get().variable(leaves[i]);
34  }
35  }
36  if (variablePSet.exists("useTFileService"))
37  useTFileService_ = variablePSet.getParameter<bool>("useTFileService");
38  else
39  useTFileService_ = iConfig.getParameter<bool>("useTFileService");
40 
41  if (useTFileService_) {
42  if (variablePSet.exists("treeName"))
43  treeName_ = variablePSet.getParameter<std::string>("treeName");
44  else
45  treeName_ = iConfig.getParameter<std::string>("treeName");
46  }
47  }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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:27

Member Function Documentation

◆ callBack()

void VariableNTupler::callBack ( )
inline

Definition at line 119 of file VariableNTupler.h.

Referenced by CompleteNTupler::fill().

119 {}

◆ fill()

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

Implements NTupler.

Definition at line 94 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().

94  {
95  if (useTFileService_) {
96  //fill the data holder
97  iterator i = leaves_.begin();
98  iterator i_end = leaves_.end();
99  uint iInDataHolder = 0;
100  for (; i != i_end; ++i, ++iInDataHolder) {
101  dataHolder_[iInDataHolder] = (*i->second)(iEvent);
102  }
103  //fill into root;
104  if (ownTheTree_) {
105  tree_->Fill();
106  }
107  } else {
108  //other leaves
109  iterator i = leaves_.begin();
110  iterator i_end = leaves_.end();
111  for (; i != i_end; ++i) {
112  auto leafValue = std::make_unique<double>((*i->second)(iEvent));
113  std::string lName(i->first);
114  std::replace(lName.begin(), lName.end(), '_', '0');
115  iEvent.put(std::move(leafValue), lName);
116  }
117  }
118  }
std::map< std::string, const CachingVariable * >::iterator iterator
TTree * tree_
Definition: NTupler.h:28
std::map< std::string, const CachingVariable * > leaves_
def replace(string, replacements)
int iEvent
Definition: GenABIO.cc:224
bool useTFileService_
Definition: NTupler.h:27
def move(src, dest)
Definition: eostools.py:511

◆ registerleaves()

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

Implements NTupler.

Definition at line 49 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().

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

Member Data Documentation

◆ dataHolder_

double* VariableNTupler::dataHolder_
protected

Definition at line 127 of file VariableNTupler.h.

Referenced by fill(), and registerleaves().

◆ leaves_

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

Definition at line 123 of file VariableNTupler.h.

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

◆ ownTheTree_

bool VariableNTupler::ownTheTree_
protected

Definition at line 125 of file VariableNTupler.h.

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

◆ treeName_

std::string VariableNTupler::treeName_
protected

Definition at line 126 of file VariableNTupler.h.

Referenced by registerleaves(), and VariableNTupler().