CMS 3D CMS Logo

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