1 #ifndef StringBasedNTupler_NTupler_H 2 #define StringBasedNTupler_NTupler_H 74 typedef std::unique_ptr<std::vector<float> >
value;
94 template <
typename Object>
101 const float defaultValue = 0.;
108 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()
119 (*value_)[0] = defaultValue;
128 template <
typename Object,
typename Collection = std::vector<Object> >
135 const float defaultValue = 0.;
146 value_.reset(
new std::vector<float>());
151 value_.reset(
new std::vector<float>());
152 value_->reserve(oH->size());
160 uint i_end = oH->size();
162 if (!B.
order().empty()) {
165 std::vector<const Object*> copyToSort(oH->size());
166 for (
uint i = 0;
i != i_end; ++
i)
167 copyToSort[
i] = &(*oH)[
i];
170 for (
uint i = 0;
i != i_end; ++
i) {
173 if (selection && !((*selection)(*(copyToSort)[
i])))
175 value_->push_back((
expr)(*(copyToSort)[i]));
178 <<
"with sorting. could not evaluate expression: " << B.
expr() <<
" on class: " << B.
className();
179 value_->push_back(defaultValue);
184 for (
uint i = 0;
i != i_end; ++
i) {
187 if (selection && !((*selection)((*oH)[
i])))
189 value_->push_back((
expr)((*oH)[i]));
192 <<
"could not evaluate expression: " << B.
expr() <<
" on class: " << B.
className();
193 value_->push_back(defaultValue);
210 std::vector<std::string> branches;
213 for (
uint b = 0;
b != branches.size(); ++
b) {
216 if (bPSet.
exists(
"class"))
223 if (bPSet.
exists(
"order"))
226 if (bPSet.
exists(
"selection"))
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(
" ");
247 while (space != -1 ) {
251 space = name.find(
" ");
257 branches_[maxName].push_back(
TreeBranch(className, src, expr, order, selection, maxName, branchAlias));
265 lumiblock_ =
new uint;
266 experimentType_ =
new uint;
267 bunchCrossing_ =
new uint;
268 orbitNumber_ =
new uint;
272 if (branchesPSet.
exists(
"useTFileService"))
273 useTFileService_ = branchesPSet.
getParameter<
bool>(
"useTFileService");
275 useTFileService_ = iConfig.
getParameter<
bool>(
"useTFileService");
277 if (useTFileService_) {
278 if (branchesPSet.
exists(
"treeName")) {
291 if (useTFileService_) {
295 tree_ = fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
297 TObject*
object = fs->
file().Get(treeName_.c_str());
300 tree_ = fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
302 tree_ =
dynamic_cast<TTree*
>(
object);
305 tree_ = fs->
make<TTree>(treeName_.c_str(),
"StringBasedNTupler tree");
312 indexDataHolder_ =
new uint[branches_.size()];
314 Branches::iterator iB = branches_.begin();
315 Branches::iterator iB_end = branches_.end();
316 uint indexOfIndexInDataHolder = 0;
317 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
319 tree_->Branch(iB->first.c_str(), &(indexDataHolder_[indexOfIndexInDataHolder]), (iB->first +
"/i").c_str());
321 std::vector<TreeBranch>::iterator iL = iB->second.begin();
322 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
323 for (; iL != iL_end; ++iL) {
326 TBranch*
br = tree_->Branch(b.
branchAlias().c_str(),
"std::vector<float>", iL->dataHolderPtrAdress());
333 tree_->Branch(
"run", run_,
"run/i");
334 tree_->Branch(
"event", ev_,
"event/l");
335 tree_->Branch(
"lumiblock", lumiblock_,
"lumiblock/i");
336 tree_->Branch(
"experimentType", experimentType_,
"experimentType/i");
337 tree_->Branch(
"bunchCrossing", bunchCrossing_,
"bunchCrossing/i");
338 tree_->Branch(
"orbitNumber", orbitNumber_,
"orbitNumber/i");
339 tree_->Branch(
"weight", weight_,
"weight/f");
340 tree_->Branch(
"model_params", &model_params_);
344 Branches::iterator iB = branches_.begin();
345 Branches::iterator iB_end = branches_.end();
346 for (; iB != iB_end; ++iB) {
349 producesCollector.
produces<
uint>(iB->first).setBranchAlias(iB->first);
350 std::vector<TreeBranch>::iterator iL = iB->second.begin();
351 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
352 for (; iL != iL_end; ++iL) {
367 if (useTFileService_) {
369 Branches::iterator iB = branches_.begin();
370 Branches::iterator iB_end = branches_.end();
371 uint indexOfIndexInDataHolder = 0;
372 for (; iB != iB_end; ++iB, ++indexOfIndexInDataHolder) {
373 std::vector<TreeBranch>::iterator iL = iB->second.begin();
374 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
376 for (; iL != iL_end; ++iL) {
379 std::unique_ptr<std::vector<float> >
branch(b.
branch(iEvent));
381 if (
branch->size() > maxS)
388 indexDataHolder_[indexOfIndexInDataHolder] = maxS;
392 *run_ = iEvent.
id().
run();
403 iEvent.
getByLabel(
"generator", wgeneventinfo);
404 *weight_ = wgeneventinfo->
weight();
407 typedef std::vector<std::string>::const_iterator comments_const_iterator;
411 *model_params_ =
"NULL";
414 comments_const_iterator c_end = product->
comments_end();
416 for (comments_const_iterator cit = c_begin; cit != c_end; ++cit) {
417 size_t found = (*cit).find(
"model");
418 if (found != std::string::npos) {
420 *model_params_ = *cit;
430 Branches::iterator iB = branches_.begin();
431 Branches::iterator iB_end = branches_.end();
432 for (; iB != iB_end; ++iB) {
433 std::vector<TreeBranch>::iterator iL = iB->second.begin();
434 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
436 for (; iL != iL_end; ++iL) {
438 std::unique_ptr<std::vector<float> >
branch(b.
branch(iEvent));
439 if (
branch->size() > maxS)
444 iEvent.
put(std::make_unique<uint>(maxS), iB->first);
450 if (useTFileService_) {
451 Branches::iterator iB = branches_.begin();
452 Branches::iterator iB_end = branches_.end();
454 for (; iB != iB_end; ++iB) {
455 std::vector<TreeBranch>::iterator iL = iB->second.begin();
456 std::vector<TreeBranch>::iterator iL_end = iB->second.end();
457 for (; iL != iL_end; ++iL) {
466 delete indexDataHolder_;
470 delete experimentType_;
471 delete bunchCrossing_;
474 delete model_params_;
478 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
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
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)
const edm::InputTag & src() const
comments_const_iterator comments_begin() 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)
TFile & file() const
return opened TFile
unsigned long long uint64_t
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()