1 #ifndef StringBasedNTupler_NTupler_H
2 #define StringBasedNTupler_NTupler_H
72 typedef std::auto_ptr<std::vector<float> >
value;
92 template <
typename Object>
100 const float defaultValue = 0.;
107 value_.reset(
new std::vector<float>(0));
113 value_.reset(
new std::vector<float>(1));
115 (*value_)[0]=(expr)(*oH);
117 LogDebug(
"StringLeaveHelper")<<
"could not evaluate expression: "<<B.
expr()<<
" on class: "<<B.
className();
118 (*value_)[0]=defaultValue;
126 template <
typename Object,
typename Collection=std::vector<Object> >
134 const float defaultValue = 0.;
146 value_.reset(
new std::vector<float>());
152 value_.reset(
new std::vector<float>());
153 value_->reserve(oH->size());
161 uint i_end=oH->size();
166 std::vector<const Object*> copyToSort(oH->size());
167 for (uint
i=0;
i!=i_end;++
i) copyToSort[
i]= &(*oH)[
i];
170 for (uint
i=0;
i!=i_end;++
i) {
173 if (selection && !((*selection)(*(copyToSort)[
i])))
continue;
174 value_->push_back((expr)(*(copyToSort)[i]));
176 LogDebug(
"StringBranchHelper")<<
"with sorting. could not evaluate expression: "<<B.
expr()<<
" on class: "<<B.
className();
177 value_->push_back(defaultValue);
183 for (uint
i=0;
i!=i_end;++
i){
186 if (selection && !((*selection)((*oH)[
i])))
continue;
187 value_->push_back((expr)((*oH)[i]));
189 LogDebug(
"StringBranchHelper")<<
"could not evaluate expression: "<<B.
expr()<<
" on class: "<<B.
className();
190 value_->push_back(defaultValue);
212 std::vector<std::string> branches;
215 for (uint
b=0;
b!=branches.size();++
b){
218 if (bPSet.
exists(
"class"))
231 for (uint
l=0;
l!=leaves.size();++
l){
236 branches_[maxName].push_back(
TreeBranch(className, src, leave_expr, order, selection, maxName, branchAlias));
240 if (leavesPSet.
exists(
"vars")){
241 std::vector<std::string> leavesS = leavesPSet.
getParameter<std::vector<std::string> >(
"vars");
242 for (uint
l=0;
l!=leavesS.size();++
l){
243 uint
sep=leavesS[
l].find(separator);
246 int space = name.find(
" ");
251 space = name.find(
" ");
257 branches_[maxName].push_back(
TreeBranch(className, src, expr, order, selection, maxName, branchAlias));
276 if (branchesPSet.
exists(
"useTFileService"))
282 if (branchesPSet.
exists(
"treeName")){
323 Branches::iterator iB_end=
branches_.end();
324 uint indexOfIndexInDataHolder=0;
325 for(;iB!=iB_end;++iB,++indexOfIndexInDataHolder){
327 tree_->Branch(iB->first.c_str(), &(
indexDataHolder_[indexOfIndexInDataHolder]),(iB->first+
"/i").c_str());
329 std::vector<TreeBranch>::iterator iL=iB->second.begin();
330 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
331 for(;iL!=iL_end;++iL){
334 TBranch *
br =
tree_->Branch(b.
branchAlias().c_str(),
"std::vector<float>",iL->dataHolderPtrAdress());
342 tree_->Branch(
"event",
ev_,
"event/i");
354 Branches::iterator iB_end=
branches_.end();
355 for(;iB!=iB_end;++iB){
358 producer->
produces<uint>(iB->first).setBranchAlias(iB->first);
359 std::vector<TreeBranch>::iterator iL=iB->second.begin();
360 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
361 for(;iL!=iL_end;++iL){
379 Branches::iterator iB_end=
branches_.end();
380 uint indexOfIndexInDataHolder=0;
381 for(;iB!=iB_end;++iB,++indexOfIndexInDataHolder){
382 std::vector<TreeBranch>::iterator iL=iB->second.begin();
383 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
385 for(;iL!=iL_end;++iL){
388 std::auto_ptr<std::vector<float> > branch(b.
branch(iEvent));
390 if (branch->size()>maxS) maxS=branch->size();
411 iEvent.
getByLabel(
"generator", wgeneventinfo);
412 *
weight_ = wgeneventinfo->weight();
415 typedef std::vector<std::string>::const_iterator comments_const_iterator;
421 comments_const_iterator c_begin = product->comments_begin();
422 comments_const_iterator c_end = product->comments_end();
424 for( comments_const_iterator cit=c_begin; cit!=c_end; ++cit) {
425 size_t found = (*cit).find(
"model");
426 if( found != std::string::npos) {
438 Branches::iterator iB_end=
branches_.end();
439 for(;iB!=iB_end;++iB){
440 std::vector<TreeBranch>::iterator iL=iB->second.begin();
441 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
443 for(;iL!=iL_end;++iL){
445 std::auto_ptr<std::vector<float> > branch(b.
branch(iEvent));
446 if (branch->size()>maxS) maxS=branch->size();
450 std::auto_ptr<uint> maxN(
new uint(maxS));
451 iEvent.
put(maxN, iB->first);
460 Branches::iterator iB_end=
branches_.end();
462 for(;iB!=iB_end;++iB){
463 std::vector<TreeBranch>::iterator iL=iB->second.begin();
464 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
465 for(;iL!=iL_end;++iL){
486 typedef std::map<std::string, std::vector<TreeBranch> >
Branches;
const std::string & branchTitle() const
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
const std::string & branchAlias() const
std::vector< float > * dataHolderPtr()
const std::string branchName() const
std::auto_ptr< std::vector< float > > value
value branch(const edm::Event &iEvent)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
int bunchCrossing() const
edm::LuminosityBlockNumber_t luminosityBlock() const
T * make(const Args &...args) const
make new ROOT object
std::string maxIndexName_
StringLeaveHelper(const TreeBranch &B, const edm::Event &iEvent)
const std::string & selection() const
std::vector< float > * dataHolderPtr_
const std::string & order() const
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
std::string * model_params_
U second(std::pair< T, U > const &p)
uint registerleaves(edm::ProducerBase *producer)
const edm::InputTag & src() const
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
TypeLabelItem const & produces()
declare what type of product will make and with which optional label
std::map< std::string, std::vector< TreeBranch > > Branches
TreeBranch(std::string C, edm::InputTag S, std::string E, std::string O, std::string SE, std::string Mi, std::string Ba)
void fill(edm::Event &iEvent)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
void assignDataHolderPtr(std::vector< float > *data)
TFile & file() const
return opened TFile
const std::string & className() const
char data[epos_bytes_allocation]
edm::EventAuxiliary::ExperimentType experimentType() const
const std::string & maxIndexName() const
size_t getParameterSetNames(std::vector< std::string > &output, bool trackiness=true) const
const std::string & expr() const
StringBranchHelper(const TreeBranch &B, const edm::Event &iEvent)
std::string className(const T &t)
StringBasedNTupler(const edm::ParameterSet &iConfig)
std::vector< float > ** dataHolderPtrAdress()