CMS 3D CMS Logo

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