CMS 3D CMS Logo

EcalTPGSlidingWindowHandler.cc
Go to the documentation of this file.
2 
4 
6 
14 
18 
19 #include <iostream>
20 #include <fstream>
21 
22 #include <ctime>
23 #include <unistd.h>
24 
25 #include <string>
26 #include <cstdio>
27 #include <typeinfo>
28 #include <sstream>
29 
31  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGSlidingWindowHandler")) {
32  edm::LogInfo("EcalTPGSlidingWindowHandler") << "EcalTPGSlidingWindow Source handler constructor";
33  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
34  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
35  m_sid = ps.getParameter<std::string>("OnlineDBSID");
36  m_user = ps.getParameter<std::string>("OnlineDBUser");
37  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
38  m_locationsource = ps.getParameter<std::string>("LocationSource");
39  m_location = ps.getParameter<std::string>("Location");
40  m_gentag = ps.getParameter<std::string>("GenTag");
41  m_runtype = ps.getParameter<std::string>("RunType");
42 
43  edm::LogInfo("EcalTPGSlidingWindowHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
44 }
45 
47 
49  edm::LogInfo("EcalTPGSlidingWindowHandler") << "Started GetNewObjects!!!";
50 
51  //check whats already inside of database
52  if (tagInfo().size) {
53  //check whats already inside of database
54  std::cout << "got offlineInfo = " << std::endl;
55  std::cout << "tag name = " << tagInfo().name << std::endl;
56  std::cout << "size = " << tagInfo().size << std::endl;
57  } else {
58  std::cout << " First object for this tag " << std::endl;
59  }
60 
61  unsigned int max_since = 0;
62  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
63  edm::LogInfo("EcalTPGSlidingWindowHandler") << "max_since : " << max_since;
64  edm::LogInfo("EcalTPGSlidingWindowHandler") << "retrieved last payload ";
65 
66  // here we retrieve all the runs after the last from online DB
67 
68  edm::LogInfo("EcalTPGSlidingWindowHandler") << "Retrieving run list from ONLINE DB ... ";
69 
70  edm::LogInfo("EcalTPGSlidingWindowHandler") << "Making connection...";
71  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
72  edm::LogInfo("EcalTPGSlidingWindowHandler") << "Done.";
73 
74  if (!econn) {
75  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
76  throw cms::Exception("OMDS not available");
77  }
78 
80  my_locdef.setLocation(m_location);
81 
83  my_rundef.setRunType(m_runtype);
84 
85  RunTag my_runtag;
86  my_runtag.setLocationDef(my_locdef);
87  my_runtag.setRunTypeDef(my_rundef);
88  my_runtag.setGeneralTag(m_gentag);
89 
90  readFromFile("last_tpg_sliding_settings.txt");
91 
92  unsigned int min_run = m_i_run_number + 1;
93  if (m_firstRun < m_i_run_number) {
94  min_run = m_i_run_number + 1; // we have to add 1 to the last transferred one
95  } else {
96  min_run = m_firstRun;
97  }
98 
99  if (min_run < max_since) {
100  min_run = max_since + 1; // we have to add 1 to the last transferred one
101  }
102 
103  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
104  << std::endl;
105 
106  unsigned int max_run = m_lastRun;
107 
108  edm::LogInfo("EcalTPGSlidingWindowHandler") << "min_run= " << min_run << "max_run= " << max_run;
109 
110  RunList my_list;
111  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
112  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run, my_locdef);
113 
114  std::vector<RunIOV> run_vec = my_list.getRuns();
115  size_t num_runs = run_vec.size();
116 
117  std::cout << "number of runs is : " << num_runs << std::endl;
118 
119  unsigned int irun = 0;
120  if (num_runs > 0) {
121  // going to query the ecal logic id
122  std::vector<EcalLogicID> my_StripEcalLogicId_EE;
123  my_StripEcalLogicId_EE =
124  econn->getEcalLogicIDSetOrdered("ECAL_readout_strip", 1, 1000, 1, 70, 0, 5, "EE_offline_stripid", 123);
125  std::cout << " GOT the logic ID for the EE trigger strips " << std::endl;
126 
127  for (size_t kr = 0; kr < run_vec.size(); kr++) {
128  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
129 
130  std::cout << " **************** " << std::endl;
131  std::cout << " **************** " << std::endl;
132  std::cout << " run= " << irun << std::endl;
133 
134  // retrieve the data :
135  std::map<EcalLogicID, RunTPGConfigDat> dataset;
136  econn->fetchDataSet(&dataset, &run_vec[kr]);
137 
138  std::string the_config_tag = "";
139  int the_config_version = 0;
140 
141  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
142  FEConfigMainInfo fe_main_info;
143 
144  int nr = 0;
145  for (it = dataset.begin(); it != dataset.end(); it++) {
146  ++nr;
147  //EcalLogicID ecalid = it->first;
148  RunTPGConfigDat dat = it->second;
149  the_config_tag = dat.getConfigTag();
150  the_config_version = dat.getVersion();
151  }
152 
153  // it is all the same for all SM... get the last one
154 
155  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
156 
157  // here we should check if it is the same as previous run.
158 
159  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
160  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
161  << std::endl;
162 
163  FEConfigMainInfo fe_main_info;
164  fe_main_info.setConfigTag(the_config_tag);
165  fe_main_info.setVersion(the_config_version);
166 
167  try {
168  std::cout << " before fetch config set" << std::endl;
169  econn->fetchConfigSet(&fe_main_info);
170  std::cout << " after fetch config set" << std::endl;
171 
172  // now get TPGSlidingWindow
173  int slidingId = fe_main_info.getSliId();
174 
175  if (slidingId != m_i_sliding) {
176  FEConfigSlidingInfo fe_sli_info;
177  fe_sli_info.setId(slidingId);
178  econn->fetchConfigSet(&fe_sli_info);
179  std::map<EcalLogicID, FEConfigSlidingDat> dataset_TpgSli;
180  econn->fetchDataSet(&dataset_TpgSli, &fe_sli_info);
181 
183  typedef std::map<EcalLogicID, FEConfigSlidingDat>::const_iterator CIfesli;
184  EcalLogicID ecid_xt;
185  FEConfigSlidingDat rd_sli;
186  int icells = 0;
187 
188  for (CIfesli p = dataset_TpgSli.begin(); p != dataset_TpgSli.end(); p++) {
189  ecid_xt = p->first;
190  rd_sli = p->second;
191 
192  std::string ecid_name = ecid_xt.getName();
193 
194  // EB data
195  if (ecid_name == "EB_VFE") {
196  int sm = ecid_xt.getID1();
197  int tt = ecid_xt.getID2();
198  int strip = ecid_xt.getID3();
199  int tcc = sm + 54;
200  if (sm > 18)
201  tcc = sm + 18;
202 
203  // simple formula to calculate the Srip EB identifier
204 
205  unsigned int stripEBId = 303176 + (tt - 1) * 64 + (strip - 1) * 8 + (tcc - 37) * 8192;
206 
207  sliW->setValue(stripEBId, (unsigned int)rd_sli.getSliding());
208  ++icells;
209 
210  } else if (ecid_name == "ECAL_readout_strip") {
211  // EE data
212  int id1 = ecid_xt.getID1(); // dcc
213  int id2 = ecid_xt.getID2(); // ccu
214  int id3 = ecid_xt.getID3(); // strip
215 
216  bool set_the_strip = false;
217  int stripid;
218  for (size_t istrip = 0; istrip < my_StripEcalLogicId_EE.size(); istrip++) {
219  if (!set_the_strip) {
220  if (my_StripEcalLogicId_EE[istrip].getID1() == id1 &&
221  my_StripEcalLogicId_EE[istrip].getID2() == id2 &&
222  my_StripEcalLogicId_EE[istrip].getID3() == id3) {
223  stripid = my_StripEcalLogicId_EE[istrip].getLogicID();
224  set_the_strip = true;
225  break;
226  }
227  }
228  }
229 
230  if (set_the_strip) {
231  sliW->setValue(stripid, (unsigned int)rd_sli.getSliding());
232 
233  } else {
234  std::cout << " these may be the additional towers TCC/TT " << id1 << "/" << id2 << std::endl;
235  }
236 
237  ++icells;
238  }
239  }
240 
241  Time_t snc = (Time_t)irun;
242  m_to_transfer.push_back(std::make_pair((EcalTPGSlidingWindow*)sliW, snc));
243 
244  m_i_run_number = irun;
245  m_i_tag = the_config_tag;
246  m_i_version = the_config_version;
247  m_i_sliding = slidingId;
248 
249  writeFile("last_tpg_sliding_settings.txt");
250 
251  } else {
252  m_i_run_number = irun;
253  m_i_tag = the_config_tag;
254  m_i_version = the_config_version;
255 
256  writeFile("last_tpg_sliding_settings.txt");
257 
258  std::cout
259  << " even if the tag/version is not the same, the sliding windows id is the same -> no transfer needed "
260  << std::endl;
261  }
262  } catch (std::exception& e) {
263  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
264  << std::endl;
265  std::cout << e.what() << std::endl;
266 
267  m_i_run_number = irun;
268  }
269 
270  std::cout << " **************** " << std::endl;
271 
272  } else if (nr == 0) {
273  m_i_run_number = irun;
274  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
275  std::cout << " **************** " << std::endl;
276  } else {
277  m_i_run_number = irun;
278  m_i_tag = the_config_tag;
279  m_i_version = the_config_version;
280  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
281  std::cout << " **************** " << std::endl;
282  writeFile("last_tpg_sliding_settings.txt");
283  }
284  }
285  }
286 
287  delete econn;
288 
289  edm::LogInfo("EcalTPGSlidingWindowHandler") << "Ecal - > end of getNewObjects -----------";
290 }
291 
293  //-------------------------------------------------------------
294 
295  m_i_tag = "";
296  m_i_version = 0;
297  m_i_run_number = 0;
298  m_i_sliding = 0;
299 
300  FILE* inpFile; // input file
301  inpFile = fopen(inputFile, "r");
302  if (!inpFile) {
303  edm::LogError("EcalTPGSlidingWindowHandler") << "*** Can not open file: " << inputFile;
304  return;
305  }
306 
307  char line[256];
308 
309  std::ostringstream str;
310 
311  fgets(line, 255, inpFile);
312  m_i_tag = to_string(line);
313  str << "gen tag " << m_i_tag << std::endl; // should I use this?
314 
315  fgets(line, 255, inpFile);
316  m_i_version = atoi(line);
317  str << "version= " << m_i_version << std::endl;
318 
319  fgets(line, 255, inpFile);
320  m_i_run_number = atoi(line);
321  str << "run_number= " << m_i_run_number << std::endl;
322 
323  fgets(line, 255, inpFile);
324  m_i_sliding = atoi(line);
325  str << "sliding_config= " << m_i_sliding << std::endl;
326 
327  fclose(inpFile); // close inp. file
328 }
329 
331  //-------------------------------------------------------------
332 
333  std::ofstream myfile;
334  myfile.open(inputFile);
335  myfile << m_i_tag << std::endl;
336  myfile << m_i_version << std::endl;
337  myfile << m_i_run_number << std::endl;
338  myfile << m_i_sliding << std::endl;
339 
340  myfile.close();
341 }
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
popcon::EcalTPGSlidingWindowHandler::m_pass
std::string m_pass
Definition: EcalTPGSlidingWindowHandler.h:78
popcon::EcalTPGSlidingWindowHandler::m_user
std::string m_user
Definition: EcalTPGSlidingWindowHandler.h:77
ESHandle.h
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
FEConfigSlidingInfo
Definition: FEConfigSlidingInfo.h:11
RunList
Definition: RunList.h:16
EcalTPGSlidingWindowHandler.h
EcalTPGSlidingWindow::setValue
void setValue(const uint32_t &id, const uint32_t &value)
Definition: EcalTPGSlidingWindow.cc:7
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
RunTag
Definition: RunTag.h:13
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
globals_cff.id1
id1
Definition: globals_cff.py:32
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalLogicID::getName
std::string getName() const
Definition: EcalLogicID.cc:26
FEConfigMainInfo
Definition: FEConfigMainInfo.h:14
edm::LogInfo
Definition: MessageLogger.h:254
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalTPGSlidingWindow >::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
popcon::EcalTPGSlidingWindowHandler::EcalTPGSlidingWindowHandler
EcalTPGSlidingWindowHandler(edm::ParameterSet const &)
Definition: EcalTPGSlidingWindowHandler.cc:30
popcon::EcalTPGSlidingWindowHandler::getNewObjects
void getNewObjects() override
Definition: EcalTPGSlidingWindowHandler.cc:48
RunTPGConfigDat.h
EcalLogicID::getID1
int getID1() const
Definition: EcalLogicID.cc:30
FEConfigMainInfo::setVersion
void setVersion(int id)
Definition: FEConfigMainInfo.h:66
FEConfigSlidingInfo::setId
void setId(int id)
Definition: FEConfigSlidingInfo.h:24
EcalLaserHandler.h
EcalLogicID::getID2
int getID2() const
Definition: EcalLogicID.cc:32
EcalTPGSlidingWindow
Definition: EcalTPGSlidingWindow.h:9
FEConfigSlidingInfo.h
popcon::EcalTPGSlidingWindowHandler::writeFile
void writeFile(const char *inputFile)
Definition: EcalTPGSlidingWindowHandler.cc:330
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
EcalMappingRcd.h
str
#define str(s)
Definition: TestProcessor.cc:48
popcon::EcalTPGSlidingWindowHandler::m_location
std::string m_location
Definition: EcalTPGSlidingWindowHandler.h:74
EcalLogicID
Definition: EcalLogicID.h:7
RunTPGConfigDat
Definition: RunTPGConfigDat.h:11
popcon::EcalTPGSlidingWindowHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalTPGSlidingWindowHandler.h:70
popcon::EcalTPGSlidingWindowHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalTPGSlidingWindowHandler.h:69
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::EcalTPGSlidingWindowHandler::m_runtype
std::string m_runtype
Definition: EcalTPGSlidingWindowHandler.h:82
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
edm::ParameterSet
Definition: ParameterSet.h:36
popcon::EcalTPGSlidingWindowHandler::~EcalTPGSlidingWindowHandler
~EcalTPGSlidingWindowHandler() override
Definition: EcalTPGSlidingWindowHandler.cc:46
edm::LogError
Definition: MessageLogger.h:183
popcon::EcalTPGSlidingWindowHandler::m_locationsource
std::string m_locationsource
Definition: EcalTPGSlidingWindowHandler.h:79
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
FEConfigSlidingDat
Definition: FEConfigSlidingDat.h:11
EcalElectronicsMapping.h
popcon::EcalTPGSlidingWindowHandler::m_sid
std::string m_sid
Definition: EcalTPGSlidingWindowHandler.h:76
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
FEConfigSlidingDat::getSliding
float getSliding() const
Definition: FEConfigSlidingDat.h:21
FEConfigMainInfo::getSliId
int getSliId() const
Definition: FEConfigMainInfo.h:46
EcalLogicID.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
std
Definition: JetResolutionObject.h:76
writedatasetfile.dataset
dataset
Definition: writedatasetfile.py:19
EcalTPGSlidingWindow.h
RunTPGConfigDat::getVersion
int getVersion() const
Definition: RunTPGConfigDat.h:22
RunTag::setLocationDef
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
FEConfigSlidingDat.h
popcon::EcalTPGSlidingWindowHandler::readFromFile
void readFromFile(const char *inputFile)
Definition: EcalTPGSlidingWindowHandler.cc:292
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
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
dataset
Definition: dataset.py:1
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
IODConfig::setConfigTag
void setConfigTag(std::string x)
Definition: IODConfig.h:29
globals_cff.id2
id2
Definition: globals_cff.py:33
mps_splice.line
line
Definition: mps_splice.py:76
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
popcon::EcalTPGSlidingWindowHandler::m_gentag
std::string m_gentag
Definition: EcalTPGSlidingWindowHandler.h:75