CMS 3D CMS Logo

EcalTPGOddWeightIdMapHandler.cc
Go to the documentation of this file.
2 
10 
11 #include <iostream>
12 #include <fstream>
13 
14 #include <ctime>
15 #include <unistd.h>
16 
17 #include <string>
18 #include <cstdio>
19 #include <typeinfo>
20 #include <sstream>
21 
23  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGOddWeightIdMapHandler")) {
24  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "EcalTPGOddWeightIdMap Source handler constructor";
25  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
26  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
27  m_sid = ps.getParameter<std::string>("OnlineDBSID");
28  m_user = ps.getParameter<std::string>("OnlineDBUser");
29  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
30  m_locationsource = ps.getParameter<std::string>("LocationSource");
31  m_location = ps.getParameter<std::string>("Location");
32  m_gentag = ps.getParameter<std::string>("GenTag");
33  m_runtype = ps.getParameter<std::string>("RunType");
34  m_file_type = ps.getParameter<std::string>("fileType"); // xml/txt
35  m_file_name = ps.getParameter<std::string>("fileName");
36 
37  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
38 }
39 
41 
43  if (m_file_type == "txt") {
44  readtxtFile();
45  } else if (m_file_type == "xml") {
46  readxmlFile();
47  } else {
48  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "Started GetNewObjects!!!";
49 
50  //check whats already inside of database
51  if (tagInfo().size) {
52  //check whats already inside of database
53  std::cout << "got offlineInfo = " << std::endl;
54  std::cout << "tag name = " << tagInfo().name << std::endl;
55  std::cout << "size = " << tagInfo().size << std::endl;
56  } else {
57  std::cout << " First object for this tag " << std::endl;
58  }
59 
60  unsigned int max_since = 0;
61  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
62  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "max_since : " << max_since;
63  //Ref weightIdMap_db = lastPayload();
64 
65  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "retrieved last payload ";
66 
67  // here we retrieve all the runs after the last from online DB
68  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "Retrieving run list from ONLINE DB ... ";
69 
70  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "Making connection...";
71  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
72  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "Done.";
73 
74  if (!econn) {
75  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
76  // cerr << e.what() << std::endl;
77  throw cms::Exception("OMDS not available");
78  }
79 
81  my_locdef.setLocation(m_location);
82 
84  my_rundef.setRunType(m_runtype);
85 
86  RunTag my_runtag;
87  my_runtag.setLocationDef(my_locdef);
88  my_runtag.setRunTypeDef(my_rundef);
89  my_runtag.setGeneralTag(m_gentag);
90 
91  readFromFile("last_tpg_OddweightIdMap_settings.txt");
92 
93  unsigned int min_run = m_i_run_number + 1;
94 
95  if (m_firstRun < m_i_run_number) {
96  min_run = m_i_run_number + 1;
97  } else {
98  min_run = m_firstRun;
99  }
100 
101  if (min_run < max_since) {
102  min_run = max_since + 1; // we have to add 1 to the last transferred one
103  }
104 
105  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
106  << std::endl;
107 
108  unsigned int max_run = m_lastRun;
109  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "min_run= " << min_run << "max_run= " << max_run;
110 
111  RunList my_list;
112  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
113  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
114 
115  std::vector<RunIOV> run_vec = my_list.getRuns();
116  size_t num_runs = run_vec.size();
117  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "number of Mon runs is : " << num_runs;
118 
119  unsigned int irun;
120  if (num_runs > 0) {
121  for (size_t kr = 0; kr < run_vec.size(); kr++) {
122  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
123 
124  std::cout << " **************** " << std::endl;
125  std::cout << " **************** " << std::endl;
126  std::cout << " run= " << irun << std::endl;
127 
128  // retrieve the data :
129  std::map<EcalLogicID, RunTPGConfigDat> dataset;
130  econn->fetchDataSet(&dataset, &run_vec[kr]);
131 
132  std::string the_config_tag = "";
133  int the_config_version = 0;
134 
135  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
136 
137  int nr = 0;
138  for (it = dataset.begin(); it != dataset.end(); it++) {
139  ++nr;
140  //EcalLogicID ecalid = it->first;
141  RunTPGConfigDat dat = it->second;
142  the_config_tag = dat.getConfigTag();
143  the_config_version = dat.getVersion();
144  }
145 
146  // it is all the same for all SM... get the last one
147 
148  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
149 
150  // here we should check if it is the same as previous run.
151 
152  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
153  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
154  << std::endl;
155 
156  FEConfigMainInfo fe_main_info;
157  fe_main_info.setConfigTag(the_config_tag);
158  fe_main_info.setVersion(the_config_version);
159 
160  try {
161  std::cout << " before fetch config set" << std::endl;
162  econn->fetchConfigSet(&fe_main_info);
163  std::cout << " after fetch config set" << std::endl;
164 
165  // now get TPGOddWeightIdMap
166  int weightId = fe_main_info.getWei2Id();
167 
168  if (weightId != m_i_oddweightIdMap) {
169  FEConfigOddWeightInfo fe_odd_weight_info;
170  fe_odd_weight_info.setId(weightId);
171  econn->fetchConfigSet(&fe_odd_weight_info);
172  std::map<EcalLogicID, FEConfigOddWeightGroupDat> dataset_TpgWeight;
173  econn->fetchDataSet(&dataset_TpgWeight, &fe_odd_weight_info);
174  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "Got object!";
176  typedef std::map<EcalLogicID, FEConfigOddWeightGroupDat>::const_iterator CIfeweight;
177  EcalLogicID ecid_xt;
179 
180  int igroups = 0;
181  for (CIfeweight p = dataset_TpgWeight.begin(); p != dataset_TpgWeight.end(); p++) {
182  rd_w = p->second;
183  // EB and EE data
185  unsigned int weight0 = static_cast<unsigned int>(rd_w.getWeight4());
186  unsigned int weight1 = static_cast<unsigned int>(rd_w.getWeight3());
187  unsigned int weight2 = static_cast<unsigned int>(rd_w.getWeight2());
188  unsigned int weight3 = static_cast<unsigned int>(rd_w.getWeight1() - 0x80);
189  unsigned int weight4 = static_cast<unsigned int>(rd_w.getWeight0());
190 
191  w.setValues(weight0, weight1, weight2, weight3, weight4);
192  weightMap->setValue(rd_w.getWeightGroupId(), w);
193 
194  ++igroups;
195  }
196 
197  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "found " << igroups << "Weight groups";
198 
199  Time_t snc = (Time_t)irun;
200  m_to_transfer.push_back(std::make_pair((EcalTPGOddWeightIdMap*)weightMap, snc));
201 
202  m_i_run_number = irun;
203  m_i_tag = the_config_tag;
204  m_i_version = the_config_version;
205  m_i_oddweightIdMap = weightId;
206 
207  writeFile("last_tpg_OddweightIdMap_settings.txt");
208 
209  } else {
210  m_i_run_number = irun;
211  m_i_tag = the_config_tag;
212  m_i_version = the_config_version;
213 
214  writeFile("last_tpg_OddweightIdMap_settings.txt");
215 
216  std::cout
217  << " even if the tag/version is not the same, the weightIdMap id is the same -> no transfer needed "
218  << std::endl;
219  }
220 
221  } catch (std::exception& e) {
222  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag
223  << " version=" << the_config_version << std::endl;
224  std::cout << e.what() << std::endl;
225  m_i_run_number = irun;
226  }
227  std::cout << " **************** " << std::endl;
228 
229  } else if (nr == 0) {
230  m_i_run_number = irun;
231  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
232  std::cout << " **************** " << std::endl;
233  } else {
234  m_i_run_number = irun;
235  m_i_tag = the_config_tag;
236  m_i_version = the_config_version;
237  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
238  std::cout << " **************** " << std::endl;
239  writeFile("last_tpg_OddweightIdMap_settings.txt");
240  }
241  }
242  }
243 
244  delete econn;
245  } // usual way
246  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "Ecal - > end of getNewObjects -----------";
247 }
249  std::cout << " reading the input file " << m_file_name << std::endl;
250  std::ifstream fInput;
251  fInput.open(m_file_name);
252  if (!fInput.is_open()) {
253  std::cout << "ERROR : cannot open file " << m_file_name << std::endl;
254  exit(1);
255  }
256  unsigned int wloc[5];
259  int igroups = 0;
261  while (!fInput.eof()) {
262  getline(fInput, line);
263  if (!line.empty()) {
264  std::stringstream ss;
265  ss << line;
266  ss >> wloc[0] >> wloc[1] >> wloc[2] >> wloc[3] >> wloc[4];
267  // std::cout << wloc[0] << " " << wloc[1] << " " << wloc[2] << " " << wloc[3] << " " << wloc[4] << std::endl;
268  w.setValues(wloc[0], wloc[1], wloc[2], wloc[3], wloc[4]);
269  weightMap->setValue(igroups, w);
270  igroups++;
271  }
272  }
273  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "found " << igroups << " Weight groups";
274  try {
275  Time_t snc = (Time_t)m_firstRun;
276  m_to_transfer.push_back(std::make_pair((EcalTPGOddWeightIdMap*)weightMap, snc));
277  } catch (std::exception& e) {
278  std::cout << "EcalTPGOddWeightIdMapHandler::readtxtFile error : " << e.what() << std::endl;
279  }
280  std::cout << " **************** " << std::endl;
281 }
282 
284  std::cout << " reading the input file " << m_file_name << std::endl;
285  std::ifstream fxml;
286  fxml.open(m_file_name);
287  if (!fxml.is_open()) {
288  std::cout << "ERROR : cannot open file " << m_file_name << std::endl;
289  exit(1);
290  }
291  std::string dummyLine, bid;
292  unsigned int wloc[5];
295  int ngroups, igroups;
296  for (int i = 0; i < 5; i++)
297  std::getline(fxml, dummyLine); // skip first lines
298  // get the Weight group number
299  fxml >> bid;
300  std::string stt = bid.substr(7, 1);
301  std::istringstream sc(stt);
302  sc >> ngroups;
303  edm::LogInfo("EcalTPGOddWeightIdMapHandler") << "found " << ngroups << " Weight groups";
304  for (int i = 0; i < 2; i++)
305  std::getline(fxml, dummyLine); // <item_version>0</item_version>
306  // std::cout << dummyLine << std::endl;
307  for (int i = 0; i < ngroups; i++) {
308  std::getline(fxml, dummyLine); // <item
309  // std::cout << " group " << i << " first line " << dummyLine << std::endl;
310  fxml >> bid; // <first
311  std::size_t found = bid.find("</");
312  stt = bid.substr(7, found - 7);
313  std::istringstream sg1(stt);
314  sg1 >> igroups;
315  if (igroups != i) {
316  std::cout << " group " << i << ": " << bid << " igroups " << igroups << std::endl;
317  exit(-1);
318  }
319  for (int i = 0; i < 2; i++)
320  std::getline(fxml, dummyLine); // < second
321  for (int i = 0; i < 5; i++) {
322  fxml >> bid;
323  found = bid.find("</");
324  stt = bid.substr(5, found - 5);
325  std::istringstream w(stt);
326  w >> wloc[i];
327  }
328  w.setValues(wloc[0], wloc[1], wloc[2], wloc[3], wloc[4]);
329  weightMap->setValue(igroups, w);
330  for (int i = 0; i < 3; i++)
331  std::getline(fxml, dummyLine); // </item>
332  // std::cout << " group " << i << " last line " << dummyLine << std::endl;
333  }
334  try {
335  Time_t snc = (Time_t)m_firstRun;
336  m_to_transfer.push_back(std::make_pair((EcalTPGOddWeightIdMap*)weightMap, snc));
337  } catch (std::exception& e) {
338  std::cout << "EcalTPGOddWeightIdMapHandler::readxmlFile error : " << e.what() << std::endl;
339  }
340  std::cout << " **************** " << std::endl;
341 }
342 
344  //-------------------------------------------------------------
345 
346  m_i_tag = "";
347  m_i_version = 0;
348  m_i_run_number = 0;
349  m_i_oddweightIdMap = 0;
350 
351  FILE* inpFile; // input file
352  inpFile = fopen(inputFile, "r");
353  if (!inpFile) {
354  edm::LogError("EcalTPGOddWeightIdMapHandler") << "*** Can not open file: " << inputFile;
355  return;
356  }
357 
358  char line[256];
359 
360  std::ostringstream str;
361 
362  fgets(line, 255, inpFile);
363  m_i_tag = to_string(line);
364  str << "gen tag " << m_i_tag << std::endl; // should I use this?
365 
366  fgets(line, 255, inpFile);
367  m_i_version = atoi(line);
368  str << "version= " << m_i_version << std::endl;
369 
370  fgets(line, 255, inpFile);
371  m_i_run_number = atoi(line);
372  str << "run_number= " << m_i_run_number << std::endl;
373 
374  fgets(line, 255, inpFile);
375  m_i_oddweightIdMap = atoi(line);
376  str << "weightIdMap_config= " << m_i_oddweightIdMap << std::endl;
377 
378  fclose(inpFile); // close inp. file
379 }
380 
382  //-------------------------------------------------------------
383 
384  std::ofstream myfile;
385  myfile.open(inputFile);
386  myfile << m_i_tag << std::endl;
387  myfile << m_i_version << std::endl;
388  myfile << m_i_run_number << std::endl;
389  myfile << m_i_oddweightIdMap << std::endl;
390 
391  myfile.close();
392 }
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
l1tpf_impl::readFromFile
void readFromFile(CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:22
popcon::EcalTPGOddWeightIdMapHandler::~EcalTPGOddWeightIdMapHandler
~EcalTPGOddWeightIdMapHandler() override
Definition: EcalTPGOddWeightIdMapHandler.cc:40
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
mps_fire.i
i
Definition: mps_fire.py:428
FEConfigOddWeightGroupDat::getWeight1
float getWeight1() const
Definition: FEConfigOddWeightGroupDat.h:26
MessageLogger.h
popcon::EcalTPGOddWeightIdMapHandler::EcalTPGOddWeightIdMapHandler
EcalTPGOddWeightIdMapHandler(edm::ParameterSet const &)
Definition: EcalTPGOddWeightIdMapHandler.cc:22
RunList
Definition: RunList.h:16
popcon::EcalTPGOddWeightIdMapHandler::m_location
std::string m_location
Definition: EcalTPGOddWeightIdMapHandler.h:73
popcon::EcalTPGOddWeightIdMapHandler::writeFile
void writeFile(const char *inputFile)
Definition: EcalTPGOddWeightIdMapHandler.cc:381
popcon::EcalTPGOddWeightIdMapHandler::m_file_type
std::string m_file_type
Definition: EcalTPGOddWeightIdMapHandler.h:83
RunTag
Definition: RunTag.h:13
gather_cfg.cout
cout
Definition: gather_cfg.py:144
FEConfigMainInfo
Definition: FEConfigMainInfo.h:14
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalTPGOddWeightIdMap >::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
FEConfigOddWeightInfo
Definition: FEConfigOddWeightInfo.h:11
FEConfigOddWeightGroupDat::getWeight0
float getWeight0() const
Definition: FEConfigOddWeightGroupDat.h:24
RunTPGConfigDat.h
FEConfigOddWeightGroupDat::getWeightGroupId
int getWeightGroupId() const
Definition: FEConfigOddWeightGroupDat.h:21
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
FEConfigMainInfo::setVersion
void setVersion(int id)
Definition: FEConfigMainInfo.h:78
popcon::EcalTPGOddWeightIdMapHandler::readtxtFile
void readtxtFile()
Definition: EcalTPGOddWeightIdMapHandler.cc:248
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
EcalLaserHandler.h
EcalTPGOddWeightIdMap::setValue
void setValue(const uint32_t &id, const EcalTPGWeights &value)
Definition: EcalTPGOddWeightIdMap.cc:7
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
popcon::EcalTPGOddWeightIdMapHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalTPGOddWeightIdMapHandler.h:70
FEConfigOddWeightInfo::setId
void setId(int id)
Definition: FEConfigOddWeightInfo.h:24
FEConfigMainInfo.h
EcalTPGOddWeightIdMap
Definition: EcalTPGOddWeightIdMap.h:10
popcon::EcalTPGOddWeightIdMapHandler::m_runtype
std::string m_runtype
Definition: EcalTPGOddWeightIdMapHandler.h:81
RunTag::setGeneralTag
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
test_db_connect.my_rundef
my_rundef
Definition: test_db_connect.py:13
w
const double w
Definition: UKUtility.cc:23
str
#define str(s)
Definition: TestProcessor.cc:53
EcalLogicID
Definition: EcalLogicID.h:7
RunTPGConfigDat
Definition: RunTPGConfigDat.h:11
popcon::EcalTPGOddWeightIdMapHandler::m_gentag
std::string m_gentag
Definition: EcalTPGOddWeightIdMapHandler.h:74
EcalTPGOddWeightIdMapHandler.h
FEConfigOddWeightGroupDat
Definition: FEConfigOddWeightGroupDat.h:11
popcon::EcalTPGOddWeightIdMapHandler::m_file_name
std::string m_file_name
Definition: EcalTPGOddWeightIdMapHandler.h:84
popcon::EcalTPGOddWeightIdMapHandler::readFromFile
void readFromFile(const char *inputFile)
Definition: EcalTPGOddWeightIdMapHandler.cc:343
popcon::EcalTPGOddWeightIdMapHandler::m_sid
std::string m_sid
Definition: EcalTPGOddWeightIdMapHandler.h:75
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
edm::ParameterSet
Definition: ParameterSet.h:47
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
popcon::EcalTPGOddWeightIdMapHandler::m_locationsource
std::string m_locationsource
Definition: EcalTPGOddWeightIdMapHandler.h:78
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
popcon::EcalTPGOddWeightIdMapHandler::getNewObjects
void getNewObjects() override
Definition: EcalTPGOddWeightIdMapHandler.cc:42
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
popcon::EcalTPGOddWeightIdMapHandler::readxmlFile
void readxmlFile()
Definition: EcalTPGOddWeightIdMapHandler.cc:283
popcon::EcalTPGOddWeightIdMapHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalTPGOddWeightIdMapHandler.h:71
popcon::EcalTPGOddWeightIdMapHandler::m_user
std::string m_user
Definition: EcalTPGOddWeightIdMapHandler.h:76
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
popcon::EcalTPGOddWeightIdMapHandler::m_pass
std::string m_pass
Definition: EcalTPGOddWeightIdMapHandler.h:77
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EcalLogicID.h
EcalTPGWeights
Definition: EcalTPGWeights.h:9
std
Definition: JetResolutionObject.h:76
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
Exception
Definition: hltDiff.cc:245
FEConfigWeightInfo.h
RunList::getRuns
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
RunTPGConfigDat::getConfigTag
std::string getConfigTag() const
Definition: RunTPGConfigDat.h:20
ParameterSetfwd.h
FEConfigOddWeightGroupDat::getWeight4
float getWeight4() const
Definition: FEConfigOddWeightGroupDat.h:32
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
FEConfigOddWeightGroupDat::getWeight2
float getWeight2() const
Definition: FEConfigOddWeightGroupDat.h:28
dataset
Definition: dataset.py:1
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
beamvalidation.exit
def exit(msg="")
Definition: beamvalidation.py:52
IODConfig::setConfigTag
void setConfigTag(std::string x)
Definition: IODConfig.h:29
mps_splice.line
line
Definition: mps_splice.py:76
FEConfigMainInfo::getWei2Id
int getWei2Id() const
Definition: FEConfigMainInfo.h:73
FEConfigOddWeightGroupDat::getWeight3
float getWeight3() const
Definition: FEConfigOddWeightGroupDat.h:30
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37