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 
HcalDbProducer::TokenAndTopologyHolder::token
const auto & token() const
Definition: HcalDbProducer.cc:154
HcalTPChannelParametersRcd
Definition: HcalTPChannelParametersRcd.h:7
mixOne_cfi.ESProducer
ESProducer
Definition: mixOne_cfi.py:33
edm::ESInputTag
Definition: ESInputTag.h:87
HcalSiPMCharacteristicsRcd
Definition: HcalSiPMCharacteristicsRcd.h:4
HcalElectronicsMapRcd
Definition: HcalElectronicsMapRcd.h:8
ESTransientHandle.h
HcalLutMetadataRcd
Definition: HcalLutMetadataRcd.h:25
HcalDbProducer::TokensForServiceHolder::setupHcalDbService
void setupHcalDbService(HostType &host, const HcalDbRecord &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
Definition: HcalDbProducer.cc:121
HcalDbProducer::ServiceTokenImpl
Definition: HcalDbProducer.cc:80
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:61
TypeDemangler.h
HcalChannelQualityRcd
Definition: HcalChannelQualityRcd.h:8
HcalGainsRcd
Definition: HcalGainsRcd.h:8
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::typeDemangle
std::string typeDemangle(char const *mangledName)
Definition: TypeDemangler.cc:93
HcalDbProducer::serviceSetData
static void serviceSetData(HostType &host, const ProductType &item, std::false_type)
Definition: HcalDbProducer.cc:72
HcalDbProducer::mDumpStream
std::ostream * mDumpStream
Definition: HcalDbProducer.cc:262
HcalL1TriggerObjectsRcd
Definition: HcalL1TriggerObjectsRcd.h:25
AllObjects.h
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HcalDbProducer::HcalDbProducer
HcalDbProducer(const edm::ParameterSet &)
Definition: HcalDbProducer.cc:265
HcalDbProducer::serviceSetData
static void serviceSetData(HostType &host, const ProductType &item, std::true_type)
Definition: HcalDbProducer.cc:76
HcalMCParamsRcd
Definition: HcalMCParamsRcd.h:6
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
ESProducer.h
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
HcalDbProducer::TokensForServiceHolder::tokens_
std::tuple< ServiceTokenImpl< typename TokenHolders::Product, RecordType, TokenHolders::label, typename TokenHolders::Effective >... > tokens_
Definition: HcalDbProducer.cc:137
HcalDbProducer::TokensForServiceHolder::setConsumes
void setConsumes(edm::ESConsumesCollector &cc)
Definition: HcalDbProducer.cc:118
apply
Vec apply(Vec v, F f)
Definition: ExtVec.h:81
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
HcalDbProducer::TokenAndTopologyHolder::topoToken
const auto & topoToken() const
Definition: HcalDbProducer.cc:156
HcalDbProducer::TokenAndTopologyHolder::topoToken_
edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > topoToken_
Definition: HcalDbProducer.cc:160
HcalDbProducer::TokenAndTopologyHolder::setConsumes
void setConsumes(edm::ESConsumesCollector &&cc, const edm::ESInputTag &tag)
Definition: HcalDbProducer.cc:149
HcalDbProducer::setupProduceAll
void setupProduceAll(const char *label, const edm::ESInputTag &tag)
Definition: HcalDbProducer.cc:195
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
HcalGainWidthsRcd
Definition: HcalGainWidthsRcd.h:8
query.host
string host
Definition: query.py:115
HcalLUTCorrsRcd
Definition: HcalLUTCorrsRcd.h:25
HcalDbProducer::TokenAndTopologyHolder::Product
ProductT Product
Definition: HcalDbProducer.cc:144
edm::ReusableObjectHolder< HostType >
edm::ReusableObjectHolder::makeOrGet
std::shared_ptr< T > makeOrGet(F iFunc)
If there isn't an object already available, creates a new one using iFunc.
Definition: ReusableObjectHolder.h:126
HcalDbProducer::ServiceTokenImpl::token_
edm::ESGetToken< ProductType, RecordType > token_
Definition: HcalDbProducer.cc:104
HcalDbProducer::ServiceTokenImpl::setupHcalDbService
void setupHcalDbService(HostType &host, const RecordType &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
Definition: HcalDbProducer.cc:90
HcalQIETypesRcd
Definition: HcalQIETypesRcd.h:25
HcalSiPMParametersRcd
Definition: HcalSiPMParametersRcd.h:7
ReusableObjectHolder.h
HcalDbProducer::produceWithTopology
std::unique_ptr< ProductType > produceWithTopology(RecordType const &record)
Definition: HcalDbProducer.cc:164
HcalDbProducer::tokensForService_
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_
Definition: HcalDbProducer.cc:233
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
HcalDbProducer::ServiceToken::Product
ProductType Product
Definition: HcalDbProducer.cc:110
edm::es::Label
Definition: es_Label.h:56
HcalDbProducer::TokensForServiceHolder
Definition: HcalDbProducer.cc:116
HcalPedestalWidthsRcd
Definition: HcalPedestalWidthsRcd.h:8
HcalDbRecord.h
HcalTPParametersRcd
Definition: HcalTPParametersRcd.h:4
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalDbProducer::setupProduceAllImpl
void setupProduceAllImpl(const char *label, const edm::ESInputTag &tag, std::index_sequence< IND2s... >)
Definition: HcalDbProducer.cc:190
HcalDbProducer::kWithTopoEff
constexpr static const char kWithTopoEff[]
Definition: HcalDbProducer.cc:204
HcalDbProducer::ServiceToken
Definition: HcalDbProducer.cc:109
HcalDbProducer::produce
std::shared_ptr< HcalDbService > produce(const HcalDbRecord &)
Definition: HcalDbProducer.cc:287
edm::ParameterSet
Definition: ParameterSet.h:47
HcalPFCorrsRcd
Definition: HcalPFCorrsRcd.h:25
HcalDbProducer::TokenAndTopologyHolder::TokenAndTopologyHolder
TokenAndTopologyHolder()=default
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
HcalDbProducer::ServiceTokenImpl::setConsumes
void setConsumes(edm::ESConsumesCollector &cc)
Definition: HcalDbProducer.cc:89
HcalDbProducer::setupProduce
void setupProduce(const char *label, const edm::ESInputTag &tag)
Definition: HcalDbProducer.cc:176
HcalFrontEndMapRcd
Definition: HcalFrontEndMapRcd.h:7
HcalAllRcds.h
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
HcalZSThresholdsRcd
Definition: HcalZSThresholdsRcd.h:25
HcalRespCorrsRcd
Definition: HcalRespCorrsRcd.h:27
HcalDbProducer::ServiceTokenImpl::ServiceTokenImpl
ServiceTokenImpl()
Definition: HcalDbProducer.cc:82
cc
edm::ESGetToken< ProductType, RecordType >
HcalDbProducer::mDumpRequest
std::vector< std::string > mDumpRequest
Definition: HcalDbProducer.cc:261
HcalDbProducer::TokenAndTopologyHolder::token_
edm::ESGetToken< ProductT, RecordT > token_
Definition: HcalDbProducer.cc:159
HcalDbProducer::kWithTopo
constexpr static const char kWithTopo[]
Definition: HcalDbProducer.cc:205
HcalDbASCIIIO::dumpObject
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
ModuleFactory.h
edm::ESProductHost
Definition: ESProductHost.h:93
DependentRecordImplementation.h
HcalDbService
Definition: HcalDbService.h:26
HcalDbProducer::ServiceTokenImpl::dumpName_
std::string dumpName_
Definition: HcalDbProducer.cc:105
HcalDbASCIIIO.h
HcalDbProducer::HostType
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
Definition: HcalDbProducer.cc:68
DEFINE_FWK_EVENTSETUP_MODULE
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
HcalDbProducer::holder_
edm::ReusableObjectHolder< HostType > holder_
Definition: HcalDbProducer.cc:201
HcalQIEDataRcd
Definition: HcalQIEDataRcd.h:8
HcalDbProducer::TokenAndTopologyHolder
Definition: HcalDbProducer.cc:142
HcalDbProducer
Definition: HcalDbProducer.cc:38
Record
relativeConstraints.value
value
Definition: relativeConstraints.py:53
HcalPedestalsRcd
Definition: HcalPedestalsRcd.h:9
HcalRecoParamsRcd
Definition: HcalRecoParamsRcd.h:6
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
HcalDbService.h
edm::ESProducer
Definition: ESProducer.h:104
ESProductHost.h
HcalDbRecord
Definition: HcalDbRecord.h:30
HcalDbProducer::~HcalDbProducer
~HcalDbProducer() override
Definition: HcalDbProducer.cc:281
HcalTimeCorrsRcd
Definition: HcalTimeCorrsRcd.h:25
HcalDbProducer::ServiceToken::Effective
EffectiveType Effective
Definition: HcalDbProducer.cc:112
label
const char * label
Definition: PFTauDecayModeTools.cc:11
HcalDbProducer::tokenHolders_
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_
Definition: HcalDbProducer.cc:259
HcalDbProducer::ServiceToken::label
static constexpr const char * label
Definition: HcalDbProducer.cc:111
HcalDbProducer::kEmpty
constexpr static const char kEmpty[]
Definition: HcalDbProducer.cc:206