CMS 3D CMS Logo

HcalDbProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalDbProducer
4 // Class: HcalDbProducer
5 //
13 //
14 // Original Author: Fedor Ratnikov
15 // Created: Tue Aug 9 19:10:10 CDT 2005
16 //
17 //
18 
19 // system include files
20 #include <iostream>
21 #include <fstream>
22 #include <memory>
23 
31 
37 
39 public:
41  ~HcalDbProducer() override;
42 
43  std::shared_ptr<HcalDbService> produce(const HcalDbRecord&);
44 
45 private:
69 
70  // Helper functions and class for the tokens and work for HcalDbService
71  template <typename ProductType>
72  static void serviceSetData(HostType& host, const ProductType& item, std::false_type) {
73  host.setData(&item);
74  }
75  template <typename ProductType>
76  static void serviceSetData(HostType& host, const ProductType& item, std::true_type) {
77  host.setData(&item, true);
78  }
79  template <typename ProductType, typename RecordType, const char* LABEL, typename EffectiveType>
81  public:
83  : dumpName_(edm::typeDemangle(typeid(ProductType).name()).substr(4)) // remove leading "Hcal"
84  {
85  if constexpr (EffectiveType::value) {
86  dumpName_ = "Effective" + dumpName_;
87  }
88  }
89  void setConsumes(edm::ESConsumesCollector& cc) { token_ = cc.consumes(edm::ESInputTag{"", LABEL}); }
91  const RecordType& record,
92  const std::vector<std::string>& dumpRequest,
93  std::ostream* dumpStream) {
94  const auto& item = record.get(token_);
95  serviceSetData(host, item, EffectiveType{});
96 
97  if (std::find(dumpRequest.begin(), dumpRequest.end(), dumpName_) != dumpRequest.end()) {
98  *dumpStream << "New HCAL " << dumpName_ << " set" << std::endl;
99  HcalDbASCIIIO::dumpObject(*dumpStream, item);
100  }
101  }
102 
103  private:
106  };
107 
108  template <typename ProductType, const char* LABEL, typename EffectiveType = std::false_type>
109  struct ServiceToken {
110  using Product = ProductType;
111  static constexpr const char* label = LABEL;
112  using Effective = EffectiveType;
113  };
114 
115  template <typename RecordType, typename... TokenHolders>
117  public:
119  std::apply([&cc](auto&&... item) { ((item.setConsumes(cc)), ...); }, tokens_);
120  }
122  const HcalDbRecord& record,
123  const std::vector<std::string>& dumpRequest,
124  std::ostream* dumpStream) {
125  host.ifRecordChanges<RecordType>(record, [this, &host, &dumpRequest, &dumpStream](auto const& rec) {
126  std::apply([&host, &rec, &dumpRequest, &dumpStream](
127  auto&&... item) { ((item.setupHcalDbService(host, rec, dumpRequest, dumpStream)), ...); },
128  tokens_);
129  });
130  }
131 
132  private:
133  std::tuple<ServiceTokenImpl<typename TokenHolders::Product,
134  RecordType,
136  typename TokenHolders::Effective>...>
138  };
139 
140  // Helper class and functions for the individual products
141  template <typename ProductT, typename RecordT>
143  public:
144  using Product = ProductT;
145  using Record = RecordT;
146 
147  TokenAndTopologyHolder() = default;
148 
150  token_ = cc.consumes(tag);
151  topoToken_ = cc.consumes();
152  }
153 
154  const auto& token() const { return token_; }
155 
156  const auto& topoToken() const { return topoToken_; }
157 
158  private:
161  };
162 
163  template <typename ProductType, typename RecordType, size_t IND1, size_t IND2>
164  std::unique_ptr<ProductType> produceWithTopology(RecordType const& record) {
165  const auto& tokenHolder = std::get<IND2>(std::get<IND1>(tokenHolders_));
166  auto item = record.getTransientHandle(tokenHolder.token());
167 
168  auto productWithTopology = std::make_unique<ProductType>(*item);
169  const auto& topo = record.get(tokenHolder.topoToken());
170  productWithTopology->setTopo(&topo);
171 
172  return productWithTopology;
173  }
174 
175  template <size_t IND1, size_t IND2>
176  void setupProduce(const char* label, const edm::ESInputTag& tag) {
177  auto& holder = std::get<IND2>(std::get<IND1>(tokenHolders_));
178 
179  using HolderT = typename std::remove_reference<decltype(holder)>::type;
180  using ProductT = typename HolderT::Product;
181  using RecordT = typename HolderT::Record;
182 
183  holder.setConsumes(
185  this, &HcalDbProducer::produceWithTopology<ProductT, RecordT, IND1, IND2>, edm::es::Label(label)),
186  tag);
187  }
188 
189  template <size_t IND1, size_t... IND2s>
190  void setupProduceAllImpl(const char* label, const edm::ESInputTag& tag, std::index_sequence<IND2s...>) {
191  ((setupProduce<IND1, IND2s>(label, tag)), ...);
192  }
193 
194  template <size_t IND1>
195  void setupProduceAll(const char* label, const edm::ESInputTag& tag) {
196  setupProduceAllImpl<IND1>(
197  label, tag, std::make_index_sequence<std::tuple_size_v<std::tuple_element_t<IND1, decltype(tokenHolders_)>>>{});
198  }
199 
200  // ----------member data ---------------------------
202 
203  // Tokens for the "service" produce function
204  constexpr static const char kWithTopoEff[] = "withTopoEff";
205  constexpr static const char kWithTopo[] = "withTopo";
206  constexpr static const char kEmpty[] = "";
234 
235  // Tokens for the produceWithTopology functions
236  std::tuple<
237  // First are withTopo
238  std::tuple<TokenAndTopologyHolder<HcalPedestals, HcalPedestalsRcd>,
256  // Then withTopoEff
257  std::tuple<TokenAndTopologyHolder<HcalPedestals, HcalPedestalsRcd>,
260 
261  std::vector<std::string> mDumpRequest;
262  std::ostream* mDumpStream;
263 };
264 
265 HcalDbProducer::HcalDbProducer(const edm::ParameterSet& fConfig) : ESProducer(), mDumpRequest(), mDumpStream(nullptr) {
266  auto cc = setWhatProduced(this);
267  std::apply([&cc](auto&&... item) { ((item.setConsumes(cc)), ...); }, tokensForService_);
268 
269  // Setup all withTopo produces functions and their consumes
270  setupProduceAll<0>("withTopo", edm::ESInputTag{});
271  // Setup all withTopoEff produces functions and their consumes
272  setupProduceAll<1>("withTopoEff", edm::ESInputTag{"", "effective"});
273 
274  mDumpRequest = fConfig.getUntrackedParameter<std::vector<std::string>>("dump", std::vector<std::string>());
275  if (!mDumpRequest.empty()) {
276  std::string otputFile = fConfig.getUntrackedParameter<std::string>("file", "");
277  mDumpStream = otputFile.empty() ? &std::cout : new std::ofstream(otputFile.c_str());
278  }
279 }
280 
282  if (mDumpStream != &std::cout)
283  delete mDumpStream;
284 }
285 
286 // ------------ method called to produce the data ------------
287 std::shared_ptr<HcalDbService> HcalDbProducer::produce(const HcalDbRecord& record) {
288  auto host = holder_.makeOrGet([]() { return new HostType; });
289 
290  std::apply([this, &host, &record](
291  auto&&... item) { ((item.setupHcalDbService(*host, record, mDumpRequest, mDumpStream)), ...); },
293 
294  return host;
295 }
296 
static void serviceSetData(HostType &host, const ProductType &item, std::true_type)
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
std::tuple< TokensForServiceHolder< HcalPedestalWidthsRcd, ServiceToken< HcalPedestalWidths, kWithTopoEff, std::true_type >, ServiceToken< HcalPedestalWidths, kWithTopo > >, TokensForServiceHolder< HcalPedestalsRcd, ServiceToken< HcalPedestals, kWithTopoEff, std::true_type >, ServiceToken< HcalPedestals, kWithTopo > >, TokensForServiceHolder< HcalRecoParamsRcd, ServiceToken< HcalRecoParams, kWithTopo > >, TokensForServiceHolder< HcalMCParamsRcd, ServiceToken< HcalMCParams, kWithTopo > >, TokensForServiceHolder< HcalLutMetadataRcd, ServiceToken< HcalLutMetadata, kWithTopo > >, TokensForServiceHolder< HcalTPParametersRcd, ServiceToken< HcalTPParameters, kEmpty > >, TokensForServiceHolder< HcalTPChannelParametersRcd, ServiceToken< HcalTPChannelParameters, kWithTopo > >, TokensForServiceHolder< HcalSiPMCharacteristicsRcd, ServiceToken< HcalSiPMCharacteristics, kEmpty > >, TokensForServiceHolder< HcalSiPMParametersRcd, ServiceToken< HcalSiPMParameters, kWithTopo > >, TokensForServiceHolder< HcalFrontEndMapRcd, ServiceToken< HcalFrontEndMap, kEmpty > >, TokensForServiceHolder< HcalElectronicsMapRcd, ServiceToken< HcalElectronicsMap, kEmpty > >, TokensForServiceHolder< HcalL1TriggerObjectsRcd, ServiceToken< HcalL1TriggerObjects, kWithTopo > >, TokensForServiceHolder< HcalZSThresholdsRcd, ServiceToken< HcalZSThresholds, kWithTopo > >, TokensForServiceHolder< HcalChannelQualityRcd, ServiceToken< HcalChannelQuality, kWithTopo > >, TokensForServiceHolder< HcalGainWidthsRcd, ServiceToken< HcalGainWidths, kWithTopo > >, TokensForServiceHolder< HcalQIETypesRcd, ServiceToken< HcalQIETypes, kWithTopo > >, TokensForServiceHolder< HcalQIEDataRcd, ServiceToken< HcalQIEData, kWithTopo > >, TokensForServiceHolder< HcalTimeCorrsRcd, ServiceToken< HcalTimeCorrs, kWithTopo > >, TokensForServiceHolder< HcalPFCorrsRcd, ServiceToken< HcalPFCorrs, kWithTopo > >, TokensForServiceHolder< HcalLUTCorrsRcd, ServiceToken< HcalLUTCorrs, kWithTopo > >, TokensForServiceHolder< HcalGainsRcd, ServiceToken< HcalGains, kWithTopo > >, TokensForServiceHolder< HcalRespCorrsRcd, ServiceToken< HcalRespCorrs, kWithTopo > > > tokensForService_
string host
Definition: query.py:115
std::tuple< std::tuple< TokenAndTopologyHolder< HcalPedestals, HcalPedestalsRcd >, TokenAndTopologyHolder< HcalPedestalWidths, HcalPedestalWidthsRcd >, TokenAndTopologyHolder< HcalGains, HcalGainsRcd >, TokenAndTopologyHolder< HcalGainWidths, HcalGainWidthsRcd >, TokenAndTopologyHolder< HcalQIEData, HcalQIEDataRcd >, TokenAndTopologyHolder< HcalQIETypes, HcalQIETypesRcd >, TokenAndTopologyHolder< HcalChannelQuality, HcalChannelQualityRcd >, TokenAndTopologyHolder< HcalZSThresholds, HcalZSThresholdsRcd >, TokenAndTopologyHolder< HcalRespCorrs, HcalRespCorrsRcd >, TokenAndTopologyHolder< HcalL1TriggerObjects, HcalL1TriggerObjectsRcd >, TokenAndTopologyHolder< HcalTimeCorrs, HcalTimeCorrsRcd >, TokenAndTopologyHolder< HcalLUTCorrs, HcalLUTCorrsRcd >, TokenAndTopologyHolder< HcalPFCorrs, HcalPFCorrsRcd >, TokenAndTopologyHolder< HcalLutMetadata, HcalLutMetadataRcd >, TokenAndTopologyHolder< HcalSiPMParameters, HcalSiPMParametersRcd >, TokenAndTopologyHolder< HcalTPChannelParameters, HcalTPChannelParametersRcd >, TokenAndTopologyHolder< HcalMCParams, HcalMCParamsRcd >, TokenAndTopologyHolder< HcalRecoParams, HcalRecoParamsRcd > >, std::tuple< TokenAndTopologyHolder< HcalPedestals, HcalPedestalsRcd >, TokenAndTopologyHolder< HcalPedestalWidths, HcalPedestalWidthsRcd > > > tokenHolders_
void setConsumes(edm::ESConsumesCollector &&cc, const edm::ESInputTag &tag)
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
HcalDbProducer(const edm::ParameterSet &)
void setupHcalDbService(HostType &host, const RecordType &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void setupProduceAll(const char *label, const edm::ESInputTag &tag)
void setupHcalDbService(HostType &host, const HcalDbRecord &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
T getUntrackedParameter(std::string const &, T const &) const
edm::ESGetToken< ProductType, RecordType > token_
char const * label
std::unique_ptr< ProductType > produceWithTopology(RecordType const &record)
static constexpr const char * label
std::vector< std::string > mDumpRequest
static constexpr const char kEmpty[]
void setupProduce(const char *label, const edm::ESInputTag &tag)
void setConsumes(edm::ESConsumesCollector &cc)
void setupProduceAllImpl(const char *label, const edm::ESInputTag &tag, std::index_sequence< IND2s... >)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:61
std::shared_ptr< T > makeOrGet(FM &&iMakeFunc)
Takes an object from the queue if one is available, or creates one using iMakeFunc.
static constexpr const char kWithTopoEff[]
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > topoToken_
static constexpr const char kWithTopo[]
void setConsumes(edm::ESConsumesCollector &cc)
static void serviceSetData(HostType &host, const ProductType &item, std::false_type)
std::string typeDemangle(char const *mangledName)
~HcalDbProducer() override
HLT enums.
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
edm::ESProductHost< HcalDbService, HcalPedestalsRcd, HcalPedestalWidthsRcd, HcalGainsRcd, HcalGainWidthsRcd, HcalQIEDataRcd, HcalQIETypesRcd, HcalChannelQualityRcd, HcalZSThresholdsRcd, HcalRespCorrsRcd, HcalL1TriggerObjectsRcd, HcalTimeCorrsRcd, HcalLUTCorrsRcd, HcalPFCorrsRcd, HcalLutMetadataRcd, HcalSiPMParametersRcd, HcalTPChannelParametersRcd, HcalMCParamsRcd, HcalRecoParamsRcd, HcalElectronicsMapRcd, HcalFrontEndMapRcd, HcalSiPMCharacteristicsRcd, HcalTPParametersRcd > HostType
edm::ESGetToken< ProductT, RecordT > token_
std::tuple< ServiceTokenImpl< typename TokenHolders::Product, RecordType, TokenHolders::label, typename TokenHolders::Effective >... > tokens_
std::ostream * mDumpStream
std::shared_ptr< HcalDbService > produce(const HcalDbRecord &)
edm::ReusableObjectHolder< HostType > holder_
Vec apply(Vec v, F f)
Definition: ExtVec.h:77