1 #ifndef StringBasedNTupler_NTupler_H 2 #define StringBasedNTupler_NTupler_H 72 typedef std::unique_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));
268 lumiblock_ =
new uint;
269 experimentType_ =
new uint;
270 bunchCrossing_ =
new uint;
271 orbitNumber_ =
new uint;
276 if (branchesPSet.
exists(
"useTFileService"))
277 useTFileService_=branchesPSet.
getParameter<
bool>(
"useTFileService");
279 useTFileService_=iConfig.
getParameter<
bool>(
"useTFileService");
281 if (useTFileService_){
282 if (branchesPSet.
exists(
"treeName")){
298 if (useTFileService_){
302 tree_=fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
304 TObject *
object = fs->
file().Get(treeName_.c_str());
307 tree_=fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
310 tree_=
dynamic_cast<TTree*
>(
object);
313 tree_=fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
315 else ownTheTree_=
false;
320 indexDataHolder_ =
new uint[branches_.size()];
322 Branches::iterator iB=branches_.begin();
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());
341 tree_->Branch(
"run",run_,
"run/i");
342 tree_->Branch(
"event",ev_,
"event/l");
343 tree_->Branch(
"lumiblock",lumiblock_,
"lumiblock/i");
344 tree_->Branch(
"experimentType",experimentType_,
"experimentType/i");
345 tree_->Branch(
"bunchCrossing",bunchCrossing_,
"bunchCrossing/i");
346 tree_->Branch(
"orbitNumber",orbitNumber_,
"orbitNumber/i");
347 tree_->Branch(
"weight",weight_,
"weight/f");
348 tree_->Branch(
"model_params",&model_params_);
353 Branches::iterator iB=branches_.begin();
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){
376 if (useTFileService_){
378 Branches::iterator iB=branches_.begin();
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::unique_ptr<std::vector<float> >
branch(b.
branch(iEvent));
396 indexDataHolder_[indexOfIndexInDataHolder]=maxS;
400 *run_ = iEvent.
id().
run();
411 iEvent.
getByLabel(
"generator", wgeneventinfo);
412 *weight_ = wgeneventinfo->
weight();
415 typedef std::vector<std::string>::const_iterator comments_const_iterator;
419 *model_params_ =
"NULL";
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) {
428 *model_params_ = *cit;
434 if (ownTheTree_){ tree_->Fill(); }
437 Branches::iterator iB=branches_.begin();
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::unique_ptr<std::vector<float> >
branch(b.
branch(iEvent));
450 iEvent.
put(std::make_unique<uint>(maxS), iB->first);
457 if (useTFileService_){
458 Branches::iterator iB=branches_.begin();
459 Branches::iterator iB_end=branches_.end();
461 for(;iB!=iB_end;++iB){
462 std::vector<TreeBranch>::iterator iL=iB->second.begin();
463 std::vector<TreeBranch>::iterator iL_end=iB->second.end();
464 for(;iL!=iL_end;++iL){
473 delete indexDataHolder_;
477 delete experimentType_;
478 delete bunchCrossing_;
481 delete model_params_;
485 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
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
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)
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()