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

Member Typedef Documentation

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

Definition at line 126 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(), mps_fire::i, leaves_, ownTheTree_, AlCaHLTBitMon_QueryRunRegistry::string, treeName_, parallelization::uint, NTupler::useTFileService_, and findQualityFiles::v.

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

void VariableNTupler::callBack ( )
inline

Definition at line 123 of file VariableNTupler.h.

Referenced by CompleteNTupler::fill().

123 {}
void VariableNTupler::fill ( edm::Event iEvent)
inlineoverridevirtual

Implements NTupler.

Definition at line 98 of file VariableNTupler.h.

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

Referenced by CompleteNTupler::fill().

98  {
99  if (useTFileService_) {
100  //fill the data holder
101  iterator i = leaves_.begin();
102  iterator i_end = leaves_.end();
103  uint iInDataHolder = 0;
104  for (; i != i_end; ++i, ++iInDataHolder) {
105  dataHolder_[iInDataHolder] = (*i->second)(iEvent);
106  }
107  //fill into root;
108  if (ownTheTree_) {
109  tree_->Fill();
110  }
111  } else {
112  //other leaves
113  iterator i = leaves_.begin();
114  iterator i_end = leaves_.end();
115  for (; i != i_end; ++i) {
116  auto leafValue = std::make_unique<double>((*i->second)(iEvent));
117  std::string lName(i->first);
118  std::replace(lName.begin(), lName.end(), '_', '0');
119  iEvent.put(std::move(leafValue), lName);
120  }
121  }
122  }
std::map< std::string, const CachingVariable * >::iterator iterator
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
TTree * tree_
Definition: NTupler.h:30
std::map< std::string, const CachingVariable * > leaves_
def replace(string, replacements)
bool useTFileService_
Definition: NTupler.h:29
def move(src, dest)
Definition: eostools.py:511
uint VariableNTupler::registerleaves ( edm::ProducesCollector  producesCollector)
inlineoverridevirtual

Implements NTupler.

Definition at line 53 of file VariableNTupler.h.

References dataHolder_, TFileService::file(), mps_fire::i, leaves_, simpleEdmComparison::lName, TFileService::make(), 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().

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

Member Data Documentation

double* VariableNTupler::dataHolder_
protected

Definition at line 131 of file VariableNTupler.h.

Referenced by fill(), and registerleaves().

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

Definition at line 127 of file VariableNTupler.h.

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

bool VariableNTupler::ownTheTree_
protected

Definition at line 129 of file VariableNTupler.h.

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

std::string VariableNTupler::treeName_
protected

Definition at line 130 of file VariableNTupler.h.

Referenced by registerleaves(), and VariableNTupler().