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 == "int8")
139  vars_.push_back(std::make_unique<Int8Var>(vname, varPSet));
140  else if (type == "uint8")
141  vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
142  else if (type == "int16")
143  vars_.push_back(std::make_unique<Int16Var>(vname, varPSet));
144  else if (type == "uint16")
145  vars_.push_back(std::make_unique<UInt16Var>(vname, varPSet));
146  else if (type == "bool")
147  vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
148  else
149  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
150  }
151 
152  produces<nanoaod::FlatTable>();
153  }
154 
156 
160  desc.add<std::string>("name")->setComment("name of the branch in the flat table output for " + classname);
161  desc.add<std::string>("doc", "")->setComment("few words of self documentation");
162  desc.add<bool>("extension", false)->setComment("whether or not to extend an existing same table");
163  desc.add<bool>("skipNonExistingSrc", false)
164  ->setComment("whether or not to skip producing the table on absent input product");
165  desc.add<edm::InputTag>("src")->setComment("input collection to fill the flat table");
166 
168  variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
169  variable.add<std::string>("doc")->setComment("few words description of the branch content");
170  variable.ifValue(
172  "type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
173  edm::allowedValues<std::string>("int", "uint", "float", "double", "int8", "uint8", "int16", "uint16", "bool"));
174  variable.addOptionalNode(
176  "precision", true, edm::Comment("the precision with which to store the value in the flat table")) xor
178  "precision", true, edm::Comment("the precision with which to store the value in the flat table")),
179  false);
180 
182  variables.setComment("a parameters set to define all variable to fill the flat table");
183  variables.addNode(
185  desc.add<edm::ParameterSetDescription>("variables", variables);
186 
187  return desc;
188  }
189  // this is to be overriden by the child class
190  virtual std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
191  const edm::Handle<TProd> &prod) const = 0;
192 
193  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {
195  iEvent.getByToken(src_, src);
196 
197  std::unique_ptr<nanoaod::FlatTable> out = fillTable(iEvent, src);
198  out->setDoc(doc_);
199 
200  iEvent.put(std::move(out));
201  }
202 
203 protected:
206  const bool extension_;
209 
219  std::vector<std::unique_ptr<Variable<T>>> vars_;
220 };
221 
222 template <typename T>
223 class SimpleFlatTableProducer : public SimpleFlatTableProducerBase<T, edm::View<T>> {
224 public:
227  singleton_(params.getParameter<bool>("singleton")),
228  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
229  : std::numeric_limits<unsigned int>::max()),
230  cut_(!singleton_ ? params.getParameter<std::string>("cut") : "", true) {
231  if (params.existsAs<edm::ParameterSet>("externalVariables")) {
232  edm::ParameterSet const &extvarsPSet = params.getParameter<edm::ParameterSet>("externalVariables");
233  for (const std::string &vname : extvarsPSet.getParameterNamesForType<edm::ParameterSet>()) {
234  const auto &varPSet = extvarsPSet.getParameter<edm::ParameterSet>(vname);
235  const std::string &type = varPSet.getParameter<std::string>("type");
236  if (type == "int")
237  extvars_.push_back(
238  std::make_unique<IntExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
239  else if (type == "uint")
240  extvars_.push_back(
241  std::make_unique<UIntExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
242  else if (type == "float")
243  extvars_.push_back(
244  std::make_unique<FloatExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
245  else if (type == "double")
246  extvars_.push_back(
247  std::make_unique<DoubleExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
248  else if (type == "int8")
249  extvars_.push_back(
250  std::make_unique<Int8ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
251  else if (type == "uint8")
252  extvars_.push_back(
253  std::make_unique<UInt8ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
254  else if (type == "int16")
255  extvars_.push_back(
256  std::make_unique<Int16ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
257  else if (type == "uint16")
258  extvars_.push_back(
259  std::make_unique<UInt16ExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
260  else if (type == "bool")
261  extvars_.push_back(
262  std::make_unique<BoolExtVar>(vname, varPSet, this->consumesCollector(), this->skipNonExistingSrc_));
263  else
264  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
265  }
266  }
267  }
268 
270 
273 
275  "singleton", false, true, edm::Comment("whether or not the input collection is single-element")),
277  "cut", "", true, edm::Comment("selection on the main input collection")) or
278  true >> edm::EmptyGroupDescription());
279  desc.addOptional<unsigned int>("maxLen")->setComment(
280  "define the maximum length of the input collection to put in the branch");
281 
282  edm::ParameterSetDescription extvariable;
283  extvariable.add<edm::InputTag>("src")->setComment("valuemap input collection to fill the flat table");
284  extvariable.add<std::string>("doc")->setComment("few words description of the branch content");
285  extvariable.ifValue(
287  "type", "int", true, edm::Comment("the c++ type of the branch in the flat table")),
288  edm::allowedValues<std::string>("int", "uint", "float", "double", "int8", "uint8", "int16", "uint16", "bool"));
289  extvariable.addOptionalNode(
291  "precision", true, edm::Comment("the precision with which to store the value in the flat table")) xor
293  "precision", true, edm::Comment("the precision with which to store the value in the flat table")),
294  false);
295 
296  edm::ParameterSetDescription extvariables;
297  extvariables.setComment("a parameters set to define all variable taken form valuemap to fill the flat table");
298  extvariables.addOptionalNode(
300  desc.addOptional<edm::ParameterSetDescription>("externalVariables", extvariables);
301 
302  descriptions.addWithDefaultLabel(desc);
303  }
304 
305  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
306  const edm::Handle<edm::View<T>> &prod) const override {
307  std::vector<const T *> selobjs;
308  std::vector<edm::Ptr<T>> selptrs; // for external variables
309  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
310  if (singleton_) {
311  assert(prod->size() == 1);
312  selobjs.push_back(&(*prod)[0]);
313  if (!extvars_.empty())
314  selptrs.emplace_back(prod->ptrAt(0));
315  } else {
316  for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
317  const auto &obj = (*prod)[i];
318  if (cut_(obj)) {
319  selobjs.push_back(&obj);
320  if (!extvars_.empty())
321  selptrs.emplace_back(prod->ptrAt(i));
322  }
323  if (selobjs.size() >= maxLen_)
324  break;
325  }
326  }
327  }
328  auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, singleton_, this->extension_);
329  for (const auto &var : this->vars_)
330  var->fill(selobjs, *out);
331  for (const auto &var : this->extvars_)
332  var->fill(iEvent, selptrs, *out);
333  return out;
334  }
335 
336 protected:
338  const unsigned int maxLen_;
340 
350  std::vector<std::unique_ptr<ExtVariable<T>>> extvars_;
351 };
352 
353 template <typename T>
355 public:
358  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
359  : std::numeric_limits<unsigned int>::max()),
360  cut_(params.getParameter<std::string>("cut"), true),
361  minBX_(params.getParameter<int>("minBX")),
362  maxBX_(params.getParameter<int>("maxBX")),
363  alwaysWriteBXValue_(params.getParameter<bool>("alwaysWriteBXValue")),
364  bxVarName_("bx") {
365  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
367  if (std::find(varNames.begin(), varNames.end(), bxVarName_) != varNames.end()) {
368  throw cms::Exception("Configuration",
369  "BXVectorSimpleFlatTableProducer already defines the " + bxVarName_ +
370  "internally and thus you should not specify it yourself");
371  }
372  }
373 
376  desc.add<std::string>("cut", "")->setComment(
377  "selection on the main input collection (but selection can not be bx based)");
378  desc.addOptional<unsigned int>("maxLen")->setComment(
379  "define the maximum length of the input collection to put in the branch");
380  desc.add<int>("minBX", -2)->setComment("min bx (inclusive) to include");
381  desc.add<int>("maxBX", 2)->setComment("max bx (inclusive) to include");
382  desc.add<bool>("alwaysWriteBXValue", true)
383  ->setComment("always write the bx number (event when only one bx can be present, ie minBX==maxBX)");
384  descriptions.addWithDefaultLabel(desc);
385  }
386 
387  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
388  const edm::Handle<BXVector<T>> &prod) const override {
389  std::vector<const T *> selObjs;
390  std::vector<int> selObjBXs;
391 
392  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
393  const int minBX = std::max(minBX_, prod->getFirstBX());
394  const int maxBX = std::min(maxBX_, prod->getLastBX());
395  for (int bx = minBX; bx <= maxBX; bx++) {
396  for (size_t objNr = 0, nrObjs = prod->size(bx); objNr < nrObjs; ++objNr) {
397  const auto &obj = prod->at(bx, objNr);
398  if (cut_(obj)) {
399  selObjs.push_back(&obj);
400  selObjBXs.push_back(bx);
401  }
402  if (selObjs.size() >= maxLen_)
403  break;
404  }
405  }
406  }
407  auto out = std::make_unique<nanoaod::FlatTable>(selObjs.size(), this->name_, false, this->extension_);
408  for (const auto &var : this->vars_)
409  var->fill(selObjs, *out);
410  if (alwaysWriteBXValue_ || minBX_ != maxBX_) {
411  out->template addColumn<int16_t>(bxVarName_, selObjBXs, "BX of the L1 candidate");
412  }
413  return out;
414  }
415 
416 protected:
417  const unsigned int maxLen_;
419  const int minBX_;
420  const int maxBX_;
423 };
424 
425 template <typename T>
427 public:
429 
431 
434  descriptions.addWithDefaultLabel(desc);
435  }
436 
437  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &, const edm::Handle<T> &prod) const override {
438  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
439  std::vector<const T *> selobjs(1, prod.product());
440  for (const auto &var : this->vars_)
441  var->fill(selobjs, *out);
442  return out;
443  }
444 };
445 
446 template <typename T>
448 public:
451 
453 
456  descriptions.addWithDefaultLabel(desc);
457  }
458 
459  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
460  const edm::Handle<edm::View<T>> &prod) const override {
461  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
462  std::vector<const T *> selobjs(1, &(*prod)[0]);
463  for (const auto &var : this->vars_)
464  var->fill(selobjs, *out);
465  return out;
466  }
467 };
468 
469 // LuminosityBlock producers
470 // - ABC
471 // - Singleton
472 // - Collection
473 template <typename T, typename TProd>
475  : public edm::one::EDProducer<edm::EndLuminosityBlockProducer, edm::LuminosityBlockCache<int>> {
476 public:
478  : name_(params.getParameter<std::string>("name")),
479  doc_(params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""),
480  extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false),
482 
483  params.existsAs<bool>("skipNonExistingSrc") ? params.getParameter<bool>("skipNonExistingSrc") : false),
484  src_(consumes<TProd, edm::InLumi>(params.getParameter<edm::InputTag>("src"))) {
485  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
486  for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
487  const auto &varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
488  const std::string &type = varPSet.getParameter<std::string>("type");
489  if (type == "int")
490  vars_.push_back(std::make_unique<IntVar>(vname, varPSet));
491  else if (type == "float")
492  vars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
493  else if (type == "uint8")
494  vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
495  else if (type == "bool")
496  vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
497  else
498  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
499  }
500 
501  produces<nanoaod::FlatTable, edm::Transition::EndLuminosityBlock>();
502  }
503 
505 
506  std::shared_ptr<int> globalBeginLuminosityBlock(edm::LuminosityBlock const &,
507  edm::EventSetup const &) const override {
508  return nullptr;
509  }
510 
512 
513  // this is to be overriden by the child class
514  virtual std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::LuminosityBlock &iLumi,
515  const edm::Handle<TProd> &prod) const = 0;
516 
517  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {
518  // do nothing
519  }
520 
523  iLumi.getByToken(src_, src);
524 
525  std::unique_ptr<nanoaod::FlatTable> out = fillTable(iLumi, src);
526  out->setDoc(doc_);
527 
528  iLumi.put(std::move(out));
529  }
530 
531 protected:
534  const bool extension_;
537 
542  std::vector<std::unique_ptr<Variable<T>>> vars_;
543 };
544 
545 // Class for singletons like GenFilterInfo
546 template <typename T>
548 public:
551 
553 
556  descriptions.addWithDefaultLabel(desc);
557  }
558 
559  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::LuminosityBlock &,
560  const edm::Handle<T> &prod) const override {
561  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
562  std::vector<const T *> selobjs(1, prod.product());
563  for (const auto &var : this->vars_)
564  var->fill(selobjs, *out);
565  return out;
566  }
567 };
568 
569 // Class for generic collections
570 template <typename T, typename TProd>
572 public:
575  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
576  : std::numeric_limits<unsigned int>::max()),
577  cut_(params.existsAs<std::string>("cut") ? params.getParameter<std::string>("cut") : "", true) {}
578 
580 
583  desc.addOptional<unsigned int>("maxLen")->setComment(
584  "define the maximum length of the input collection to put in the branch");
585  descriptions.addWithDefaultLabel(desc);
586  }
587 
588  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::LuminosityBlock &iLumi,
589  const edm::Handle<TProd> &prod) const override {
590  std::vector<const T *> selobjs;
591  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
592  for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
593  const auto &obj = (*prod)[i];
594  if (cut_(obj)) {
595  selobjs.push_back(&obj);
596  }
597  if (selobjs.size() >= maxLen_)
598  break;
599  }
600  }
601  auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, false, this->extension_);
602  for (const auto &var : this->vars_)
603  var->fill(selobjs, *out);
604  return out;
605  }
606 
607 protected:
608  const unsigned int maxLen_;
610 };
611 
612 // Run producers
613 // - ABC
614 // - Singleton
615 // - Collection
616 template <typename T, typename TProd>
617 class SimpleFlatTableProducerBaseRun : public edm::one::EDProducer<edm::EndRunProducer, edm::RunCache<int>> {
618 public:
620  : name_(params.getParameter<std::string>("name")),
621  doc_(params.existsAs<std::string>("doc") ? params.getParameter<std::string>("doc") : ""),
622  extension_(params.existsAs<bool>("extension") ? params.getParameter<bool>("extension") : false),
624 
625  params.existsAs<bool>("skipNonExistingSrc") ? params.getParameter<bool>("skipNonExistingSrc") : false),
626  src_(consumes<TProd, edm::InRun>(params.getParameter<edm::InputTag>("src"))) {
627  edm::ParameterSet const &varsPSet = params.getParameter<edm::ParameterSet>("variables");
628  for (const std::string &vname : varsPSet.getParameterNamesForType<edm::ParameterSet>()) {
629  const auto &varPSet = varsPSet.getParameter<edm::ParameterSet>(vname);
630  const std::string &type = varPSet.getParameter<std::string>("type");
631  if (type == "int")
632  vars_.push_back(std::make_unique<IntVar>(vname, varPSet));
633  else if (type == "float")
634  vars_.push_back(std::make_unique<FloatVar>(vname, varPSet));
635  else if (type == "uint8")
636  vars_.push_back(std::make_unique<UInt8Var>(vname, varPSet));
637  else if (type == "bool")
638  vars_.push_back(std::make_unique<BoolVar>(vname, varPSet));
639  else
640  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + vname);
641  }
642 
643  produces<nanoaod::FlatTable, edm::Transition::EndRun>();
644  }
645 
647 
648  std::shared_ptr<int> globalBeginRun(edm::Run const &, edm::EventSetup const &) const override { return nullptr; }
649 
650  void globalEndRun(edm::Run const &, edm::EventSetup const &) override {}
651 
652  // this is to be overriden by the child class
653  virtual std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Run &iRun, const edm::Handle<TProd> &prod) const = 0;
654 
655  void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override {
656  // do nothing
657  }
658 
659  void endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) final {
661  iRun.getByToken(src_, src);
662 
663  std::unique_ptr<nanoaod::FlatTable> out = fillTable(iRun, src);
664  out->setDoc(doc_);
665 
666  iRun.put(std::move(out));
667  }
668 
669 protected:
672  const bool extension_;
675 
680  std::vector<std::unique_ptr<Variable<T>>> vars_;
681 };
682 
683 // Class for singletons like GenFilterInfo
684 template <typename T>
686 public:
688 
690 
691  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Run &, const edm::Handle<T> &prod) const override {
692  auto out = std::make_unique<nanoaod::FlatTable>(1, this->name_, true, this->extension_);
693  std::vector<const T *> selobjs(1, prod.product());
694  for (const auto &var : this->vars_)
695  var->fill(selobjs, *out);
696  return out;
697  }
698 };
699 
700 // Class for generic collections
701 template <typename T, typename TProd>
703 public:
706  maxLen_(params.existsAs<unsigned int>("maxLen") ? params.getParameter<unsigned int>("maxLen")
707  : std::numeric_limits<unsigned int>::max()),
708  cut_(params.existsAs<std::string>("cut") ? params.getParameter<std::string>("cut") : "", true) {}
709 
711 
712  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Run &iRun, const edm::Handle<TProd> &prod) const override {
713  std::vector<const T *> selobjs;
714  if (prod.isValid() || !(this->skipNonExistingSrc_)) {
715  for (unsigned int i = 0, n = prod->size(); i < n; ++i) {
716  const auto &obj = (*prod)[i];
717  if (cut_(obj)) {
718  selobjs.push_back(&obj);
719  }
720  if (selobjs.size() >= maxLen_)
721  break;
722  }
723  }
724  auto out = std::make_unique<nanoaod::FlatTable>(selobjs.size(), this->name_, false, this->extension_);
725  for (const auto &var : this->vars_)
726  var->fill(selobjs, *out);
727  return out;
728  }
729 
730 protected:
731  const unsigned int maxLen_;
733 };
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:303
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)
ValueMapVariable< T, int, int8_t > Int8ExtVar
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:179
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
FuncVariable< T, StringObjectFunction< T >, int8_t > Int8Var
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()