1 #ifndef StringBasedNTupler_NTupler_H 2 #define StringBasedNTupler_NTupler_H 45 branchTitle_ = E +
" calculated on " +
C +
" object from " +
S.encode();
66 typedef std::unique_ptr<std::vector<float>>
value;
86 template <
typename Object>
100 value_ = std::make_unique<std::vector<float>>(0);
105 value_ = std::make_unique<std::vector<float>>(1);
107 (*value_)[0] = (
expr)(*oH);
109 LogDebug(
"StringLeaveHelper") <<
"could not evaluate expression: " <<
B.expr()
110 <<
" on class: " <<
B.className();
120 template <
typename Object,
typename Collection = std::vector<Object>>
131 iEvent.getByLabel(
B.src(), oH);
135 if (!(
iEvent.isRealData() &&
B.className() ==
"reco::GenParticle")) {
136 edm::LogError(
"StringBranchHelper") <<
"cannot open: " <<
B.src() <<
" " <<
B.className();
138 value_ = std::make_unique<std::vector<float>>();
143 value_ = std::make_unique<std::vector<float>>();
144 value_->reserve(oH->size());
147 if (!
B.selection().empty()) {
152 uint i_end = oH->size();
154 if (!
B.order().empty()) {
157 std::vector<const Object*> copyToSort(oH->size());
158 for (
uint i = 0;
i != i_end; ++
i)
159 copyToSort[
i] = &(*oH)[
i];
162 for (
uint i = 0;
i != i_end; ++
i) {
170 <<
"with sorting. could not evaluate expression: " <<
B.expr() <<
" on class: " <<
B.className();
176 for (
uint i = 0;
i != i_end; ++
i) {
184 <<
"could not evaluate expression: " <<
B.expr() <<
" on class: " <<
B.className();
202 std::vector<std::string> branches;
205 for (
uint b = 0;
b != branches.size(); ++
b) {
208 if (bPSet.
exists(
"class"))
215 if (bPSet.
exists(
"order"))
218 if (bPSet.
exists(
"selection"))
223 for (
uint l = 0;
l != leaves.size(); ++
l) {
232 if (leavesPSet.
exists(
"vars")) {
233 std::vector<std::string> leavesS = leavesPSet.
getParameter<std::vector<std::string>>(
"vars");
234 for (
uint l = 0;
l != leavesS.size(); ++
l) {
238 int space =
name.find(
' ');
239 while (space != -1 ) {
243 space =
name.find(
' ');
264 if (branchesPSet.
exists(
"useTFileService"))
270 if (branchesPSet.
exists(
"treeName")) {
289 TObject*
object =
fs->file().Get(
treeName_.c_str());
306 Branches::iterator iB =
branches_.begin();
307 Branches::iterator iB_end =
branches_.end();
308 uint indexOfIndexInDataHolder = 0;
309 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
311 tree_->Branch(iB->first.c_str(), &(
indexDataHolder_[indexOfIndexInDataHolder]), (iB->first +
"/i").c_str());
313 std::vector<TreeBranch>::iterator iL = iB->second.begin();
314 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
315 for (; iL != iL_end; ++iL) {
318 TBranch*
br =
tree_->Branch(
b.branchAlias().c_str(),
"std::vector<float>", iL->dataHolderPtrAdress());
319 br->SetTitle(
b.branchTitle().c_str());
326 tree_->Branch(
"event",
ev_,
"event/l");
336 Branches::iterator iB =
branches_.begin();
337 Branches::iterator iB_end =
branches_.end();
338 for (; iB != iB_end; ++iB) {
341 producesCollector.
produces<
uint>(iB->first).setBranchAlias(iB->first);
342 std::vector<TreeBranch>::iterator iL = iB->second.begin();
343 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
344 for (; iL != iL_end; ++iL) {
347 producesCollector.
produces<std::vector<float>>(
b.branchName()).setBranchAlias(
b.branchAlias());
361 Branches::iterator iB =
branches_.begin();
362 Branches::iterator iB_end =
branches_.end();
363 uint indexOfIndexInDataHolder = 0;
364 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
365 std::vector<TreeBranch>::iterator iL = iB->second.begin();
366 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
368 for (; iL != iL_end; ++iL) {
371 std::unique_ptr<std::vector<float>>
branch(
b.branch(
iEvent));
373 if (
branch->size() > maxS)
376 b.assignDataHolderPtr(
branch.release());
393 if (!
iEvent.isRealData()) {
395 iEvent.getByLabel(
"generator", wgeneventinfo);
399 typedef std::vector<std::string>::const_iterator comments_const_iterator;
404 if (
iEvent.getByLabel(
"source", product)) {
406 comments_const_iterator c_end = product->
comments_end();
408 for (comments_const_iterator cit = c_begin; cit != c_end; ++cit) {
409 size_t found = (*cit).find(
"model");
410 if (
found != std::string::npos) {
422 Branches::iterator iB =
branches_.begin();
423 Branches::iterator iB_end =
branches_.end();
424 for (; iB != iB_end; ++iB) {
425 std::vector<TreeBranch>::iterator iL = iB->second.begin();
426 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
428 for (; iL != iL_end; ++iL) {
430 std::unique_ptr<std::vector<float>>
branch(
b.branch(
iEvent));
431 if (
branch->size() > maxS)
436 iEvent.put(std::make_unique<uint>(maxS), iB->first);
443 Branches::iterator iB =
branches_.begin();
444 Branches::iterator iB_end =
branches_.end();
446 for (; iB != iB_end; ++iB) {
447 std::vector<TreeBranch>::iterator iL = iB->second.begin();
448 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
449 for (; iL != iL_end; ++iL) {
451 delete b.dataHolderPtr();
470 typedef std::map<std::string, std::vector<TreeBranch>>
Branches;
const edm::InputTag & src() const
T getParameter(std::string const &) 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
const std::string & className() const
def replace(string, replacements)
const std::string & expr() const
std::string maxIndexName_
StringLeaveHelper(const TreeBranch &B, const edm::Event &iEvent)
Log< level::Error, false > LogError
std::vector< float > * dataHolderPtr_
size_t getParameterSetNames(std::vector< std::string > &output, bool trackiness=true) const
T getUntrackedParameter(std::string const &, T const &) const
std::string * model_params_
U second(std::pair< T, U > const &p)
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
std::map< std::string, std::vector< TreeBranch > > Branches
const std::string & branchAlias() const
~StringBasedNTupler() override
const std::string & selection() const
TreeBranch(std::string C, edm::InputTag S, std::string E, std::string O, std::string SE, std::string Mi, std::string Ba)
std::unique_ptr< std::vector< float > > value
const std::string & branchTitle() const
uint registerleaves(edm::ProducesCollector producesCollector) override
void assignDataHolderPtr(std::vector< float > *data)
Log< level::Info, false > LogInfo
comments_const_iterator comments_begin() const
unsigned long long uint64_t
const std::string & order() const
char data[epos_bytes_allocation]
const std::string & maxIndexName() const
StringBranchHelper(const TreeBranch &B, const edm::Event &iEvent)
std::string className(const T &t)
StringBasedNTupler(const edm::ParameterSet &iConfig)
comments_const_iterator comments_end() const
std::vector< float > ** dataHolderPtrAdress()