CMS 3D CMS Logo

SimpleFlatTableProducer.h
Go to the documentation of this file.
14 
17 
18 #include <memory>
19 #include <vector>
20 
21 // Base class for dumped variables
22 class VariableBase {
23 public:
25  : name_(aname),
26  doc_(cfg.getParameter<std::string>("doc")),
27  precision_(cfg.existsAs<int>("precision") ? cfg.getParameter<int>("precision")
28  : (cfg.existsAs<std::string>("precision") ? -2 : -1)) {}
29  virtual ~VariableBase() {}
30  const std::string &name() const { return name_; }
31 
32 protected:
35 };
36 
37 // Object member variables and methods
38 template <typename ObjType>
39 class Variable : public VariableBase {
40 public:
41  Variable(const std::string &aname, const edm::ParameterSet &cfg) : VariableBase(aname, cfg) {}
42  virtual void fill(std::vector<const ObjType *> &selobjs, nanoaod::FlatTable &out) const = 0;
43 };
44 
45 template <typename ObjType, typename StringFunctor, typename ValType>
46 class FuncVariable : public Variable<ObjType> {
47 public:
49  : Variable<ObjType>(aname, cfg),
50  func_(cfg.getParameter<std::string>("expr"), true),
51  precisionFunc_(cfg.existsAs<std::string>("precision") ? cfg.getParameter<std::string>("precision") : "23",
52  true) {}
53  ~FuncVariable() override {}
54  void fill(std::vector<const ObjType *> &selobjs, nanoaod::FlatTable &out) const override {
55  std::vector<ValType> vals(selobjs.size());
56  for (unsigned int i = 0, n = vals.size(); i < n; ++i) {
57  ValType val = func_(*selobjs[i]);
58  if constexpr (std::is_same<ValType, float>()) {
59  if (this->precision_ == -2) {
60  auto prec = precisionFunc_(*selobjs[i]);
61  vals[i] = prec > 0 ? MiniFloatConverter::reduceMantissaToNbitsRounding(val, prec) : val;
62  } else
63  vals[i] = val;
64  } else {
65  vals[i] = val;
66  }
67  }
68  out.template addColumn<ValType>(this->name_, vals, this->doc_, this->precision_);
69  }
70 
71 protected:
72  StringFunctor func_;
73  StringFunctor precisionFunc_;
74 };
75 
76 // External variables: i.e. variables that are not member or methods of the object
77 template <typename ObjType>
78 class ExtVariable : public VariableBase {
79 public:
80  ExtVariable(const std::string &aname, const edm::ParameterSet &cfg) : VariableBase(aname, cfg) {}
81  virtual void fill(const edm::Event &iEvent,
83  nanoaod::FlatTable &out) const = 0;
84 };
85 template <typename ObjType, typename TIn, typename ValType = TIn>
86 class ValueMapVariable : public ExtVariable<ObjType> {
87 public:
89  const edm::ParameterSet &cfg,
91  bool skipNonExistingSrc = false)
92  : ExtVariable<ObjType>(aname, cfg),
94  token_(cc.consumes<edm::ValueMap<TIn>>(cfg.getParameter<edm::InputTag>("src"))) {}
95  void fill(const edm::Event &iEvent, std::vector<edm::Ptr<ObjType>> selptrs, nanoaod::FlatTable &out) const override {
97  iEvent.getByToken(token_, vmap);
98  std::vector<ValType> vals;
99  if (vmap.isValid() || !skipNonExistingSrc_) {
100  vals.resize(selptrs.size());
101  for (unsigned int i = 0, n = vals.size(); i < n; ++i) {
102  vals[i] = (*vmap)[selptrs[i]];
103  }
104  }
105  out.template addColumn<ValType>(this->name_, vals, this->doc_, this->precision_);
106  }
107 
108 protected:
111 };
112 
113 // Event producers
114 // - ABC
115 // - Singleton
116 // - Collection
117 template <typename T, typename TProd>
119 public:
121  : name_(params.getParameter<std::string>("name")),
122  doc_(params.getParameter<std::string>("doc")),
123  extension_(params.getParameter<bool>("extension")),
124  skipNonExistingSrc_(params.getParameter<bool>("skipNonExistingSrc")),
125  src_(consumes<TProd>(params.getParameter<edm::InputTag>("src"))) {
126  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
127  for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
128  const auto &varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
129  const std::string &type = varPSet.getParameter<std::string>("type");
130  if (type == "int")
131  vars_.push_back(std::make_unique<IntVar>(vname, varPSet));
132  else if (type == "uint")
133  vars_.push_back(std::make_unique<UIntVar>(vname, varPSet));
134  else if (type == "float")
135  vars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
136  else if (type == "double")
137  vars_.push_back(std::make_unique<DoubleVar>(vname, varPSet));
138  else if (type == "uint8")
139  vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
140  else if (type == "int16")
141  vars_.push_back(std::make_unique<Int16Var>(vname, varPSet));
142  else if (type == "uint16")
143  vars_.push_back(std::make_unique<UInt16Var>(vname, varPSet));
144  else if (type == "bool")
145  vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
146  else
147  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
148  }
149 
150  produces<nanoaod::FlatTable>();
151  }
152 
154 
158  desc.add<std::string>("name")->setComment("name of the branch in the flat table output for " + classname);
159  desc.add<std::string>("doc", "")->setComment("few words of self documentation");
160  desc.add<bool>("extension", false)->setComment("whether or not to extend an existing same table");
161  desc.add<bool>("skipNonExistingSrc", false)
162  ->setComment("whether or not to skip producing the table on absent input product");
163  desc.add<edm::InputTag>("src")->setComment("input collection to fill the flat table");
164 
166  variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
167  variable.add<std::string>("doc")->setComment("few words description of the branch content");
168  variable.ifValue(
170  "type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
171  edm::allowedValues<std::string>("int", "uint", "float", "double", "uint8", "int16", "uint16", "bool"));
172  variable.addOptionalNode(
174  "precision", true, edm::Comment("the precision with which to store the value in the flat table")) xor
176  "precision", true, edm::Comment("the precision with which to store the value in the flat table")),
177  false);
178 
180  variables.setComment("a parameters set to define all variable to fill the flat table");
181  variables.addNode(
183  desc.add<edm::ParameterSetDescription>("variables", variables);
184 
185  return desc;
186  }
187  // this is to be overriden by the child class
188  virtual std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
189  const edm::Handle<TProd> &prod) const = 0;
190 
191  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {
193  iEvent.getByToken(src_, src);
194 
195  std::unique_ptr<nanoaod::FlatTable> out = fillTable(iEvent, src);
196  out->setDoc(doc_);
197 
198  iEvent.put(std::move(out));
199  }
200 
201 protected:
204  const bool extension_;
207 
216  std::vector<std::unique_ptr<Variable<T>>> vars_;
217 };
218 
219 template <typename T>
220 class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<T>> {
221 public:
224  singleton_(params.getParameter<bool>("singleton")),
225  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
226  : std::numeric_limits<unsigned int>::max()),
227  cut_(!singleton_ ? params.getParameter<std::string>("cut") : "", true) {
228  if (params.existsAs<edm::ParameterSet>("externalVariables")) {
229  edm::ParameterSet const &extvarsPSet = params.getParameter<edm::ParameterSet>("externalVariables");
230  for (const std::string &vname : extvarsPSet.getParameterNamesForType<edm::ParameterSet>()) {
231  const auto &varPSet = extvarsPSet.getParameter<edm::ParameterSet>(vname);
232  const std::string &type = varPSet.getParameter<std::string>("type");
233  if (type == "int")
234  extvars_.push_back(
235  std::make_unique<IntExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
236  else if (type == "uint")
237  extvars_.push_back(
238  std::make_unique<UIntExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
239  else if (type == "float")
240  extvars_.push_back(
241  std::make_unique<FloatExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
242  else if (type == "double")
243  extvars_.push_back(
244  std::make_unique<DoubleExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
245  else if (type == "uint8")
246  extvars_.push_back(
247  std::make_unique<UInt8ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
248  else if (type == "int16")
249  extvars_.push_back(
250  std::make_unique<Int16ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
251  else if (type == "uint16")
252  extvars_.push_back(
253  std::make_unique<UInt16ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
254  else if (type == "bool")
255  extvars_.push_back(
256  std::make_unique<BoolExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
257  else
258  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
259  }
260  }
261  }
262 
264 
267 
269  "singleton", false, true, edm::Comment("whether or not the input collection is single-element")),
271  "cut", "", true, edm::Comment("selection on the main input collection")) or
272  true >> edm::EmptyGroupDescription());
273  desc.addOptional<unsigned int>("maxLen")->setComment(
274  "define the maximum length of the input collection to put in the branch");
275 
276  edm::ParameterSetDescription extvariable;
277  extvariable.add<edm::InputTag>("src")->setComment("valuemap input collection to fill the flat table");
278  extvariable.add<std::string>("doc")->setComment("few words description of the branch content");
279  extvariable.ifValue(
281  "type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
282  edm::allowedValues<std::string>("int", "uint", "float", "double", "uint8", "int16", "uint16", "bool"));
283  extvariable.addOptionalNode(
285  "precision", true, edm::Comment("the precision with which to store the value in the flat table")) xor
287  "precision", true, edm::Comment("the precision with which to store the value in the flat table")),
288  false);
289 
290  edm::ParameterSetDescription extvariables;
291  extvariables.setComment("a parameters set to define all variable taken form valuemap to fill the flat table");
292  extvariables.addOptionalNode(
294  desc.addOptional<edm::ParameterSetDescription>("externalVariables", extvariables);
295 
296  descriptions.addWithDefaultLabel(desc);
297  }
298 
299  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
300  const edm::Handle<edm::View<T>> &prod) const override {
301  std::vector<const T *> selobjs;
302  std::vector<edm::Ptr<T>> selptrs; // for external variables
303  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
304  if (singleton_) {
305  assert(prod->size() == 1);
306  selobjs.push_back(&(*prod)[0]);
307  if (!extvars_.empty())
308  selptrs.emplace_back(prod->ptrAt(0));
309  } else {
310  for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
311  const auto &obj = (*prod)[i];
312  if (cut_(obj)) {
313  selobjs.push_back(&obj);
314  if (!extvars_.empty())
315  selptrs.emplace_back(prod->ptrAt(i));
316  }
317  if (selobjs.size() >= maxLen_)
318  break;
319  }
320  }
321  }
322  auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, singleton_, this->extension_);
323  for (const auto &var : this->vars_)
324  var->fill(selobjs, *out);
325  for (const auto &var : this->extvars_)
326  var->fill(iEvent, selptrs, *out);
327  return out;
328  }
329 
330 protected:
332  const unsigned int maxLen_;
334 
343  std::vector<std::unique_ptr<ExtVariable<T>>> extvars_;
344 };
345 
346 template <typename T>
348 public:
351  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
352  : std::numeric_limits<unsigned int>::max()),
353  cut_(params.getParameter<std::string>("cut"), true),
354  minBX_(params.getParameter<int>("minBX")),
355  maxBX_(params.getParameter<int>("maxBX")),
356  alwaysWriteBXValue_(params.getParameter<bool>("alwaysWriteBXValue")),
357  bxVarName_("bx") {
358  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
360  if (std::find(varNames.begin(), varNames.end(), bxVarName_) != varNames.end()) {
361  throw cms::Exception("Configuration",
362  "BXVectorSimpleFlatTableProducer already defines the " + bxVarName_ +
363  "internally and thus you should not specify it yourself");
364  }
365  }
366 
369  desc.add<std::string>("cut", "")->setComment(
370  "selection on the main input collection (but selection can not be bx based)");
371  desc.addOptional<unsigned int>("maxLen")->setComment(
372  "define the maximum length of the input collection to put in the branch");
373  desc.add<int>("minBX", -2)->setComment("min bx (inclusive) to include");
374  desc.add<int>("maxBX", 2)->setComment("max bx (inclusive) to include");
375  desc.add<bool>("alwaysWriteBXValue", true)
376  ->setComment("always write the bx number (event when only one bx can be present, ie minBX==maxBX)");
377  descriptions.addWithDefaultLabel(desc);
378  }
379 
380  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
381  const edm::Handle<BXVector<T>> &prod) const override {
382  std::vector<const T *> selObjs;
383  std::vector<int> selObjBXs;
384 
385  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
386  const int minBX = std::max(minBX_, prod->getFirstBX());
387  const int maxBX = std::min(maxBX_, prod->getLastBX());
388  for (int bx = minBX; bx <= maxBX; bx++) {
389  for (size_t objNr = 0, nrObjs = prod->size(bx); objNr < nrObjs; ++objNr) {
390  const auto &obj = prod->at(bx, objNr);
391  if (cut_(obj)) {
392  selObjs.push_back(&obj);
393  selObjBXs.push_back(bx);
394  }
395  if (selObjs.size() >= maxLen_)
396  break;
397  }
398  }
399  }
400  auto out = std::make_unique<nanoaod::FlatTable>(selObjs.size(), this->name_, false, this->extension_);
401  for (const auto &var : this->vars_)
402  var->fill(selObjs, *out);
403  if (alwaysWriteBXValue_ || minBX_ != maxBX_) {
404  out->template addColumn<int16_t>(bxVarName_, selObjBXs, "BX of the L1 candidate");
405  }
406  return out;
407  }
408 
409 protected:
410  const unsigned int maxLen_;
412  const int minBX_;
413  const int maxBX_;
416 };
417 
418 template <typename T>
420 public:
422 
424 
427  descriptions.addWithDefaultLabel(desc);
428  }
429 
430  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &, const edm::Handle<T> &prod) const override {
431  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
432  std::vector<const T *> selobjs(1, prod.product());
433  for (const auto &var : this->vars_)
434  var->fill(selobjs, *out);
435  return out;
436  }
437 };
438 
439 template <typename T>
441 public:
444 
446 
449  descriptions.addWithDefaultLabel(desc);
450  }
451 
452  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
453  const edm::Handle<edm::View<T>> &prod) const override {
454  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
455  std::vector<const T *> selobjs(1, &(*prod)[0]);
456  for (const auto &var : this->vars_)
457  var->fill(selobjs, *out);
458  return out;
459  }
460 };
461 
462 // LuminosityBlock producers
463 // - ABC
464 // - Singleton
465 // - Collection
466 template <typename T, typename TProd>
468  : public edm::one::EDProducer<edm::EndLuminosityBlockProducer, edm::LuminosityBlockCache<int>> {
469 public:
471  : name_(params.getParameter<std::string>("name")),
472  doc_(params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""),
473  extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false),
475 
476  params.existsAs<bool>("skipNonExistingSrc") ? params.getParameter<bool>("skipNonExistingSrc") : false),
477  src_(consumes<TProd, edm::InLumi>(params.getParameter<edm::InputTag>("src"))) {
478  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
479  for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
480  const auto &varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
481  const std::string &type = varPSet.getParameter<std::string>("type");
482  if (type == "int")
483  vars_.push_back(std::make_unique<IntVar>(vname, varPSet));
484  else if (type == "float")
485  vars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
486  else if (type == "uint8")
487  vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
488  else if (type == "bool")
489  vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
490  else
491  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
492  }
493 
494  produces<nanoaod::FlatTable, edm::Transition::EndLuminosityBlock>();
495  }
496 
498 
499  std::shared_ptr<int> globalBeginLuminosityBlock(edm::LuminosityBlock const &,
500  edm::EventSetup const &) const override {
501  return nullptr;
502  }
503 
505 
506  // this is to be overriden by the child class
507  virtual std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::LuminosityBlock &iLumi,
508  const edm::Handle<TProd> &prod) const = 0;
509 
510  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {
511  // do nothing
512  }
513 
516  iLumi.getByToken(src_, src);
517 
518  std::unique_ptr<nanoaod::FlatTable> out = fillTable(iLumi, src);
519  out->setDoc(doc_);
520 
521  iLumi.put(std::move(out));
522  }
523 
524 protected:
527  const bool extension_;
530 
535  std::vector<std::unique_ptr<Variable<T>>> vars_;
536 };
537 
538 // Class for singletons like GenFilterInfo
539 template <typename T>
541 public:
544 
546 
549  descriptions.addWithDefaultLabel(desc);
550  }
551 
552  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::LuminosityBlock &,
553  const edm::Handle<T> &prod) const override {
554  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
555  std::vector<const T *> selobjs(1, prod.product());
556  for (const auto &var : this->vars_)
557  var->fill(selobjs, *out);
558  return out;
559  }
560 };
561 
562 // Class for generic collections
563 template <typename T, typename TProd>
565 public:
568  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
569  : std::numeric_limits<unsigned int>::max()),
570  cut_(params.existsAs<std::string>("cut") ? params.getParameter<std::string>("cut") : "", true) {}
571 
573 
576  desc.addOptional<unsigned int>("maxLen")->setComment(
577  "define the maximum length of the input collection to put in the branch");
578  descriptions.addWithDefaultLabel(desc);
579  }
580 
581  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::LuminosityBlock &iLumi,
582  const edm::Handle<TProd> &prod) const override {
583  std::vector<const T *> selobjs;
584  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
585  for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
586  const auto &obj = (*prod)[i];
587  if (cut_(obj)) {
588  selobjs.push_back(&obj);
589  }
590  if (selobjs.size() >= maxLen_)
591  break;
592  }
593  }
594  auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, false, this->extension_);
595  for (const auto &var : this->vars_)
596  var->fill(selobjs, *out);
597  return out;
598  }
599 
600 protected:
601  const unsigned int maxLen_;
603 };
604 
605 // Run producers
606 // - ABC
607 // - Singleton
608 // - Collection
609 template <typename T, typename TProd>
610 class SimpleFlatTableProducerBaseRun : public edm::one::EDProducer<edm::EndRunProducer, edm::RunCache<int>> {
611 public:
613  : name_(params.getParameter<std::string>("name")),
614  doc_(params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""),
615  extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false),
617 
618  params.existsAs<bool>("skipNonExistingSrc") ? params.getParameter<bool>("skipNonExistingSrc") : false),
619  src_(consumes<TProd, edm::InRun>(params.getParameter<edm::InputTag>("src"))) {
620  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
621  for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
622  const auto &varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
623  const std::string &type = varPSet.getParameter<std::string>("type");
624  if (type == "int")
625  vars_.push_back(std::make_unique<IntVar>(vname, varPSet));
626  else if (type == "float")
627  vars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
628  else if (type == "uint8")
629  vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
630  else if (type == "bool")
631  vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
632  else
633  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
634  }
635 
636  produces<nanoaod::FlatTable, edm::Transition::EndRun>();
637  }
638 
640 
641  std::shared_ptr<int> globalBeginRun(edm::Run const &, edm::EventSetup const &) const override { return nullptr; }
642 
643  void globalEndRun(edm::Run const &, edm::EventSetup const &) override {}
644 
645  // this is to be overriden by the child class
646  virtual std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Run &iRun, const edm::Handle<TProd> &prod) const = 0;
647 
648  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {
649  // do nothing
650  }
651 
652  void endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) final {
654  iRun.getByToken(src_, src);
655 
656  std::unique_ptr<nanoaod::FlatTable> out = fillTable(iRun, src);
657  out->setDoc(doc_);
658 
659  iRun.put(std::move(out));
660  }
661 
662 protected:
665  const bool extension_;
668 
673  std::vector<std::unique_ptr<Variable<T>>> vars_;
674 };
675 
676 // Class for singletons like GenFilterInfo
677 template <typename T>
679 public:
681 
683 
684  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Run &, const edm::Handle<T> &prod) const override {
685  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
686  std::vector<const T *> selobjs(1, prod.product());
687  for (const auto &var : this->vars_)
688  var->fill(selobjs, *out);
689  return out;
690  }
691 };
692 
693 // Class for generic collections
694 template <typename T, typename TProd>
696 public:
699  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
700  : std::numeric_limits<unsigned int>::max()),
701  cut_(params.existsAs<std::string>("cut") ? params.getParameter<std::string>("cut") : "", true) {}
702 
704 
705  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Run &iRun, const edm::Handle<TProd> &prod) const override {
706  std::vector<const T *> selobjs;
707  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
708  for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
709  const auto &obj = (*prod)[i];
710  if (cut_(obj)) {
711  selobjs.push_back(&obj);
712  }
713  if (selobjs.size() >= maxLen_)
714  break;
715  }
716  }
717  auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, false, this->extension_);
718  for (const auto &var : this->vars_)
719  var->fill(selobjs, *out);
720  return out;
721  }
722 
723 protected:
724  const unsigned int maxLen_;
726 };
ValueMapVariable< T, double, float > DoubleExtVar
ParameterDescriptionNode * ifValue(ParameterDescription< T > const &switchParameter, std::unique_ptr< ParameterDescriptionCases< T >> cases)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
Variable(const std::string &aname, const edm::ParameterSet &cfg)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ValueMapVariable< T, int, uint16_t > UInt16ExtVar
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ValueMapVariable< T, bool > BoolExtVar
FuncVariable< T, StringObjectFunction< T >, int > IntVar
std::vector< std::unique_ptr< Variable< T > > > vars_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::LuminosityBlock &, const edm::Handle< T > &prod) const override
FuncVariable< T, StringCutObjectSelector< T >, bool > BoolVar
virtual void fill(const edm::Event &iEvent, std::vector< edm::Ptr< ObjType >> selptrs, nanoaod::FlatTable &out) const =0
std::shared_ptr< int > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
ValueMapVariable< T, int, uint8_t > UInt8ExtVar
const edm::EDGetTokenT< TProd > src_
void globalEndRun(edm::Run const &, edm::EventSetup const &) override
const StringCutObjectSelector< T > cut_
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< edm::View< T >> &prod) const override
FuncVariable< T, StringObjectFunction< T >, uint32_t > UIntVar
FuncVariable< T, StringObjectFunction< T >, uint8_t > UInt8Var
constexpr char const * varNames[]
FuncVariable< T, StringCutObjectSelector< T >, bool > BoolVar
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
VariableBase(const std::string &aname, const edm::ParameterSet &cfg)
FuncVariable< T, StringObjectFunction< T >, uint16_t > UInt16Var
SimpleFlatTableProducerBase(edm::ParameterSet const &params)
ValueMapVariable< T, uint32_t > UIntExtVar
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Run &iRun, const edm::Handle< TProd > &prod) const =0
ValueMapVariable< T, int, int16_t > Int16ExtVar
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &, const edm::Handle< T > &prod) const override
FuncVariable< T, StringObjectFunction< T >, uint8_t > UInt8Var
void setComment(std::string const &value)
void globalEndLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
int iEvent
Definition: GenABIO.cc:224
const StringCutObjectSelector< T > cut_
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::LuminosityBlock &iLumi, const edm::Handle< TProd > &prod) const override
const StringCutObjectSelector< T > cut_
void fill(const edm::Event &iEvent, std::vector< edm::Ptr< ObjType >> selptrs, nanoaod::FlatTable &out) const override
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
FuncVariable< T, StringObjectFunction< T >, int16_t > Int16Var
FuncVariable< T, StringObjectFunction< T >, float > FloatVar
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:180
static const std::string & name()
Definition: ClassName.h:38
std::vector< std::unique_ptr< ExtVariable< T > > > extvars_
ParameterDescriptionNode * addOptionalNode(ParameterDescriptionNode const &node, bool writeToCfi)
LumiSingletonSimpleFlatTableProducer(edm::ParameterSet const &params)
RunSingletonSimpleFlatTableProducer(edm::ParameterSet const &params)
edm::EDGetTokenT< edm::ValueMap< TIn > > token_
ExtVariable(const std::string &aname, const edm::ParameterSet &cfg)
SimpleFlatTableProducer(edm::ParameterSet const &params)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Run &iRun, const edm::Handle< TProd > &prod) const override
void endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) final
const edm::EDGetTokenT< TProd > src_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
FuncVariable< T, StringObjectFunction< T >, float > FloatVar
FuncVariable< T, StringObjectFunction< T >, int32_t > IntVar
void fill(std::vector< const ObjType *> &selobjs, nanoaod::FlatTable &out) const override
BXVectorSimpleFlatTableProducer(edm::ParameterSet const &params)
FuncVariable< T, StringObjectFunction< T >, int > IntVar
StringFunctor precisionFunc_
RunSimpleFlatTableProducer(edm::ParameterSet const &params)
const std::string & name() const
SimpleFlatTableProducerBaseRun(edm::ParameterSet const &params)
FuncVariable< T, StringObjectFunction< T >, uint8_t > UInt8Var
FuncVariable< T, StringObjectFunction< T >, float > FloatVar
SimpleFlatTableProducerBaseLumi(edm::ParameterSet const &params)
virtual std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< TProd > &prod) const =0
FuncVariable< T, StringObjectFunction< T >, double > DoubleVar
std::vector< std::unique_ptr< Variable< T > > > vars_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::shared_ptr< int > globalBeginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) const override
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< edm::View< T >> &prod) const override
bool isValid() const
Definition: HandleBase.h:70
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< BXVector< T >> &prod) const override
static float reduceMantissaToNbitsRounding(const float &f)
Definition: libminifloat.h:79
HLT enums.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
ValueMapVariable(const std::string &aname, const edm::ParameterSet &cfg, edm::ConsumesCollector &&cc, bool skipNonExistingSrc=false)
FirstObjectSimpleFlatTableProducer(edm::ParameterSet const &params)
EventSingletonSimpleFlatTableProducer(edm::ParameterSet const &params)
ValueMapVariable< T, float > FloatExtVar
FuncVariable(const std::string &aname, const edm::ParameterSet &cfg)
virtual void fill(std::vector< const ObjType *> &selobjs, nanoaod::FlatTable &out) const =0
ValueMapVariable< T, int32_t > IntExtVar
std::vector< std::unique_ptr< Variable< T > > > vars_
LumiSimpleFlatTableProducer(edm::ParameterSet const &params)
long double T
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Run &, const edm::Handle< T > &prod) const override
void endLuminosityBlockProduce(edm::LuminosityBlock &iLumi, const edm::EventSetup &iSetup) final
const StringCutObjectSelector< T > cut_
FuncVariable< T, StringCutObjectSelector< T >, bool > BoolVar
def move(src, dest)
Definition: eostools.py:511
virtual std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::LuminosityBlock &iLumi, const edm::Handle< TProd > &prod) const =0
Definition: Run.h:45
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::EDGetTokenT< TProd > src_
static edm::ParameterSetDescription baseDescriptions()