1 #ifndef StringBasedNTupler_NTupler_H 2 #define StringBasedNTupler_NTupler_H 71 typedef std::unique_ptr<std::vector<float> >
value;
91 template <
typename Object>
99 const float defaultValue = 0.;
106 value_.reset(
new std::vector<float>(0));
112 value_.reset(
new std::vector<float>(1));
114 (*value_)[0]=(
expr)(*oH);
116 LogDebug(
"StringLeaveHelper")<<
"could not evaluate expression: "<<B.
expr()<<
" on class: "<<B.
className();
117 (*value_)[0]=defaultValue;
125 template <
typename Object,
typename Collection=std::vector<Object> >
133 const float defaultValue = 0.;
145 value_.reset(
new std::vector<float>());
151 value_.reset(
new std::vector<float>());
152 value_->reserve(oH->size());
160 uint i_end=oH->size();
165 std::vector<const Object*> copyToSort(oH->size());
166 for (
uint i=0;
i!=i_end;++
i) copyToSort[
i]= &(*oH)[
i];
172 if (selection && !((*selection)(*(copyToSort)[
i])))
continue;
173 value_->push_back((
expr)(*(copyToSort)[i]));
175 LogDebug(
"StringBranchHelper")<<
"with sorting. could not evaluate expression: "<<B.
expr()<<
" on class: "<<B.
className();
176 value_->push_back(defaultValue);
185 if (selection && !((*selection)((*oH)[
i])))
continue;
186 value_->push_back((
expr)((*oH)[i]));
188 LogDebug(
"StringBranchHelper")<<
"could not evaluate expression: "<<B.
expr()<<
" on class: "<<B.
className();
189 value_->push_back(defaultValue);
211 std::vector<std::string> branches;
214 for (
uint b=0;
b!=branches.size();++
b){
217 if (bPSet.
exists(
"class"))
230 for (
uint l=0;
l!=leaves.size();++
l){
235 branches_[maxName].push_back(
TreeBranch(className, src, leave_expr, order, selection, maxName, branchAlias));
239 if (leavesPSet.
exists(
"vars")){
240 std::vector<std::string> leavesS = leavesPSet.
getParameter<std::vector<std::string> >(
"vars");
241 for (
uint l=0;
l!=leavesS.size();++
l){
242 uint sep=leavesS[
l].find(separator);
245 int space = name.find(
" ");
250 space = name.find(
" ");
256 branches_[maxName].push_back(
TreeBranch(className, src, expr, order, selection, maxName, branchAlias));
267 lumiblock_ =
new uint;
268 experimentType_ =
new uint;
269 bunchCrossing_ =
new uint;
270 orbitNumber_ =
new uint;
275 if (branchesPSet.
exists(
"useTFileService"))
276 useTFileService_=branchesPSet.
getParameter<
bool>(
"useTFileService");
278 useTFileService_=iConfig.
getParameter<
bool>(
"useTFileService");
280 if (useTFileService_){
281 if (branchesPSet.
exists(
"treeName")){
297 if (useTFileService_){
301 tree_=fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
303 TObject *
object = fs->
file().Get(treeName_.c_str());
306 tree_=fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
309 tree_=
dynamic_cast<TTree*
>(
object);
312 tree_=fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
314 else ownTheTree_=
false;
319 indexDataHolder_ =
new uint[branches_.size()];
321 Branches::iterator iB=branches_.begin();
322 Branches::iterator iB_end=branches_.end();
323 uint indexOfIndexInDataHolder=0;
324 for(;iB!=iB_end;++iB,++indexOfIndexInDataHolder){
326 tree_->Branch(iB->first.c_str(), &(indexDataHolder_[indexOfIndexInDataHolder]),(iB->first+
"/i").c_str());
328 std::vector<TreeBranch>::iterator iL=iB->second.begin();
329 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
330 for(;iL!=iL_end;++iL){
333 TBranch *
br = tree_->Branch(b.
branchAlias().c_str(),
"std::vector<float>",iL->dataHolderPtrAdress());
340 tree_->Branch(
"run",run_,
"run/i");
341 tree_->Branch(
"event",ev_,
"event/l");
342 tree_->Branch(
"lumiblock",lumiblock_,
"lumiblock/i");
343 tree_->Branch(
"experimentType",experimentType_,
"experimentType/i");
344 tree_->Branch(
"bunchCrossing",bunchCrossing_,
"bunchCrossing/i");
345 tree_->Branch(
"orbitNumber",orbitNumber_,
"orbitNumber/i");
346 tree_->Branch(
"weight",weight_,
"weight/f");
347 tree_->Branch(
"model_params",&model_params_);
352 Branches::iterator iB=branches_.begin();
353 Branches::iterator iB_end=branches_.end();
354 for(;iB!=iB_end;++iB){
357 producer->
produces<
uint>(iB->first).setBranchAlias(iB->first);
358 std::vector<TreeBranch>::iterator iL=iB->second.begin();
359 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
360 for(;iL!=iL_end;++iL){
375 if (useTFileService_){
377 Branches::iterator iB=branches_.begin();
378 Branches::iterator iB_end=branches_.end();
379 uint indexOfIndexInDataHolder=0;
380 for(;iB!=iB_end;++iB,++indexOfIndexInDataHolder){
381 std::vector<TreeBranch>::iterator iL=iB->second.begin();
382 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
384 for(;iL!=iL_end;++iL){
387 std::unique_ptr<std::vector<float> >
branch(b.
branch(iEvent));
395 indexDataHolder_[indexOfIndexInDataHolder]=maxS;
399 *run_ = iEvent.
id().
run();
410 iEvent.
getByLabel(
"generator", wgeneventinfo);
411 *weight_ = wgeneventinfo->
weight();
414 typedef std::vector<std::string>::const_iterator comments_const_iterator;
418 *model_params_ =
"NULL";
421 comments_const_iterator c_end = product->
comments_end();
423 for( comments_const_iterator cit=c_begin; cit!=c_end; ++cit) {
424 size_t found = (*cit).find(
"model");
425 if( found != std::string::npos) {
427 *model_params_ = *cit;
433 if (ownTheTree_){ tree_->Fill(); }
436 Branches::iterator iB=branches_.begin();
437 Branches::iterator iB_end=branches_.end();
438 for(;iB!=iB_end;++iB){
439 std::vector<TreeBranch>::iterator iL=iB->second.begin();
440 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
442 for(;iL!=iL_end;++iL){
444 std::unique_ptr<std::vector<float> >
branch(b.
branch(iEvent));
449 iEvent.
put(std::make_unique<uint>(maxS), iB->first);
456 if (useTFileService_){
457 Branches::iterator iB=branches_.begin();
458 Branches::iterator iB_end=branches_.end();
460 for(;iB!=iB_end;++iB){
461 std::vector<TreeBranch>::iterator iL=iB->second.begin();
462 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
463 for(;iL!=iL_end;++iL){
472 delete indexDataHolder_;
476 delete experimentType_;
477 delete bunchCrossing_;
480 delete model_params_;
484 typedef std::map<std::string, std::vector<TreeBranch> >
Branches;
const std::string & branchTitle() const
BranchAliasSetterT< ProductType > produces()
declare what type of product will make and with which optional label
T getParameter(std::string const &) const
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
const std::string & branchAlias() const
std::vector< float > * dataHolderPtr()
const std::string branchName() const
value branch(const edm::Event &iEvent)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
int bunchCrossing() const
def replace(string, replacements)
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
comments_const_iterator comments_begin() const
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)
static const std::string B
std::unique_ptr< std::vector< float > > value
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
void assignDataHolderPtr(std::vector< float > *data)
TFile & file() const
return opened TFile
unsigned long long uint64_t
double S(const TLorentzVector &, const TLorentzVector &)
const std::string & className() const
char data[epos_bytes_allocation]
comments_const_iterator comments_end() const
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)
StringBasedNTupler(const edm::ParameterSet &iConfig)
std::vector< float > ** dataHolderPtrAdress()