CMS 3D CMS Logo

ESDBCopy.cc
Go to the documentation of this file.
3 
5 
7 
9 #include <vector>
10 
12  : m_timetype(iConfig.getParameter<std::string>("timetype")),
13  m_cacheIDs(),
14  m_records(),
15  esPedestalsToken_(esConsumes()),
16  esADCToGeVConstantToken_(esConsumes()),
17  esChannelStatusToken_(esConsumes()),
18  esIntercalibConstantsToken_(esConsumes()),
19  esWeightStripGroupsToken_(esConsumes()),
20  esTBWeightsToken_(esConsumes()) {
21  std::string container;
23  typedef std::vector<edm::ParameterSet> Parameters;
24  Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
25  for (const auto& iparam : toCopy) {
26  container = iparam.getParameter<std::string>("container");
27  record = iparam.getParameter<std::string>("record");
28  m_cacheIDs.emplace(container, 0);
29  m_records.emplace(container, record);
30  }
31 }
32 
34 
35 void ESDBCopy::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup) {
36  for (const auto& irec : m_records) {
37  if (shouldCopy(evtSetup, irec.first)) {
38  copyToDB(evtSetup, irec.first);
39  }
40  }
41 }
42 
43 bool ESDBCopy::shouldCopy(const edm::EventSetup& evtSetup, const std::string& container) {
44  unsigned long long cacheID = 0;
45  if (container == "ESPedestals") {
46  cacheID = evtSetup.get<ESPedestalsRcd>().cacheIdentifier();
47  } else if (container == "ESADCToGeVConstant") {
48  cacheID = evtSetup.get<ESADCToGeVConstantRcd>().cacheIdentifier();
49  } else if (container == "ESIntercalibConstants") {
50  cacheID = evtSetup.get<ESIntercalibConstantsRcd>().cacheIdentifier();
51  } else if (container == "ESWeightStripGroups") {
52  cacheID = evtSetup.get<ESWeightStripGroupsRcd>().cacheIdentifier();
53  } else if (container == "ESTBWeights") {
54  cacheID = evtSetup.get<ESTBWeightsRcd>().cacheIdentifier();
55  } else if (container == "ESChannelStatus") {
56  cacheID = evtSetup.get<ESChannelStatusRcd>().cacheIdentifier();
57  } else {
58  throw cms::Exception("Unknown container");
59  }
60 
61  if (m_cacheIDs[container] == cacheID) {
62  return false;
63  } else {
64  m_cacheIDs[container] = cacheID;
65  return true;
66  }
67 }
68 
69 void ESDBCopy::copyToDB(const edm::EventSetup& evtSetup, const std::string& container) {
71  if (!dbOutput.isAvailable()) {
72  throw cms::Exception("PoolDBOutputService is not available");
73  }
74 
75  std::string recordName = m_records[container];
76 
77  if (container == "ESPedestals") {
78  const auto& obj = evtSetup.getData(esPedestalsToken_);
79  edm::LogInfo("ESDBCopy") << "ped pointer is: " << &obj;
80  dbOutput->createOneIOV<const ESPedestals>(obj, dbOutput->beginOfTime(), recordName);
81 
82  } else if (container == "ESADCToGeVConstant") {
83  const auto& obj = evtSetup.getData(esADCToGeVConstantToken_);
84  edm::LogInfo("ESDBCopy") << "adc pointer is: " << &obj;
85  dbOutput->createOneIOV<const ESADCToGeVConstant>(obj, dbOutput->beginOfTime(), recordName);
86 
87  } else if (container == "ESChannelStatus") {
88  const auto& obj = evtSetup.getData(esChannelStatusToken_);
89  edm::LogInfo("ESDBCopy") << "channel status pointer is: " << &obj;
90  dbOutput->createOneIOV<const ESChannelStatus>(obj, dbOutput->beginOfTime(), recordName);
91 
92  } else if (container == "ESIntercalibConstants") {
93  const auto& obj = evtSetup.getData(esIntercalibConstantsToken_);
94  edm::LogInfo("ESDBCopy") << "inter pointer is: " << &obj;
95  dbOutput->createOneIOV<const ESIntercalibConstants>(obj, dbOutput->beginOfTime(), recordName);
96 
97  } else if (container == "ESWeightStripGroups") {
98  const auto& obj = evtSetup.getData(esWeightStripGroupsToken_);
99  edm::LogInfo("ESDBCopy") << "weight pointer is: " << &obj;
100  dbOutput->createOneIOV<const ESWeightStripGroups>(obj, dbOutput->beginOfTime(), recordName);
101 
102  } else if (container == "ESTBWeights") {
103  const auto& obj = evtSetup.getData(esTBWeightsToken_);
104  edm::LogInfo("ESDBCopy") << "tbweight pointer is: " << &obj;
105  dbOutput->createOneIOV<const ESTBWeights>(obj, dbOutput->beginOfTime(), recordName);
106 
107  } else {
108  throw cms::Exception("Unknown container");
109  }
110 
111  edm::LogInfo("ESDBCopy") << "ESDBCopy wrote " << recordName;
112 }
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< std::string, unsigned long long > m_cacheIDs
Definition: ESDBCopy.h:43
~ESDBCopy() override
Definition: ESDBCopy.cc:33
const edm::ESGetToken< ESPedestals, ESPedestalsRcd > esPedestalsToken_
Definition: ESDBCopy.h:46
const edm::ESGetToken< ESWeightStripGroups, ESWeightStripGroupsRcd > esWeightStripGroupsToken_
Definition: ESDBCopy.h:50
const edm::ESGetToken< ESIntercalibConstants, ESIntercalibConstantsRcd > esIntercalibConstantsToken_
Definition: ESDBCopy.h:49
void createOneIOV(const T &payload, cond::Time_t firstSinceTime, const std::string &recordName)
bool shouldCopy(const edm::EventSetup &evtSetup, const std::string &container)
Definition: ESDBCopy.cc:43
void copyToDB(const edm::EventSetup &evtSetup, const std::string &container)
Definition: ESDBCopy.cc:69
const edm::ESGetToken< ESChannelStatus, ESChannelStatusRcd > esChannelStatusToken_
Definition: ESDBCopy.h:48
vector< ParameterSet > Parameters
T get() const
Definition: EventSetup.h:82
bool getData(T &iHolder) const
Definition: EventSetup.h:122
Log< level::Info, false > LogInfo
std::map< std::string, std::string > m_records
Definition: ESDBCopy.h:44
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: ESDBCopy.cc:35
const edm::ESGetToken< ESADCToGeVConstant, ESADCToGeVConstantRcd > esADCToGeVConstantToken_
Definition: ESDBCopy.h:47
const edm::ESGetToken< ESTBWeights, ESTBWeightsRcd > esTBWeightsToken_
Definition: ESDBCopy.h:51
ESDBCopy(const edm::ParameterSet &iConfig)
Definition: ESDBCopy.cc:11
bool isAvailable() const
Definition: Service.h:40