CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Private Attributes
StringBranchHelper< Object, Collection > Class Template Reference

#include <StringBasedNTupler.h>

Public Types

typedef TreeBranch::value value
 

Public Member Functions

value operator() ()
 
 StringBranchHelper (const TreeBranch &B, const edm::Event &iEvent)
 

Private Attributes

value value_
 

Detailed Description

template<typename Object, typename Collection = std::vector<Object>>
class StringBranchHelper< Object, Collection >

Definition at line 124 of file StringBasedNTupler.h.

Member Typedef Documentation

template<typename Object , typename Collection = std::vector<Object>>
typedef TreeBranch::value StringBranchHelper< Object, Collection >::value

Definition at line 126 of file StringBasedNTupler.h.

Constructor & Destructor Documentation

template<typename Object , typename Collection = std::vector<Object>>
StringBranchHelper< Object, Collection >::StringBranchHelper ( const TreeBranch B,
const edm::Event iEvent 
)
inline

Definition at line 129 of file StringBasedNTupler.h.

References TreeBranch::className(), TreeBranch::expr(), edm::HandleBase::failedToGet(), edm::Event::getByLabel(), mps_fire::i, edm::EventBase::isRealData(), LogDebug, TreeBranch::order(), TreeBranch::selection(), corrVsCorr::selection, TreeBranch::src(), parallelization::uint(), and StringBranchHelper< Object, Collection >::value_.

129  {
130  const float defaultValue = 0.;
131 
132  // grab the collection
134  iEvent.getByLabel(B.src(), oH);
135 
136  //empty vector if product not found
137  if (oH.failedToGet()) {
138  if (!(iEvent.isRealData() && B.className() == "reco::GenParticle")) { //don't output genparticle error in data
139  edm::LogError("StringBranchHelper") << "cannot open: " << B.src() << " " << B.className();
140  }
141  value_ = std::make_unique<std::vector<float>>();
142  } else {
143  //parser for the object expression
145  //allocate enough memory for the data holder
146  value_ = std::make_unique<std::vector<float>>();
147  value_->reserve(oH->size());
148 
150  if (!B.selection().empty()) {
151  //std::cout<<"trying to get to a selection"<<std::endl;
152  selection = new StringCutObjectSelector<Object>(B.selection());
153  //std::cout<<"got the objet"<<std::endl;
154  }
155  uint i_end = oH->size();
156  //sort things first if requested
157  if (!B.order().empty()) {
159  // allocate a vector of pointers (we are using view) to be sorted
160  std::vector<const Object*> copyToSort(oH->size());
161  for (uint i = 0; i != i_end; ++i)
162  copyToSort[i] = &(*oH)[i];
163  std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(&order));
164  //then loop and fill
165  for (uint i = 0; i != i_end; ++i) {
166  //try and catch is necessary because ...
167  try {
168  if (selection && !((*selection)(*(copyToSort)[i])))
169  continue;
170  value_->push_back((expr)(*(copyToSort)[i]));
171  } catch (...) {
172  LogDebug("StringBranchHelper")
173  << "with sorting. could not evaluate expression: " << B.expr() << " on class: " << B.className();
174  value_->push_back(defaultValue); //push a default value to not change the indexing
175  }
176  }
177  } else {
178  //actually fill the vector of values
179  for (uint i = 0; i != i_end; ++i) {
180  //try and catch is necessary because ...
181  try {
182  if (selection && !((*selection)((*oH)[i])))
183  continue;
184  value_->push_back((expr)((*oH)[i]));
185  } catch (...) {
186  LogDebug("StringBranchHelper")
187  << "could not evaluate expression: " << B.expr() << " on class: " << B.className();
188  value_->push_back(defaultValue); //push a default value to not change the indexing
189  }
190  }
191  }
192  if (selection)
193  delete selection;
194  }
195  }
selection
main part
Definition: corrVsCorr.py:100
const std::string & selection() const
Log< level::Error, false > LogError
bool isRealData() const
Definition: EventBase.h:62
const std::string & order() const
const edm::InputTag & src() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:500
bool failedToGet() const
Definition: HandleBase.h:72
const std::string & className() const
const std::string & expr() const
#define LogDebug(id)

Member Function Documentation

template<typename Object , typename Collection = std::vector<Object>>
value StringBranchHelper< Object, Collection >::operator() ( )
inline

Member Data Documentation

template<typename Object , typename Collection = std::vector<Object>>
value StringBranchHelper< Object, Collection >::value_
private