CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 127 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 129 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 132 of file StringBasedNTupler.h.

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

133  {
134  const float defaultValue = 0.;
135 
136  // grab the collection
138  iEvent.getByLabel(B.src(), oH);
139 
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  }
148  else{
149  //parser for the object expression
151  //allocate enough memory for the data holder
152  value_.reset(new std::vector<float>());
153  value_->reserve(oH->size());
154 
156  if (B.selection()!=""){
157  //std::cout<<"trying to get to a selection"<<std::endl;
158  selection = new StringCutObjectSelector<Object>(B.selection());
159  //std::cout<<"got the objet"<<std::endl;
160  }
161  uint i_end=oH->size();
162  //sort things first if requested
163  if (B.order()!=""){
165  // allocate a vector of pointers (we are using view) to be sorted
166  std::vector<const Object*> copyToSort(oH->size());
167  for (uint i=0;i!=i_end;++i) 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]))) continue;
174  value_->push_back((expr)(*(copyToSort)[i]));
175  }catch(...){
176  LogDebug("StringBranchHelper")<<"with sorting. could not evaluate expression: "<<B.expr()<<" on class: "<<B.className();
177  value_->push_back(defaultValue);//push a default value to not change the indexing
178  }
179  }
180  }
181  else{
182  //actually fill the vector of values
183  for (uint i=0;i!=i_end;++i){
184  //try and catch is necessary because ...
185  try {
186  if (selection && !((*selection)((*oH)[i]))) continue;
187  value_->push_back((expr)((*oH)[i]));
188  }catch(...){
189  LogDebug("StringBranchHelper")<<"could not evaluate expression: "<<B.expr()<<" on class: "<<B.className();
190  value_->push_back(defaultValue);//push a default value to not change the indexing
191  }
192  }
193  }
194  if (selection) delete selection;
195  }
196  }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
selection
main part
Definition: corrVsCorr.py:98
const std::string & selection() const
bool isRealData() const
Definition: EventBase.h:63
const std::string & order() const
const edm::InputTag & src() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:418
bool failedToGet() const
Definition: HandleBase.h:79
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 130 of file StringBasedNTupler.h.

References StringBranchHelper< Object, Collection >::value_.

130 { return value_;}

Member Data Documentation

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