CMS 3D CMS Logo

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 129 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 131 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 134 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(), TreeBranch::src(), and parallelization::uint.

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

Member Function Documentation

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

Definition at line 132 of file StringBasedNTupler.h.

References eostools::move().

132 { return std::move(value_); }
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

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

Definition at line 203 of file StringBasedNTupler.h.