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 124 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 126 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 129 of file StringBasedNTupler.h.

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_.reset(new std::vector<float>());
142  } else {
143  //parser for the object expression
145  //allocate enough memory for the data holder
146  value_.reset(new 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  }

References TtFullHadDaughter::B, jets_cff::expr, edm::HandleBase::failedToGet(), mps_fire::i, iEvent, LogDebug, eventshapeDQM_cfi::order, corrVsCorr::selection, parallelization::uint, and StringBranchHelper< Object, Collection >::value_.

Member Function Documentation

◆ operator()()

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

Definition at line 127 of file StringBasedNTupler.h.

127 { return std::move(value_); }

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

Member Data Documentation

◆ value_

template<typename Object , typename Collection = std::vector<Object>>
value StringBranchHelper< Object, Collection >::value_
private
mps_fire.i
i
Definition: mps_fire.py:428
StringObjectFunction< Object >
StringBranchHelper::value_
value value_
Definition: StringBasedNTupler.h:198
edm::Handle
Definition: AssociativeIterator.h:50
parallelization.uint
uint
Definition: parallelization.py:124
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
sortByStringFunction
Definition: StringObjectFunction.h:34
edm::HandleBase::failedToGet
bool failedToGet() const
Definition: HandleBase.h:72
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
eventshapeDQM_cfi.order
order
Definition: eventshapeDQM_cfi.py:8
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
TtFullHadDaughter::B
static const std::string B
Definition: TtFullHadronicEvent.h:9
eostools.move
def move(src, dest)
Definition: eostools.py:511
jets_cff.expr
expr
Definition: jets_cff.py:483
StringCutObjectSelector< Object >