CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MuDigiBaseProducer.h
Go to the documentation of this file.
1 #ifndef MuonTools_MuDigiBaseProducer_h
2 #define MuonTools_MuDigiBaseProducer_h
3 
16 
17 #include <algorithm>
18 #include <list>
19 #include <string>
20 
21 template <class DETECTOR_T, class DIGI_T>
22 class MuDigiBaseProducer : public SimpleFlatTableProducerBase<DIGI_T, MuonDigiCollection<DETECTOR_T, DIGI_T>> {
24 
29 
30  std::vector<std::unique_ptr<Variable<DETECTOR_T>>> detIdVars_;
31 
32 public:
34  const auto &varCfgs = params.getParameter<edm::ParameterSet>("detIdVariables");
35  const auto &varNames = varCfgs.getParameterNamesForType<edm::ParameterSet>();
36 
37  std::transform(varNames.begin(), varNames.end(), std::back_inserter(detIdVars_), [&](const auto &name) {
38  const edm::ParameterSet &varCfg = varCfgs.getParameter<edm::ParameterSet>(name);
39  const std::string &type = varCfg.getParameter<std::string>("type");
40 
41  std::unique_ptr<Variable<DETECTOR_T>> detVarPtr;
42 
43  if (type == "int") {
44  detVarPtr = std::move(std::make_unique<IntDetVar>(name, varCfg));
45  } else if (type == "uint") {
46  detVarPtr = std::move(std::make_unique<UIntDetVar>(name, varCfg));
47  } else if (type == "int16") {
48  detVarPtr = std::move(std::make_unique<Int16DetVar>(name, varCfg));
49  } else if (type == "uint8") {
50  detVarPtr = std::move(std::make_unique<UInt8DetVar>(name, varCfg));
51  } else {
52  throw cms::Exception("Configuration", "unsupported type " + type + " for variable " + name);
53  }
54 
55  return detVarPtr;
56  });
57  }
58 
59  ~MuDigiBaseProducer() override {}
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
63 
65  edm::Comment comType{"the c++ type of the branch in the flat table"};
66  edm::Comment comPrecision{"the precision with which to store the value in the flat table"};
67 
68  variable.add<std::string>("expr")->setComment("a function to define the content of the branch in the flat table");
69  variable.add<std::string>("doc")->setComment("few words description of the branch content");
70  variable.addUntracked<bool>("lazyEval")->setComment("set to True if the type read from the Event is unknown");
71 
72  variable.ifValue(edm::ParameterDescription<std::string>("type", "int", true, comType),
73  edm::allowedValues<std::string>("int", "uint", "int16", "uint8"));
74 
76 
77  variables.setComment("a parameters set to define all variable taken form detId to fill the flat table");
78 
80  variables.addNode(variableWildCard);
81 
82  desc.add<edm::ParameterSetDescription>("detIdVariables", variables);
83 
84  descriptions.addWithDefaultLabel(desc);
85  }
86 
87  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
88  const edm::Handle<COLLECTION> &prod) const override {
89  std::vector<const DIGI_T *> digis;
90  std::vector<const DETECTOR_T *> detIds;
91  std::list<DETECTOR_T> detIdObjs; // CB needed to store DetIds (they are transient)
92 
93  if (prod.isValid()) {
94  auto detIdIt = prod->begin();
95  auto detIdEnd = prod->end();
96 
97  for (; detIdIt != detIdEnd; ++detIdIt) {
98  const auto &[detId, range] = (*detIdIt);
99  detIdObjs.push_back(detId);
100  std::fill_n(std::back_inserter(detIds), range.second - range.first, &detIdObjs.back());
101  std::transform(range.first, range.second, std::back_inserter(digis), [](const auto &digi) { return &digi; });
102  }
103  }
104 
105  auto table = std::make_unique<nanoaod::FlatTable>(digis.size(), this->name_, false, this->extension_);
106 
107  for (const auto &var : this->vars_) {
108  var->fill(digis, *table);
109  }
110 
111  for (const auto &var : detIdVars_) {
112  var->fill(detIds, *table);
113  }
114 
115  return table;
116  }
117 };
118 
119 #endif
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::unique_ptr< nanoaod::FlatTable > fillTable(const edm::Event &iEvent, const edm::Handle< COLLECTION > &prod) const override
constexpr char const * varNames[]
int iEvent
Definition: GenABIO.cc:224
MuDigiBaseProducer(edm::ParameterSet const &params)
~MuDigiBaseProducer() override
std::vector< std::unique_ptr< Variable< DETECTOR_T > > > detIdVars_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
def move(src, dest)
Definition: eostools.py:511
static edm::ParameterSetDescription baseDescriptions()
unsigned transform(const HcalDetId &id, unsigned transformCode)
A container for a generic type of digis indexed by some index, implemented with a map<IndexType...