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;
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 
187  for (CIfesli p = dataset_TpgSli.begin(); p != dataset_TpgSli.end(); p++) {
188  ecid_xt = p->first;
189  rd_sli = p->second;
190 
191  std::string ecid_name = ecid_xt.getName();
192 
193  // EB data
194  if (ecid_name == "EB_VFE") {
195  int sm = ecid_xt.getID1();
196  int tt = ecid_xt.getID2();
197  int strip = ecid_xt.getID3();
198  int tcc = sm + 54;
199  if (sm > 18)
200  tcc = sm + 18;
201 
202  // simple formula to calculate the Srip EB identifier
203 
204  unsigned int stripEBId = 303176 + (tt - 1) * 64 + (strip - 1) * 8 + (tcc - 37) * 8192;
205 
206  sliW->setValue(stripEBId, (unsigned int)rd_sli.getSliding());
207 
208  } else if (ecid_name == "ECAL_readout_strip") {
209  // EE data
210  int id1 = ecid_xt.getID1(); // dcc
211  int id2 = ecid_xt.getID2(); // ccu
212  int id3 = ecid_xt.getID3(); // strip
213 
214  bool set_the_strip = false;
215  int stripid;
216  for (size_t istrip = 0; istrip < my_StripEcalLogicId_EE.size(); istrip++) {
217  if (!set_the_strip) {
218  if (my_StripEcalLogicId_EE[istrip].getID1() == id1 &&
219  my_StripEcalLogicId_EE[istrip].getID2() == id2 &&
220  my_StripEcalLogicId_EE[istrip].getID3() == id3) {
221  stripid = my_StripEcalLogicId_EE[istrip].getLogicID();
222  set_the_strip = true;
223  break;
224  }
225  }
226  }
227 
228  if (set_the_strip) {
229  sliW->setValue(stripid, (unsigned int)rd_sli.getSliding());
230 
231  } else {
232  std::cout << " these may be the additional towers TCC/TT " << id1 << "/" << id2 << std::endl;
233  }
234  }
235  }
236 
237  Time_t snc = (Time_t)irun;
238  m_to_transfer.push_back(std::make_pair((EcalTPGSlidingWindow*)sliW, snc));
239 
240  m_i_run_number = irun;
241  m_i_tag = the_config_tag;
242  m_i_version = the_config_version;
243  m_i_sliding = slidingId;
244 
245  writeFile("last_tpg_sliding_settings.txt");
246 
247  } else {
248  m_i_run_number = irun;
249  m_i_tag = the_config_tag;
250  m_i_version = the_config_version;
251 
252  writeFile("last_tpg_sliding_settings.txt");
253 
254  std::cout
255  << " even if the tag/version is not the same, the sliding windows id is the same -> no transfer needed "
256  << std::endl;
257  }
258  } catch (std::exception& e) {
259  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
260  << std::endl;
261  std::cout << e.what() << std::endl;
262 
263  m_i_run_number = irun;
264  }
265 
266  std::cout << " **************** " << std::endl;
267 
268  } else if (nr == 0) {
269  m_i_run_number = irun;
270  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
271  std::cout << " **************** " << std::endl;
272  } else {
273  m_i_run_number = irun;
274  m_i_tag = the_config_tag;
275  m_i_version = the_config_version;
276  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
277  std::cout << " **************** " << std::endl;
278  writeFile("last_tpg_sliding_settings.txt");
279  }
280  }
281  }
282 
283  delete econn;
284 
285  edm::LogInfo("EcalTPGSlidingWindowHandler") << "Ecal - > end of getNewObjects -----------";
286 }
287 
289  //-------------------------------------------------------------
290 
291  m_i_tag = "";
292  m_i_version = 0;
293  m_i_run_number = 0;
294  m_i_sliding = 0;
295 
296  FILE* inpFile; // input file
297  inpFile = fopen(inputFile, "r");
298  if (!inpFile) {
299  edm::LogError("EcalTPGSlidingWindowHandler") << "*** Can not open file: " << inputFile;
300  return;
301  }
302 
303  char line[256];
304 
305  std::ostringstream str;
306 
307  fgets(line, 255, inpFile);
308  m_i_tag = to_string(line);
309  str << "gen tag " << m_i_tag << std::endl; // should I use this?
310 
311  fgets(line, 255, inpFile);
312  m_i_version = atoi(line);
313  str << "version= " << m_i_version << std::endl;
314 
315  fgets(line, 255, inpFile);
316  m_i_run_number = atoi(line);
317  str << "run_number= " << m_i_run_number << std::endl;
318 
319  fgets(line, 255, inpFile);
320  m_i_sliding = atoi(line);
321  str << "sliding_config= " << m_i_sliding << std::endl;
322 
323  fclose(inpFile); // close inp. file
324 }
325 
327  //-------------------------------------------------------------
328 
329  std::ofstream myfile;
330  myfile.open(inputFile);
331  myfile << m_i_tag << std::endl;
332  myfile << m_i_version << std::endl;
333  myfile << m_i_run_number << std::endl;
334  myfile << m_i_sliding << std::endl;
335 
336  myfile.close();
337 }
size
Write out results.
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
int getID1() const
Definition: EcalLogicID.cc:30
std::string getName() const
Definition: EcalLogicID.cc:26
Definition: RunTag.h:13
int getID2() const
Definition: EcalLogicID.cc:32
int getVersion() const
float getSliding() const
Log< level::Error, false > LogError
void setVersion(int id)
static std::string to_string(const XMLCh *ch)
Definition: TTTypes.h:54
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
void setValue(const uint32_t &id, const uint32_t &value)
Log< level::Info, false > LogInfo
int getSliId() const
std::string getConfigTag() const
cond::Time_t Time_t
Definition: Time.h:18
int getID3() const
Definition: EcalLogicID.cc:34
void setConfigTag(std::string x)
Definition: IODConfig.h:29
EcalTPGSlidingWindowHandler(edm::ParameterSet const &)
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
#define str(s)