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 
32 
38 
40 public:
42  ~HcalDbProducer() override;
43 
44  std::shared_ptr<HcalDbService> produce(const HcalDbRecord&);
45 
46 private:
70 
71  // Helper functions and class for the tokens and work for HcalDbService
72  template <typename ProductType>
73  static void serviceSetData(HostType& host, const ProductType& item, std::false_type) {
74  host.setData(&item);
75  }
76  template <typename ProductType>
77  static void serviceSetData(HostType& host, const ProductType& item, std::true_type) {
78  host.setData(&item, true);
79  }
80  template <typename ProductType, typename RecordType, const char* LABEL, typename EffectiveType>
82  public:
84  : dumpName_(edm::typeDemangle(typeid(ProductType).name()).substr(4)) // remove leading "Hcal"
85  {
86  if constexpr (EffectiveType::value) {
87  dumpName_ = "Effective" + dumpName_;
88  }
89  }
90  void setConsumes(edm::ESConsumesCollector& cc) { cc.setConsumes(token_, edm::ESInputTag{"", LABEL}); }
92  const RecordType& record,
93  const std::vector<std::string>& dumpRequest,
94  std::ostream* dumpStream) {
95  const auto& item = record.get(token_);
96  serviceSetData(host, item, EffectiveType{});
97 
98  if (std::find(dumpRequest.begin(), dumpRequest.end(), dumpName_) != dumpRequest.end()) {
99  *dumpStream << "New HCAL " << dumpName_ << " set" << std::endl;
100  HcalDbASCIIIO::dumpObject(*dumpStream, item);
101  }
102  }
103 
104  private:
107  };
108 
109  template <typename ProductType, const char* LABEL, typename EffectiveType = std::false_type>
110  struct ServiceToken {
111  using Product = ProductType;
112  static constexpr const char* label = LABEL;
113  using Effective = EffectiveType;
114  };
115 
116  template <typename RecordType, typename... TokenHolders>
118  public:
120  std::apply([&cc](auto&&... item) { ((item.setConsumes(cc)), ...); }, tokens_);
121  }
123  const HcalDbRecord& record,
124  const std::vector<std::string>& dumpRequest,
125  std::ostream* dumpStream) {
126  host.ifRecordChanges<RecordType>(record, [this, &host, &dumpRequest, &dumpStream](auto const& rec) {
127  std::apply([&host, &rec, &dumpRequest, &dumpStream](
128  auto&&... item) { ((item.setupHcalDbService(host, rec, dumpRequest, dumpStream)), ...); },
129  tokens_);
130  });
131  }
132 
133  private:
134  std::tuple<ServiceTokenImpl<typename TokenHolders::Product,
135  RecordType,
137  typename TokenHolders::Effective>...>
139  };
140 
141  // Helper class and functions for the individual products
142  template <typename ProductT, typename RecordT>
144  public:
145  using Product = ProductT;
146  using Record = RecordT;
147 
148  TokenAndTopologyHolder() = default;
149 
151  cc.setConsumes(token_, tag).setConsumes(topoToken_);
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:122
HcalDbProducer::ServiceTokenImpl
Definition: HcalDbProducer.cc:81
edm::ESConsumesCollector
Definition: ESConsumesCollector.h:58
ESHandle.h
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:73
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:77
HcalMCParamsRcd
Definition: HcalMCParamsRcd.h:6
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:138
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:138
HcalDbProducer::TokensForServiceHolder::setConsumes
void setConsumes(edm::ESConsumesCollector &cc)
Definition: HcalDbProducer.cc:119
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:150
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
HcalLUTCorrsRcd
Definition: HcalLUTCorrsRcd.h:25
HcalDbProducer::TokenAndTopologyHolder::Product
ProductT Product
Definition: HcalDbProducer.cc:145
query.host
host
Definition: query.py:115
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:105
HcalDbProducer::ServiceTokenImpl::setupHcalDbService
void setupHcalDbService(HostType &host, const RecordType &record, const std::vector< std::string > &dumpRequest, std::ostream *dumpStream)
Definition: HcalDbProducer.cc:91
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:111
edm::es::Label
Definition: es_Label.h:54
HcalDbProducer::TokensForServiceHolder
Definition: HcalDbProducer.cc:117
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:110
HcalDbProducer::produce
std::shared_ptr< HcalDbService > produce(const HcalDbRecord &)
Definition: HcalDbProducer.cc:287
edm::ParameterSet
Definition: ParameterSet.h:36
HcalPFCorrsRcd
Definition: HcalPFCorrsRcd.h:25
HcalDbProducer::TokenAndTopologyHolder::TokenAndTopologyHolder
TokenAndTopologyHolder()=default
HcalDbProducer::ServiceTokenImpl::setConsumes
void setConsumes(edm::ESConsumesCollector &cc)
Definition: HcalDbProducer.cc:90
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:83
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
type
type
Definition: HCALResponse.h:21
HcalDbProducer::ServiceTokenImpl::dumpName_
std::string dumpName_
Definition: HcalDbProducer.cc:106
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:69
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:143
HcalDbProducer
Definition: HcalDbProducer.cc:39
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:101
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:113
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:112
HcalDbProducer::kEmpty
constexpr static const char kEmpty[]
Definition: HcalDbProducer.cc:206