CMS 3D CMS Logo

ESDBCopy.cc
Go to the documentation of this file.
3 
5 
6 
9 
10 
24 
25 
26 
27 #include <vector>
28 
30  m_timetype(iConfig.getParameter<std::string>("timetype")),
31  m_cacheIDs(),
32  m_records()
33 {
34 
35  std::string container;
38  typedef std::vector< edm::ParameterSet > Parameters;
39  Parameters toCopy = iConfig.getParameter<Parameters>("toCopy");
40  for(Parameters::iterator i = toCopy.begin(); i != toCopy.end(); ++i) {
41  container = i->getParameter<std::string>("container");
42  record = i->getParameter<std::string>("record");
43  m_cacheIDs.insert( std::make_pair(container, 0) );
44  m_records.insert( std::make_pair(container, record) );
45  }
46 
47 }
48 
49 
51 {
52 
53 }
54 
55 void ESDBCopy::analyze( const edm::Event& evt, const edm::EventSetup& evtSetup)
56 {
57 
58  std::string container;
60  typedef std::map<std::string, std::string>::const_iterator recordIter;
61  for (recordIter i = m_records.begin(); i != m_records.end(); ++i) {
62  container = (*i).first;
63  record = (*i).second;
64  if ( shouldCopy(evtSetup, container) ) {
65  copyToDB(evtSetup, container);
66  }
67  }
68 
69 }
70 
71 
72 
73 bool ESDBCopy::shouldCopy(const edm::EventSetup& evtSetup, std::string container)
74 {
75 
76  unsigned long long cacheID = 0;
77  if (container == "ESPedestals") {
78  cacheID = evtSetup.get<ESPedestalsRcd>().cacheIdentifier();
79  } else if (container == "ESADCToGeVConstant") {
80  cacheID = evtSetup.get<ESADCToGeVConstantRcd>().cacheIdentifier();
81  } else if (container == "ESIntercalibConstants") {
82  cacheID = evtSetup.get<ESIntercalibConstantsRcd>().cacheIdentifier();
83  } else if (container == "ESWeightStripGroups") {
84  cacheID = evtSetup.get<ESWeightStripGroupsRcd>().cacheIdentifier();
85  } else if (container == "ESTBWeights") {
86  cacheID = evtSetup.get<ESTBWeightsRcd>().cacheIdentifier();
87  } else if (container == "ESChannelStatus") {
88  cacheID = evtSetup.get<ESChannelStatusRcd>().cacheIdentifier();
89  }
90 
91  else {
92  throw cms::Exception("Unknown container");
93  }
94 
95  if (m_cacheIDs[container] == cacheID) {
96  return false;
97  } else {
98  m_cacheIDs[container] = cacheID;
99  return true;
100  }
101 
102 }
103 
104 
105 
106 void ESDBCopy::copyToDB(const edm::EventSetup& evtSetup, std::string container)
107 {
109  if ( !dbOutput.isAvailable() ) {
110  throw cms::Exception("PoolDBOutputService is not available");
111  }
112 
113  std::string recordName = m_records[container];
114 
115  if (container == "ESPedestals") {
117  evtSetup.get<ESPedestalsRcd>().get(handle);
118  const ESPedestals* obj = handle.product();
119  std::cout << "ped pointer is: "<< obj<< std::endl;
120  dbOutput->createNewIOV<const ESPedestals>( new ESPedestals(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
121 
122  } else if (container == "ESADCToGeVConstant") {
124  evtSetup.get<ESADCToGeVConstantRcd>().get(handle);
125  const ESADCToGeVConstant* obj = handle.product();
126  std::cout << "adc pointer is: "<< obj<< std::endl;
127 
128  dbOutput->createNewIOV<const ESADCToGeVConstant>( new ESADCToGeVConstant(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
129 
130 
131  } else if (container == "ESChannelStatus") {
133  evtSetup.get<ESChannelStatusRcd>().get(handle);
134  const ESChannelStatus* obj = handle.product();
135  std::cout << "channel status pointer is: "<< obj<< std::endl;
136 
137  dbOutput->createNewIOV<const ESChannelStatus>( new ESChannelStatus(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
138 
139 
140  }
141 else if (container == "ESIntercalibConstants") {
143  evtSetup.get<ESIntercalibConstantsRcd>().get(handle);
144  const ESIntercalibConstants* obj = handle.product();
145  std::cout << "inter pointer is: "<< obj<< std::endl;
146  dbOutput->createNewIOV<const ESIntercalibConstants>( new ESIntercalibConstants(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
147 
148 
149  } else if (container == "ESWeightStripGroups") {
151  evtSetup.get<ESWeightStripGroupsRcd>().get(handle);
152  const ESWeightStripGroups* obj = handle.product();
153  std::cout << "weight pointer is: "<< obj<< std::endl;
154  dbOutput->createNewIOV<const ESWeightStripGroups>( new ESWeightStripGroups(*obj),dbOutput->beginOfTime(), dbOutput->endOfTime(),recordName);
155 
156  } else if (container == "ESTBWeights") {
158  evtSetup.get<ESTBWeightsRcd>().get(handle);
159  const ESTBWeights* obj = handle.product();
160  std::cout << "tbweight pointer is: "<< obj<< std::endl;
161  dbOutput->createNewIOV<const ESTBWeights>( new ESTBWeights(*obj), dbOutput->beginOfTime(),dbOutput->endOfTime(),recordName);
162 
163 
164  } else {
165  throw cms::Exception("Unknown container");
166  }
167 
168  std::cout<< "ESDBCopy wrote " << recordName << std::endl;
169 }
T getParameter(std::string const &) const
std::map< std::string, unsigned long long > m_cacheIDs
Definition: ESDBCopy.h:30
~ESDBCopy() override
Definition: ESDBCopy.cc:50
void copyToDB(const edm::EventSetup &evtSetup, std::string container)
Definition: ESDBCopy.cc:106
JetCorrectorParameters::Record record
Definition: classes.h:7
bool shouldCopy(const edm::EventSetup &evtSetup, std::string container)
Definition: ESDBCopy.cc:73
ESPedestalsMap ESPedestals
Definition: ESPedestals.h:32
ESChannelStatusMap ESChannelStatus
vector< ParameterSet > Parameters
bool isAvailable() const
Definition: Service.h:46
void createNewIOV(T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t firstTillTime, const std::string &recordName, bool withlogging=false)
std::map< std::string, std::string > m_records
Definition: ESDBCopy.h:31
ESIntercalibConstantMap ESIntercalibConstants
void analyze(const edm::Event &evt, const edm::EventSetup &evtSetup) override
Definition: ESDBCopy.cc:55
const T & get() const
Definition: EventSetup.h:59
ESDBCopy(const edm::ParameterSet &iConfig)
Definition: ESDBCopy.cc:29
T const * product() const
Definition: ESHandle.h:86
ESCondObjectContainer< ESStripGroupId > ESWeightStripGroups