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 126 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 128 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 131 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(), jetUpdater_cfi::sort, TreeBranch::src(), and parallelization::uint().

132  {
133  const float defaultValue = 0.;
134 
135  // grab the collection
137  iEvent.getByLabel(B.src(), oH);
138 
139 
140  //empty vector if product not found
141  if (oH.failedToGet()){
142  if(!(iEvent.isRealData() && B.className()=="reco::GenParticle") ) { //don't output genparticle error in data
143  edm::LogError("StringBranchHelper")<<"cannot open: "<<B.src()<<" "<<B.className();
144  }
145  value_.reset(new std::vector<float>());
146  }
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()!=""){
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()!=""){
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) copyToSort[i]= &(*oH)[i];
167  std::sort(copyToSort.begin(), copyToSort.end(), sortByStringFunction<Object>(&order));
168  //then loop and fill
169  for (uint i=0;i!=i_end;++i) {
170  //try and catch is necessary because ...
171  try{
172  if (selection && !((*selection)(*(copyToSort)[i]))) continue;
173  value_->push_back((expr)(*(copyToSort)[i]));
174  }catch(...){
175  LogDebug("StringBranchHelper")<<"with sorting. could not evaluate expression: "<<B.expr()<<" on class: "<<B.className();
176  value_->push_back(defaultValue);//push a default value to not change the indexing
177  }
178  }
179  }
180  else{
181  //actually fill the vector of values
182  for (uint i=0;i!=i_end;++i){
183  //try and catch is necessary because ...
184  try {
185  if (selection && !((*selection)((*oH)[i]))) continue;
186  value_->push_back((expr)((*oH)[i]));
187  }catch(...){
188  LogDebug("StringBranchHelper")<<"could not evaluate expression: "<<B.expr()<<" on class: "<<B.className();
189  value_->push_back(defaultValue);//push a default value to not change the indexing
190  }
191  }
192  }
193  if (selection) delete selection;
194  }
195  }
#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:480
bool failedToGet() const
Definition: HandleBase.h:78
def uint(string)
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 129 of file StringBasedNTupler.h.

References eostools::move().

129 { 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 197 of file StringBasedNTupler.h.