CMS 3D CMS Logo

EcalTPGBadStripHandler.cc
Go to the documentation of this file.
2 
10 
12 
13 #include <iostream>
14 #include <fstream>
15 
16 #include <ctime>
17 #include <unistd.h>
18 
19 #include <string>
20 #include <cstdio>
21 #include <typeinfo>
22 #include <sstream>
23 
25  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGBadStripHandler")) {
26  edm::LogInfo("EcalTPGBadStripHandler") << "EcalTPGStripStatus Source handler constructor.";
27  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
28  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
29  m_sid = ps.getParameter<std::string>("OnlineDBSID");
30  m_user = ps.getParameter<std::string>("OnlineDBUser");
31  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
32  m_locationsource = ps.getParameter<std::string>("LocationSource");
33  m_location = ps.getParameter<std::string>("Location");
34  m_gentag = ps.getParameter<std::string>("GenTag");
35  m_runtype = ps.getParameter<std::string>("RunType");
36 
37  edm::LogInfo("EcalTPGBadStripHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
38 }
39 
41 
43  edm::LogInfo("EcalTPGBadStripHandler") << "Started GetNewObjects!!!";
44 
45  unsigned int max_since = 0;
46  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
47  edm::LogInfo("EcalTPGBadStripHandler") << "max_since : " << max_since;
48  edm::LogInfo("EcalTPGBadStripHandler") << "retrieved last payload ";
49 
50  // here we retrieve all the runs after the last from online DB
51  edm::LogInfo("EcalTPGBadStripHandler") << "Retrieving run list from ONLINE DB ... ";
52 
53  edm::LogInfo("EcalTPGBadStripHandler") << "Making connection...";
54  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
55  edm::LogInfo("EcalTPGBadStripHandler") << "Done.";
56 
57  if (!econn) {
58  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
59  throw cms::Exception("OMDS not available");
60  }
61 
63  my_locdef.setLocation(m_location);
64 
66  my_rundef.setRunType(m_runtype);
67 
68  RunTag my_runtag;
69  my_runtag.setLocationDef(my_locdef);
70  my_runtag.setRunTypeDef(my_rundef);
71  my_runtag.setGeneralTag(m_gentag);
72 
73  readFromFile("last_tpg_badStrip_settings.txt");
74 
75  unsigned int min_run = m_i_run_number + 1;
76 
77  if (m_firstRun < m_i_run_number) {
78  min_run = m_i_run_number + 1;
79  } else {
80  min_run = m_firstRun;
81  }
82  if (min_run < max_since) {
83  min_run = max_since + 1; // we have to add 1 to the last transferred one
84  }
85 
86  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
87  << std::endl;
88 
89  unsigned int max_run = m_lastRun;
90  edm::LogInfo("EcalTPGBadStripHandler") << "min_run= " << min_run << "max_run= " << max_run;
91 
92  RunList my_list;
93  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
94  //my_list=econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
95 
96  std::vector<RunIOV> run_vec = my_list.getRuns();
97  size_t num_runs = run_vec.size();
98 
99  std::cout << "number of runs is : " << num_runs << std::endl;
100 
101  std::string str = "";
102 
103  unsigned int irun = 0;
104 
105  if (num_runs > 0) {
106  // going to query the ecal logic id
107  std::vector<EcalLogicID> my_StripEcalLogicId_EE;
108  my_StripEcalLogicId_EE = econn->getEcalLogicIDSetOrdered("EE_trigger_strip",
109  1,
110  1000, //"TCC"
111  1,
112  100, //tower
113  0,
114  5, //strip
115  "EE_offline_stripid",
116  123);
117 
118  std::cout << " GOT the logic ID for the EE trigger strips " << std::endl;
119 
120  for (size_t kr = 0; kr < run_vec.size(); kr++) {
121  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
122 
123  std::cout << " **************** " << std::endl;
124  std::cout << " **************** " << std::endl;
125  std::cout << " run= " << irun << std::endl;
126 
127  // retrieve the data :
128  std::map<EcalLogicID, RunTPGConfigDat> dataset;
129  econn->fetchDataSet(&dataset, &run_vec[kr]);
130 
131  std::string the_config_tag = "";
132  int the_config_version = 0;
133 
134  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
135 
136  int nr = 0;
137  for (it = dataset.begin(); it != dataset.end(); it++) {
138  ++nr;
139  //EcalLogicID ecalid = it->first;
140 
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 << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
154  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
155  << std::endl;
156 
157  FEConfigMainInfo fe_main_info;
158  fe_main_info.setConfigTag(the_config_tag);
159  fe_main_info.setVersion(the_config_version);
160 
161  try {
162  econn->fetchConfigSet(&fe_main_info);
163 
164  // now get TPGStripStatus
165  int badstripId = fe_main_info.getBstId();
166 
167  if (badstripId != m_i_badStrip) {
168  FEConfigBadStripInfo fe_badStrip_info;
169  fe_badStrip_info.setId(badstripId);
170 
171  econn->fetchConfigSet(&fe_badStrip_info);
172 
173  std::vector<FEConfigBadStripDat> dataset_TpgBadStrip;
174 
175  econn->fetchConfigDataSet(&dataset_TpgBadStrip, &fe_badStrip_info);
176 
177  EcalTPGStripStatus* stripStatus = new EcalTPGStripStatus;
178  typedef std::vector<FEConfigBadStripDat>::const_iterator CIfeped;
179 
180  FEConfigBadStripDat rd_badStrip;
181  //unsigned int rd_stripStatus;
182 
183  // put at 1 the strip that are bad
184  int icells = 0;
185  int icellsFound = 0;
186  for (CIfeped p = dataset_TpgBadStrip.begin(); p != dataset_TpgBadStrip.end(); p++) {
187  rd_badStrip = *p;
188 
189  //int fed_num=rd_badStrip.getFedId();
190  int tcc_num = rd_badStrip.getTCCId();
191  int tt_num = rd_badStrip.getTTId();
192  int strip_num = rd_badStrip.getStripId();
193 
194  //std::cout << fed_num << " " << tcc_num << " " << tt_num << " " << strip_num << std::endl;
195 
196  // EE data
197  int stripid;
198 
199  bool set_the_strip = false;
200  for (size_t istrip = 0; istrip < my_StripEcalLogicId_EE.size(); istrip++) {
201  if (!set_the_strip) {
202  if (my_StripEcalLogicId_EE[istrip].getID1() == tcc_num &&
203  my_StripEcalLogicId_EE[istrip].getID2() == tt_num &&
204  my_StripEcalLogicId_EE[istrip].getID3() == strip_num) {
205  stripid = my_StripEcalLogicId_EE[istrip].getLogicID();
206 
207  set_the_strip = true;
208  ++icellsFound;
209  break;
210  }
211  }
212  }
213 
214  if (set_the_strip) {
215  stripStatus->setValue(stripid, (unsigned int)rd_badStrip.getStatus());
216  }
217 
218  ++icells;
219  }
220 
221  // std::cout << " icells = " << icells << std::endl;
222 
223  edm::LogInfo("EcalTPGBadStripHandler") << "Finished badStrip reading.";
224 
225  Time_t snc = (Time_t)irun;
226 
227  m_to_transfer.push_back(std::make_pair((EcalTPGStripStatus*)stripStatus, snc));
228 
229  m_i_run_number = irun;
230  m_i_tag = the_config_tag;
231  m_i_version = the_config_version;
232  m_i_badStrip = badstripId;
233 
234  writeFile("last_tpg_badStrip_settings.txt");
235 
236  } else {
237  m_i_run_number = irun;
238  m_i_tag = the_config_tag;
239  m_i_version = the_config_version;
240 
241  writeFile("last_tpg_badStrip_settings.txt");
242 
243  // std::cout<< " even if the tag/version is not the same, the badStrip id is the same -> no transfer needed "<< std::endl;
244  }
245 
246  }
247 
248  catch (std::exception& e) {
249  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
250  << std::endl;
251  std::cout << e.what() << std::endl;
252  m_i_run_number = irun;
253  }
254 
255  } else if (nr == 0) {
256  m_i_run_number = irun;
257  // std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
258  } else {
259  m_i_run_number = irun;
260  m_i_tag = the_config_tag;
261  m_i_version = the_config_version;
262 
263  writeFile("last_tpg_badStrip_settings.txt");
264  }
265  }
266  }
267 
268  delete econn;
269 
270  edm::LogInfo("EcalTPGBadStripHandler") << "Ecal - > end of getNewObjects -----------";
271 }
272 
274  //-------------------------------------------------------------
275 
276  m_i_tag = "";
277  m_i_version = 0;
278  m_i_run_number = 0;
279  m_i_badStrip = 0;
280 
281  FILE* inpFile; // input file
282  inpFile = fopen(inputFile, "r");
283  if (!inpFile) {
284  edm::LogError("EcalTPGBadStripHandler") << "*** Can not open file: " << inputFile;
285  return;
286  }
287 
288  char line[256];
289 
290  std::ostringstream str;
291 
292  fgets(line, 255, inpFile);
293  m_i_tag = to_string(line);
294  str << "gen tag " << m_i_tag << std::endl; // should I use this?
295 
296  fgets(line, 255, inpFile);
297  m_i_version = atoi(line);
298  str << "version= " << m_i_version << std::endl;
299 
300  fgets(line, 255, inpFile);
301  m_i_run_number = atoi(line);
302  str << "run_number= " << m_i_run_number << std::endl;
303 
304  fgets(line, 255, inpFile);
305  m_i_badStrip = atoi(line);
306  str << "badTT_config= " << m_i_badStrip << std::endl;
307 
308  fclose(inpFile); // close inp. file
309 }
310 
312  //-------------------------------------------------------------
313 
314  std::ofstream myfile;
315  myfile.open(inputFile);
316  myfile << m_i_tag << std::endl;
317  myfile << m_i_version << std::endl;
318  myfile << m_i_run_number << std::endl;
319  myfile << m_i_badStrip << std::endl;
320 
321  myfile.close();
322 }
popcon::EcalTPGBadStripHandler::EcalTPGBadStripHandler
EcalTPGBadStripHandler(edm::ParameterSet const &)
Definition: EcalTPGBadStripHandler.cc:24
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
l1tpf_impl::readFromFile
void readFromFile(CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:22
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
MessageLogger.h
RunList.h
popcon::EcalTPGBadStripHandler::~EcalTPGBadStripHandler
~EcalTPGBadStripHandler() override
Definition: EcalTPGBadStripHandler.cc:40
RunList
Definition: RunList.h:16
RunTag
Definition: RunTag.h:13
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
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< EcalTPGStripStatus >::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
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
FEConfigMainInfo::setVersion
void setVersion(int id)
Definition: FEConfigMainInfo.h:78
popcon::EcalTPGBadStripHandler::m_user
std::string m_user
Definition: EcalTPGBadStripHandler.h:76
FEConfigBadStripDat::getStripId
int getStripId() const
Definition: FEConfigBadStripDat.h:32
popcon::EcalTPGBadStripHandler::readFromFile
void readFromFile(const char *inputFile)
Definition: EcalTPGBadStripHandler.cc:273
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
str
#define str(s)
Definition: TestProcessor.cc:52
RunTPGConfigDat
Definition: RunTPGConfigDat.h:11
FEConfigBadStripInfo
Definition: FEConfigBadStripInfo.h:9
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
popcon::EcalTPGBadStripHandler::m_location
std::string m_location
Definition: EcalTPGBadStripHandler.h:73
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
FEConfigBadStripDat::getTCCId
int getTCCId() const
Definition: FEConfigBadStripDat.h:26
edm::ParameterSet
Definition: ParameterSet.h:47
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
EcalTPGStripStatus::setValue
void setValue(const uint32_t &id, const uint16_t &val)
Definition: EcalTPGStripStatus.cc:7
popcon::EcalTPGBadStripHandler::m_locationsource
std::string m_locationsource
Definition: EcalTPGBadStripHandler.h:78
FEConfigBadStripDat::getStatus
int getStatus() const
Definition: FEConfigBadStripDat.h:35
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
FEConfigBadStripInfo::setId
void setId(int id)
Definition: FEConfigBadStripInfo.h:18
EcalTPGBadStripHandler.h
EcalTPGStripStatus.h
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
EcalLogicID.h
popcon::EcalTPGBadStripHandler::m_sid
std::string m_sid
Definition: EcalTPGBadStripHandler.h:75
popcon::EcalTPGBadStripHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalTPGBadStripHandler.h:69
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
popcon::EcalTPGBadStripHandler::writeFile
void writeFile(const char *inputFile)
Definition: EcalTPGBadStripHandler.cc:311
popcon::EcalTPGBadStripHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalTPGBadStripHandler.h:70
RunList::getRuns
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
RunTPGConfigDat::getConfigTag
std::string getConfigTag() const
Definition: RunTPGConfigDat.h:20
ParameterSetfwd.h
FEConfigBadStripDat::getTTId
int getTTId() const
Definition: FEConfigBadStripDat.h:29
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
EcalTPGStripStatus
Definition: EcalTPGStripStatus.h:9
dataset
Definition: dataset.py:1
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
popcon::EcalTPGBadStripHandler::getNewObjects
void getNewObjects() override
Definition: EcalTPGBadStripHandler.cc:42
popcon::EcalTPGBadStripHandler::m_pass
std::string m_pass
Definition: EcalTPGBadStripHandler.h:77
IODConfig::setConfigTag
void setConfigTag(std::string x)
Definition: IODConfig.h:29
FEConfigMainInfo::getBstId
int getBstId() const
Definition: FEConfigMainInfo.h:64
popcon::EcalTPGBadStripHandler::m_runtype
std::string m_runtype
Definition: EcalTPGBadStripHandler.h:81
mps_splice.line
line
Definition: mps_splice.py:76
FEConfigBadStripDat
Definition: FEConfigBadStripDat.h:10
popcon::EcalTPGBadStripHandler::m_gentag
std::string m_gentag
Definition: EcalTPGBadStripHandler.h:74
FEConfigBadStripInfo.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37