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 121 of file StringBasedNTupler.h.

Member Typedef Documentation

◆ value

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

Definition at line 123 of file StringBasedNTupler.h.

Constructor & Destructor Documentation

◆ StringBranchHelper()

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

Definition at line 126 of file StringBasedNTupler.h.

References B, hltPixelClustersMultiplicity_cfi::defaultValue, edm::HandleBase::failedToGet(), mps_fire::i, iEvent, LogDebug, eventshapeDQM_cfi::order, corrVsCorr::selection, jetUpdater_cfi::sort, parallelization::uint, and StringBranchHelper< Object, Collection >::value_.

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

Member Function Documentation

◆ operator()()

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

Definition at line 124 of file StringBasedNTupler.h.

References eostools::move(), and StringBranchHelper< Object, Collection >::value_.

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

Member Data Documentation

◆ value_

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