1 #ifndef StringBasedNTupler_NTupler_H
2 #define StringBasedNTupler_NTupler_H
69 typedef std::unique_ptr<std::vector<float>>
value;
89 template <
typename Object>
96 const float defaultValue = 0.;
103 value_ = std::make_unique<std::vector<float>>(0);
108 value_ = std::make_unique<std::vector<float>>(1);
110 (*value_)[0] = (expr)(*oH);
112 LogDebug(
"StringLeaveHelper") <<
"could not evaluate expression: " << B.
expr()
114 (*value_)[0] = defaultValue;
123 template <
typename Object,
typename Collection = std::vector<Object>>
130 const float defaultValue = 0.;
141 value_ = std::make_unique<std::vector<float>>();
146 value_ = std::make_unique<std::vector<float>>();
147 value_->reserve(oH->size());
155 uint i_end = oH->size();
157 if (!B.
order().empty()) {
160 std::vector<const Object*> copyToSort(oH->size());
161 for (
uint i = 0;
i != i_end; ++
i)
162 copyToSort[
i] = &(*oH)[
i];
165 for (
uint i = 0;
i != i_end; ++
i) {
168 if (selection && !((*selection)(*(copyToSort)[
i])))
170 value_->push_back((expr)(*(copyToSort)[i]));
173 <<
"with sorting. could not evaluate expression: " << B.
expr() <<
" on class: " << B.
className();
174 value_->push_back(defaultValue);
179 for (
uint i = 0;
i != i_end; ++
i) {
182 if (selection && !((*selection)((*oH)[
i])))
184 value_->push_back((expr)((*oH)[i]));
187 <<
"could not evaluate expression: " << B.
expr() <<
" on class: " << B.
className();
188 value_->push_back(defaultValue);
205 std::vector<std::string> branches;
208 for (
uint b = 0;
b != branches.size(); ++
b) {
211 if (bPSet.
exists(
"class"))
218 if (bPSet.
exists(
"order"))
221 if (bPSet.
exists(
"selection"))
226 for (
uint l = 0;
l != leaves.size(); ++
l) {
231 branches_[maxName].push_back(
TreeBranch(className, src, leave_expr, order, selection, maxName, branchAlias));
235 if (leavesPSet.
exists(
"vars")) {
236 std::vector<std::string> leavesS = leavesPSet.
getParameter<std::vector<std::string>>(
"vars");
237 for (
uint l = 0;
l != leavesS.size(); ++
l) {
238 uint sep = leavesS[
l].find(separator);
241 int space = name.find(
' ');
242 while (space != -1 ) {
246 space = name.find(
' ');
252 branches_[maxName].push_back(
TreeBranch(className, src, expr, order, selection, maxName, branchAlias));
267 if (branchesPSet.
exists(
"useTFileService"))
273 if (branchesPSet.
exists(
"treeName")) {
297 tree_ =
dynamic_cast<TTree*
>(object);
309 Branches::iterator iB =
branches_.begin();
310 Branches::iterator iB_end =
branches_.end();
311 uint indexOfIndexInDataHolder = 0;
312 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
314 tree_->Branch(iB->first.c_str(), &(
indexDataHolder_[indexOfIndexInDataHolder]), (iB->first +
"/i").c_str());
316 std::vector<TreeBranch>::iterator iL = iB->second.begin();
317 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
318 for (; iL != iL_end; ++iL) {
321 TBranch*
br =
tree_->Branch(b.
branchAlias().c_str(),
"std::vector<float>", iL->dataHolderPtrAdress());
329 tree_->Branch(
"event",
ev_,
"event/l");
339 Branches::iterator iB =
branches_.begin();
340 Branches::iterator iB_end =
branches_.end();
341 for (; iB != iB_end; ++iB) {
344 producesCollector.
produces<
uint>(iB->first).setBranchAlias(iB->first);
345 std::vector<TreeBranch>::iterator iL = iB->second.begin();
346 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
347 for (; iL != iL_end; ++iL) {
364 Branches::iterator iB =
branches_.begin();
365 Branches::iterator iB_end =
branches_.end();
366 uint indexOfIndexInDataHolder = 0;
367 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
368 std::vector<TreeBranch>::iterator iL = iB->second.begin();
369 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
371 for (; iL != iL_end; ++iL) {
374 std::unique_ptr<std::vector<float>> branch(b.
branch(iEvent));
376 if (branch->size() > maxS)
377 maxS = branch->size();
398 iEvent.
getByLabel(
"generator", wgeneventinfo);
399 *
weight_ = wgeneventinfo->weight();
402 typedef std::vector<std::string>::const_iterator comments_const_iterator;
408 comments_const_iterator c_begin = product->comments_begin();
409 comments_const_iterator c_end = product->comments_end();
411 for (comments_const_iterator cit = c_begin; cit != c_end; ++cit) {
412 size_t found = (*cit).find(
"model");
413 if (found != std::string::npos) {
425 Branches::iterator iB =
branches_.begin();
426 Branches::iterator iB_end =
branches_.end();
427 for (; iB != iB_end; ++iB) {
428 std::vector<TreeBranch>::iterator iL = iB->second.begin();
429 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
431 for (; iL != iL_end; ++iL) {
433 std::unique_ptr<std::vector<float>> branch(b.
branch(iEvent));
434 if (branch->size() > maxS)
435 maxS = branch->size();
439 iEvent.
put(std::make_unique<uint>(maxS), iB->first);
446 Branches::iterator iB =
branches_.begin();
447 Branches::iterator iB_end =
branches_.end();
449 for (; iB != iB_end; ++iB) {
450 std::vector<TreeBranch>::iterator iL = iB->second.begin();
451 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
452 for (; iL != iL_end; ++iL) {
473 typedef std::map<std::string, std::vector<TreeBranch>>
Branches;
const std::string & branchTitle() 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
ProductRegistryHelper::BranchAliasSetterT< ProductType > produces()
void fill(edm::Event &iEvent) override
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
Log< level::Error, false > LogError
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)
const edm::InputTag & src() const
std::map< std::string, std::vector< TreeBranch > > Branches
~StringBasedNTupler() override
TreeBranch(std::string C, edm::InputTag S, std::string E, std::string O, std::string SE, std::string Mi, std::string Ba)
static const std::string B
std::unique_ptr< std::vector< float > > value
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
uint registerleaves(edm::ProducesCollector producesCollector) override
void assignDataHolderPtr(std::vector< float > *data)
Log< level::Info, false > LogInfo
TFile & file() const
return opened TFile
unsigned long long uint64_t
T getParameter(std::string const &) const
const std::string & className() const
char data[epos_bytes_allocation]
edm::EventAuxiliary::ExperimentType experimentType() const
static std::string const separator(":")
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()