CMS 3D CMS Logo

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 == "int8") {
48  detVarPtr = std::move(std::make_unique<Int8DetVar>(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 
71  variable.ifValue(edm::ParameterDescription<std::string>("type", "int", true, comType),
72  edm::allowedValues<std::string>("int", "uint", "int8", "uint8"));
73 
75 
76  variables.setComment("a parameters set to define all variable taken form detId to fill the flat table");
77 
79  variables.addNode(variableWildCard);
80 
81  desc.add<edm::ParameterSetDescription>("detIdVariables", variables);
82 
83  descriptions.addWithDefaultLabel(desc);
84  }
85 
86  std::unique_ptr<nanoaod::FlatTable> fillTable(const edm::Event &iEvent,
87  const edm::Handle<COLLECTION> &prod) const override {
88  std::vector<const DIGI_T *> digis;
89  std::vector<const DETECTOR_T *> detIds;
90  std::list<DETECTOR_T> detIdObjs; // CB needed to store DetIds (they are transient)
91 
92  if (prod.isValid()) {
93  auto detIdIt = prod->begin();
94  auto detIdEnd = prod->end();
95 
96  for (; detIdIt != detIdEnd; ++detIdIt) {
97  const auto &[detId, range] = (*detIdIt);
98  detIdObjs.push_back(detId);
99  std::fill_n(std::back_inserter(detIds), range.second - range.first, &detIdObjs.back());
100  std::transform(range.first, range.second, std::back_inserter(digis), [](const auto &digi) { return &digi; });
101  }
102  }
103 
104  auto table = std::make_unique<nanoaod::FlatTable>(digis.size(), this->name_, false, this->extension_);
105 
106  for (const auto &var : this->vars_) {
107  var->fill(digis, *table);
108  }
109 
110  for (const auto &var : detIdVars_) {
111  var->fill(detIds, *table);
112  }
113 
114  return table;
115  }
116 };
117 
118 #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...