CMS 3D CMS Logo

EcalTPGPedestalsHandler.cc
Go to the documentation of this file.
9 
11 
12 #include <iostream>
13 #include <fstream>
14 
15 #include <ctime>
16 #include <unistd.h>
17 
18 #include <string>
19 #include <cstdio>
20 #include <typeinfo>
21 #include <sstream>
22 
24  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGPedestalsHandler")) {
25  edm::LogInfo("EcalTPGPedestalsHandler") << "EcalTPGPedestals Source handler constructor";
26  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
27  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
28  m_sid = ps.getParameter<std::string>("OnlineDBSID");
29  m_user = ps.getParameter<std::string>("OnlineDBUser");
30  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
31  m_locationsource = ps.getParameter<std::string>("LocationSource");
32  m_location = ps.getParameter<std::string>("Location");
33  m_gentag = ps.getParameter<std::string>("GenTag");
34  m_runtype = ps.getParameter<std::string>("RunType");
35 
36  edm::LogInfo("EcalTPGPedestalsHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
37 }
38 
40 
42  edm::LogInfo("EcalTPGPedestalsHandler") << "Started getNewObjects";
43 
44  //check whats already inside of database
45  if (tagInfo().size) {
46  //check whats already inside of database
47  std::cout << "got offlineInfo = " << std::endl;
48  std::cout << "tag name = " << tagInfo().name << std::endl;
49  std::cout << "size = " << tagInfo().size << std::endl;
50  } else {
51  std::cout << " First object for this tag " << std::endl;
52  }
53 
54  unsigned int max_since = 0;
55  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
56  edm::LogInfo("EcalTPGPedestalsHandler") << "max_since = " << max_since;
57  edm::LogInfo("EcalTPGPedestalsHandler") << "Retrieved last payload ";
58 
59  // here we retrieve all the runs after the last from online DB
60  edm::LogInfo("EcalTPGPedestalsHandler") << "Retrieving run list from ONLINE DB ... " << std::endl;
61 
62  edm::LogInfo("EcalTPGPedestalsHandler") << "Making connection..." << std::flush;
63  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
64  edm::LogInfo("EcalTPGPedestalsHandler") << "Done." << std::endl;
65 
66  if (!econn) {
67  std::cout << " Connection parameters " << m_sid << "/" << m_user << std::endl;
68  throw cms::Exception("OMDS not available");
69  }
70 
72  my_locdef.setLocation(m_location);
73 
75  my_rundef.setRunType(m_runtype);
76 
77  RunTag my_runtag;
78  my_runtag.setLocationDef(my_locdef);
79  my_runtag.setRunTypeDef(my_rundef);
80  my_runtag.setGeneralTag(m_gentag);
81 
82  readFromFile("last_tpg_ped_settings.txt");
83 
84  unsigned int min_run = m_i_run_number + 1;
85 
86  if (m_firstRun < m_i_run_number) {
87  min_run = m_i_run_number + 1;
88  } else {
89  min_run = m_firstRun;
90  }
91  if (min_run < max_since) {
92  min_run = max_since + 1; // we have to add 1 to the last transferred one
93  }
94 
95  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
96  << std::endl;
97 
98  unsigned int max_run = m_lastRun;
99  edm::LogInfo("EcalTPGPedestalsHandler") << "min_run= " << min_run << " max_run = " << max_run;
100  RunList my_list;
101  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
102  // my_list=econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
103 
104  std::vector<RunIOV> run_vec = my_list.getRuns();
105  size_t num_runs = run_vec.size();
106 
107  std::cout << "number of runs is : " << num_runs << std::endl;
108 
109  unsigned int irun = 0;
110 
111  if (num_runs > 0) {
112  for (size_t kr = 0; kr < run_vec.size(); kr++) {
113  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
114 
115  std::cout << " **************** " << std::endl;
116  std::cout << " **************** " << std::endl;
117  std::cout << " run= " << irun << std::endl;
118 
119  // retrieve the data :
120  std::map<EcalLogicID, RunTPGConfigDat> dataset;
121  econn->fetchDataSet(&dataset, &run_vec[kr]);
122 
123  std::string the_config_tag = "";
124  int the_config_version = 0;
125 
126  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
127 
128  int nr = 0;
129  for (it = dataset.begin(); it != dataset.end(); it++) {
130  ++nr;
131  //EcalLogicID ecalid = it->first;
132 
133  RunTPGConfigDat dat = it->second;
134  the_config_tag = dat.getConfigTag();
135  the_config_version = dat.getVersion();
136  }
137 
138  // it is all the same for all SM... get the last one
139 
140  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
141 
142  // here we should check if it is the same as previous run.
143 
144  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
145  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
146  << std::endl;
147 
148  FEConfigMainInfo fe_main_info;
149  fe_main_info.setConfigTag(the_config_tag);
150  fe_main_info.setVersion(the_config_version);
151 
152  try {
153  std::cout << " before fetch config set" << std::endl;
154  econn->fetchConfigSet(&fe_main_info);
155  std::cout << " after fetch config set" << std::endl;
156 
157  // now get TPGPedestals
158  int pedId = fe_main_info.getPedId();
159 
160  if (pedId != m_i_ped) {
161  FEConfigPedInfo fe_ped_info;
162  fe_ped_info.setId(pedId);
163  econn->fetchConfigSet(&fe_ped_info);
164  std::map<EcalLogicID, FEConfigPedDat> dataset_TpgPed;
165  econn->fetchDataSet(&dataset_TpgPed, &fe_ped_info);
166 
167  // NB new
169  typedef std::map<EcalLogicID, FEConfigPedDat>::const_iterator CIfeped;
170  EcalLogicID ecid_xt;
171  FEConfigPedDat rd_ped;
172  int icells = 0;
173  for (CIfeped p = dataset_TpgPed.begin(); p != dataset_TpgPed.end(); p++) {
174  ecid_xt = p->first;
175  rd_ped = p->second;
176 
177  std::string ecid_name = ecid_xt.getName();
178 
179  // EB data
180  if (ecid_name == "EB_crystal_number") {
181  if (icells < 10)
182  std::cout << " copy the EB data "
183  << " icells = " << icells << std::endl;
184  int sm_num = ecid_xt.getID1();
185  int xt_num = ecid_xt.getID2();
186 
187  EBDetId ebdetid(sm_num, xt_num, EBDetId::SMCRYSTALMODE);
189  item.mean_x1 = (unsigned int)rd_ped.getPedMeanG1();
190  item.mean_x6 = (unsigned int)rd_ped.getPedMeanG6();
191  item.mean_x12 = (unsigned int)rd_ped.getPedMeanG12();
192 
193  peds->insert(std::make_pair(ebdetid.rawId(), item));
194  ++icells;
195  } else if (ecid_name == "EE_crystal_number") {
196  // EE data
197  int z = ecid_xt.getID1();
198  int x = ecid_xt.getID2();
199  int y = ecid_xt.getID3();
200  EEDetId eedetid(x, y, z, EEDetId::XYMODE);
202  item.mean_x1 = (unsigned int)rd_ped.getPedMeanG1();
203  item.mean_x6 = (unsigned int)rd_ped.getPedMeanG6();
204  item.mean_x12 = (unsigned int)rd_ped.getPedMeanG12();
205 
206  peds->insert(std::make_pair(eedetid.rawId(), item));
207  ++icells;
208  }
209  }
210 
211  Time_t snc = (Time_t)irun;
212  m_to_transfer.push_back(std::make_pair((EcalTPGPedestals*)peds, snc));
213 
214  m_i_run_number = irun;
215  m_i_tag = the_config_tag;
216  m_i_version = the_config_version;
217  m_i_ped = pedId;
218 
219  writeFile("last_tpg_ped_settings.txt");
220 
221  } else {
222  m_i_run_number = irun;
223  m_i_tag = the_config_tag;
224  m_i_version = the_config_version;
225 
226  writeFile("last_tpg_ped_settings.txt");
227 
228  std::cout << " even if the tag/version is not the same, the pedestals id is the same -> no transfer needed "
229  << std::endl;
230  }
231 
232  }
233 
234  catch (std::exception& e) {
235  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
236  << std::endl;
237  std::cout << e.what() << std::endl;
238  m_i_run_number = irun;
239  }
240  std::cout << " **************** " << std::endl;
241 
242  } else if (nr == 0) {
243  m_i_run_number = irun;
244  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
245  std::cout << " **************** " << std::endl;
246  } else {
247  m_i_run_number = irun;
248  m_i_tag = the_config_tag;
249  m_i_version = the_config_version;
250  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
251  std::cout << " **************** " << std::endl;
252  writeFile("last_tpg_ped_settings.txt");
253  }
254  }
255  }
256 
257  delete econn;
258 
259  edm::LogInfo("EcalTPGPedestalsHandler") << "Ecal - > end of getNewObjects -----------";
260 }
261 
263  //-------------------------------------------------------------
264 
265  m_i_tag = "";
266  m_i_version = 0;
267  m_i_run_number = 0;
268  m_i_ped = 0;
269 
270  FILE* inpFile; // input file
271  inpFile = fopen(inputFile, "r");
272  if (!inpFile) {
273  edm::LogError("EcalTPGPedestalsHandler") << "*** Can not open file: " << inputFile;
274  return;
275  }
276 
277  char line[256];
278 
279  std::ostringstream str;
280 
281  fgets(line, 255, inpFile);
282  m_i_tag = to_string(line);
283  str << "gen tag " << m_i_tag << std::endl; // should I use this?
284 
285  fgets(line, 255, inpFile);
286  m_i_version = atoi(line);
287  str << "version= " << m_i_version << std::endl;
288 
289  fgets(line, 255, inpFile);
290  m_i_run_number = atoi(line);
291  str << "run_number= " << m_i_run_number << std::endl;
292 
293  fgets(line, 255, inpFile);
294  m_i_ped = atoi(line);
295  str << "ped_config= " << m_i_ped << std::endl;
296 
297  fclose(inpFile); // close inp. file
298 }
299 
301  //-------------------------------------------------------------
302 
303  std::ofstream myfile;
304  myfile.open(inputFile);
305  myfile << m_i_tag << std::endl;
306  myfile << m_i_version << std::endl;
307  myfile << m_i_run_number << std::endl;
308  myfile << m_i_ped << std::endl;
309 
310  myfile.close();
311 }
popcon::EcalTPGPedestalsHandler::writeFile
void writeFile(const char *inputFile)
Definition: EcalTPGPedestalsHandler.cc:300
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
l1tpf_impl::readFromFile
void readFromFile(CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:22
DDAxes::y
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
MessageLogger.h
RunList.h
popcon::EcalTPGPedestalsHandler::m_pass
std::string m_pass
Definition: EcalTPGPedestalsHandler.h:73
RunList
Definition: RunList.h:16
EBDetId
Definition: EBDetId.h:17
RunTag
Definition: RunTag.h:13
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalTPGPedestals
EcalTPGPedestalsMap EcalTPGPedestals
Definition: EcalTPGPedestals.h:19
EcalLogicID::getName
std::string getName() const
Definition: EcalLogicID.cc:26
FEConfigMainInfo
Definition: FEConfigMainInfo.h:14
FEConfigPedDat::getPedMeanG12
float getPedMeanG12() const
Definition: FEConfigPedDat.h:30
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalTPGPedestals >::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
LocationDef
Definition: LocationDef.h:12
DeadROCCounter.getRunNumber
def getRunNumber(filename)
Definition: DeadROCCounter.py:7
RunTPGConfigDat.h
DDAxes::x
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
EcalLogicID::getID1
int getID1() const
Definition: EcalLogicID.cc:30
FEConfigMainInfo::setVersion
void setVersion(int id)
Definition: FEConfigMainInfo.h:66
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
popcon::EcalTPGPedestalsHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalTPGPedestalsHandler.h:66
popcon::EcalTPGPedestalsHandler::EcalTPGPedestalsHandler
EcalTPGPedestalsHandler(edm::ParameterSet const &)
Definition: EcalTPGPedestalsHandler.cc:23
EcalLogicID::getID2
int getID2() const
Definition: EcalLogicID.cc:32
FEConfigMainInfo.h
RunTag::setGeneralTag
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
test_db_connect.my_rundef
my_rundef
Definition: test_db_connect.py:13
FEConfigPedDat::getPedMeanG1
float getPedMeanG1() const
Definition: FEConfigPedDat.h:24
DDAxes::z
str
#define str(s)
Definition: TestProcessor.cc:51
EcalLogicID
Definition: EcalLogicID.h:7
RunTPGConfigDat
Definition: RunTPGConfigDat.h:11
popcon::EcalTPGPedestalsHandler::m_locationsource
std::string m_locationsource
Definition: EcalTPGPedestalsHandler.h:74
FEConfigPedDat::getPedMeanG6
float getPedMeanG6() const
Definition: FEConfigPedDat.h:27
popcon::EcalTPGPedestalsHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalTPGPedestalsHandler.h:67
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RunTypeDef
Definition: RunTypeDef.h:12
test_db_connect.my_locdef
my_locdef
Definition: test_db_connect.py:11
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
popcon::EcalTPGPedestalsHandler::m_runtype
std::string m_runtype
Definition: EcalTPGPedestalsHandler.h:77
edm::ParameterSet
Definition: ParameterSet.h:47
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
EcalCondObjectContainer::Item
T Item
Definition: EcalCondObjectContainer.h:15
popcon::EcalTPGPedestalsHandler::readFromFile
void readFromFile(const char *inputFile)
Definition: EcalTPGPedestalsHandler.cc:262
createfilelist.int
int
Definition: createfilelist.py:10
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
popcon::EcalTPGPedestalsHandler::getNewObjects
void getNewObjects() override
Definition: EcalTPGPedestalsHandler.cc:41
FEConfigPedDat
Definition: FEConfigPedDat.h:11
EcalTPGPedestals.h
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
popcon::EcalTPGPedestalsHandler::m_sid
std::string m_sid
Definition: EcalTPGPedestalsHandler.h:71
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
FEConfigLUTInfo.h
EcalLogicID.h
EcalTPGPedestalsHandler.h
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.dataset
dataset
Definition: writedatasetfile.py:19
RunTPGConfigDat::getVersion
int getVersion() const
Definition: RunTPGConfigDat.h:22
RunTag::setLocationDef
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
EcalCondObjectContainer::insert
void insert(std::pair< uint32_t, Item > const &a)
Definition: EcalCondObjectContainer.h:38
FEConfigPedInfo::setId
void setId(int id)
Definition: FEConfigPedInfo.h:24
EEDetId::XYMODE
static const int XYMODE
Definition: EEDetId.h:335
Exception
Definition: hltDiff.cc:246
RunList::getRuns
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
RunTPGConfigDat::getConfigTag
std::string getConfigTag() const
Definition: RunTPGConfigDat.h:20
ParameterSetfwd.h
EcalLogicID::getID3
int getID3() const
Definition: EcalLogicID.cc:34
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
FEConfigMainInfo::getPedId
int getPedId() const
Definition: FEConfigMainInfo.h:34
dataset
Definition: dataset.py:1
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
popcon::EcalTPGPedestalsHandler::m_location
std::string m_location
Definition: EcalTPGPedestalsHandler.h:69
IODConfig::setConfigTag
void setConfigTag(std::string x)
Definition: IODConfig.h:29
FEConfigPedInfo
Definition: FEConfigPedInfo.h:11
mps_splice.line
line
Definition: mps_splice.py:76
popcon::EcalTPGPedestalsHandler::m_user
std::string m_user
Definition: EcalTPGPedestalsHandler.h:72
EBDetId::SMCRYSTALMODE
static const int SMCRYSTALMODE
Definition: EBDetId.h:159
popcon::EcalTPGPedestalsHandler::m_gentag
std::string m_gentag
Definition: EcalTPGPedestalsHandler.h:70
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
popcon::EcalTPGPedestalsHandler::~EcalTPGPedestalsHandler
~EcalTPGPedestalsHandler() override
Definition: EcalTPGPedestalsHandler.cc:39