CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGFineGrainEBIdMapHandler.cc
Go to the documentation of this file.
2 
9 
10 #include<iostream>
11 #include<fstream>
12 
13 
14 #include <time.h>
15 #include <unistd.h>
16 
17 #include <string>
18 #include <cstdio>
19 #include <typeinfo>
20 #include <sstream>
21 
23  : m_name(ps.getUntrackedParameter<std::string>("name","EcalTPGFineGrainEBIdMapHandler")) {
24 
25  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "EcalTPGFineGrainEBIdMap Source handler constructor.";
26  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
27  m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
28  m_sid= ps.getParameter<std::string>("OnlineDBSID");
29  m_user= ps.getParameter<std::string>("OnlineDBUser");
30  m_pass= ps.getParameter<std::string>("OnlineDBPassword");
31  m_locationsource= ps.getParameter<std::string>("LocationSource");
32  m_location=ps.getParameter<std::string>("Location");
33  m_gentag=ps.getParameter<std::string>("GenTag");
34  m_runtype=ps.getParameter<std::string>("RunType");
35 
36  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag;
37 }
38 
40 {
41 }
42 
43 
45 {
46 
47  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "Started GetNewObjects!!!";
48 
49  //check whats already inside of database
50  if (tagInfo().size){
51  //check whats already inside of database
52  std::cout << "got offlineInfo = " << std::endl;
53  std::cout << "tag name = " << tagInfo().name << std::endl;
54  std::cout << "size = " << tagInfo().size << std::endl;
55  } else {
56  std::cout << " First object for this tag " << std::endl;
57  }
58 
59 
60  unsigned int max_since=0;
61  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
62  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "max_since : " << max_since;
63  Ref fgrIdMap_db = lastPayload();
64 
65  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "retrieved last payload ";
66 
67  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") <<"WOW: we just retrieved the last valid record from DB ";
68 
69 
70  // here we retrieve all the runs after the last from online DB
71 
72  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "Retrieving run list from ONLINE DB ... ";
73 
74  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "Making connection...";
75  econn = new EcalCondDBInterface( m_sid, m_user, m_pass );
76  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "Done.";
77 
78  if (!econn)
79  {
80  std::cout << " connection parameters " <<m_sid <<"/"<<m_user<<std::endl;
81  // cerr << e.what() << std::endl;
82  throw cms::Exception("OMDS not available");
83  }
84 
85 
86  LocationDef my_locdef;
87  my_locdef.setLocation(m_location);
88 
89  RunTypeDef my_rundef;
90  my_rundef.setRunType(m_runtype);
91 
92  RunTag my_runtag;
93  my_runtag.setLocationDef( my_locdef );
94  my_runtag.setRunTypeDef( my_rundef );
95  my_runtag.setGeneralTag(m_gentag);
96 
97  readFromFile("last_tpg_fgrIdMap_settings.txt");
98 
99 
100  unsigned int min_run=m_i_run_number+1;
101 
102  if(m_firstRun<m_i_run_number) {
103  min_run=m_i_run_number+1;
104  } else {
105  min_run=m_firstRun;
106  }
107  if(min_run<max_since) {
108  min_run=max_since+1; // we have to add 1 to the last transferred one
109  }
110 
111  std::cout<<"m_i_run_number"<< m_i_run_number <<"m_firstRun "<<m_firstRun<< "max_since " <<max_since<< std::endl;
112 
113  unsigned int max_run=m_lastRun;
114  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "min_run= " << min_run << "max_run= " << max_run;
115 
116  RunList my_list;
117  my_list=econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
118  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
119  printf ("after fetchRunList\n");fflush(stdout);
120 
121  std::vector<RunIOV> run_vec= my_list.getRuns();
122  size_t num_runs=run_vec.size();
123 
124  std::cout <<"number of runs is : "<< num_runs<< std::endl;
125 
126  unsigned int irun;
127  if(num_runs>0){
128 
129  for(size_t kr=0; kr<run_vec.size(); kr++){
130 
131  irun=static_cast<unsigned int>(run_vec[kr].getRunNumber());
132 
133  std::cout<<" **************** "<<std::endl;
134  std::cout<<" **************** "<<std::endl;
135  std::cout<<" run= "<<irun<<std::endl;
136 
137  // retrieve the data :
138  std::map<EcalLogicID, RunTPGConfigDat> dataset;
139  econn->fetchDataSet(&dataset, &run_vec[kr]);
140 
141  std::string the_config_tag="";
142  int the_config_version=0;
143 
144  std::map< EcalLogicID, RunTPGConfigDat>::const_iterator it;
145 
146  int nr=0;
147  for( it=dataset.begin(); it!=dataset.end(); it++ )
148  {
149  ++nr;
150  EcalLogicID ecalid = it->first;
151  RunTPGConfigDat dat = it->second;
152  the_config_tag=dat.getConfigTag();
153  the_config_version=dat.getVersion();
154  }
155 
156  // it is all the same for all SM... get the last one
157 
158 
159  std::cout<<" run= "<<irun<<" tag "<<the_config_tag<<" version="<<the_config_version <<std::endl;
160 
161  // here we should check if it is the same as previous run.
162 
163 
164  if((the_config_tag != m_i_tag || the_config_version != m_i_version ) && nr>0 ) {
165  std::cout<<"the tag is different from last transferred run ... retrieving last config set from DB"<<std::endl;
166 
167  FEConfigMainInfo fe_main_info;
168  fe_main_info.setConfigTag(the_config_tag);
169  fe_main_info.setVersion(the_config_version);
170 
171  try{
172  std::cout << " before fetch config set" << std::endl;
173  econn-> fetchConfigSet(&fe_main_info);
174  std::cout << " after fetch config set" << std::endl;
175 
176  // now get TPGFineGrainEBIdMap
177  int fgrId=fe_main_info.getFgrId();
178  if( fgrId != m_i_fgrIdMap ) {
179 
180  FEConfigFgrInfo fe_fgr_info;
181  fe_fgr_info.setId(fgrId);
182  econn-> fetchConfigSet(&fe_fgr_info);
183  std::map<EcalLogicID, FEConfigFgrGroupDat> dataset_TpgFineGrainEB;
184  econn->fetchDataSet(&dataset_TpgFineGrainEB, &fe_fgr_info);
185  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "Got object!";
187  typedef std::map<EcalLogicID, FEConfigFgrGroupDat>::const_iterator CIfefgr;
188  EcalLogicID ecid_xt;
189  FEConfigFgrGroupDat rd_fgr;
190 
191  int igroups=0;
192  for (CIfefgr p = dataset_TpgFineGrainEB.begin(); p != dataset_TpgFineGrainEB.end(); p++)
193  {
194  ecid_xt = p->first;
195  rd_fgr = p->second;
196 
197  std::string ecid_name=ecid_xt.getName();
198 
200  unsigned int ThrL = (unsigned int)rd_fgr.getThreshLow();
201  unsigned int ThrH = (unsigned int)rd_fgr.getThreshHigh();
202  unsigned int RatioL = (unsigned int)rd_fgr.getRatioLow();
203  unsigned int RatioH = (unsigned int)rd_fgr.getRatioHigh();
204  unsigned int LutConfId = (unsigned int)rd_fgr.getLUTValue();
205  // I have exchanged the values to see if it works
206  f.setValues(RatioL,RatioH, ThrL,ThrH,LutConfId);
207  fgrMap->setValue(rd_fgr.getFgrGroupId(),f);
208  ++igroups;
209  }
210 
211  Time_t snc= (Time_t) irun ;
212  m_to_transfer.push_back(std::make_pair((EcalTPGFineGrainEBIdMap*)fgrMap,snc));
213 
214  m_i_run_number=irun;
215  m_i_tag=the_config_tag;
216  m_i_version=the_config_version;
217  m_i_fgrIdMap=fgrId;
218 
219  writeFile("last_tpg_fgrIdMap_settings.txt");
220 
221  } else {
222 
223  m_i_run_number=irun;
224  m_i_tag=the_config_tag;
225  m_i_version=the_config_version;
226 
227  writeFile("last_tpg_fgrIdMap_settings.txt");
228 
229  std::cout<< " even if the tag/version is not the same, the fgrIdMap is the same -> no transfer needed "<< std::endl;
230 
231  }
232 
233  }
234 
235  catch (std::exception &e) {
236  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" <<the_config_tag
237  <<" version="<<the_config_version<< std::endl;
238  std::cout << e.what() << std::endl;
239  m_i_run_number=irun;
240 
241  }
242  std::cout<<" **************** "<<std::endl;
243 
244  } else if(nr==0) {
245  m_i_run_number=irun;
246  std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
247  std::cout<<" **************** "<<std::endl;
248  } else {
249  m_i_run_number=irun;
250  m_i_tag=the_config_tag;
251  m_i_version=the_config_version;
252  std::cout<< " the tag/version is the same -> no transfer needed "<< std::endl;
253  std::cout<<" **************** "<<std::endl;
254  writeFile("last_tpg_fgrIdMap_settings.txt");
255  }
256 
257  }
258  }
259 
260  delete econn;
261  edm::LogInfo("EcalTPGFineGrainEBIdMapHandler") << "Ecal - > end of getNewObjects -----------";
262 }
263 
265  //-------------------------------------------------------------
266 
267  m_i_tag="";
268  m_i_version=0;
269  m_i_run_number=0;
270  m_i_fgrIdMap=0;
271 
272  FILE *inpFile; // input file
273  inpFile = fopen(inputFile,"r");
274  if(!inpFile) {
275  edm::LogError("EcalTPGFineGrainEBIdMapHandler")<<"*** Can not open file: "<<inputFile;
276  }
277 
278  char line[256];
279 
280  std::ostringstream str;
281 
282  fgets(line,255,inpFile);
283  m_i_tag=to_string(line);
284  str << "gen tag " << m_i_tag << std::endl ; // should I use this?
285 
286  fgets(line,255,inpFile);
287  m_i_version=atoi(line);
288  str << "version= " << m_i_version << std::endl ;
289 
290  fgets(line,255,inpFile);
291  m_i_run_number=atoi(line);
292  str << "run_number= " << m_i_run_number << std::endl ;
293 
294  fgets(line,255,inpFile);
295  m_i_fgrIdMap=atoi(line);
296  str << "fgrIdMap_config= " << m_i_fgrIdMap << std::endl ;
297 
298 
299  fclose(inpFile); // close inp. file
300 
301 }
302 
304  //-------------------------------------------------------------
305 
306 
307  std::ofstream myfile;
308  myfile.open (inputFile);
309  myfile << m_i_tag <<std::endl;
310  myfile << m_i_version <<std::endl;
311  myfile << m_i_run_number <<std::endl;
312  myfile << m_i_fgrIdMap <<std::endl;
313 
314  myfile.close();
315 
316 }
317 
T getParameter(std::string const &) const
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
void setValue(const uint32_t &id, const EcalTPGFineGrainConstEB &value)
std::vector< RunIOV > getRuns()
Definition: RunList.cc:35
std::string getConfigTag() const
int getVersion() const
Definition: RunTag.h:13
void setValues(const uint32_t &ThresholdETLow, const uint32_t &ThresholdETHigh, const uint32_t &RatioLow, const uint32_t &RatioHigh, const uint32_t &LUT)
void setVersion(int id)
std::string to_string(const T &t)
Definition: Logger.cc:26
std::string getName() const
Definition: EcalLogicID.cc:36
float getRatioLow() const
double f[11][100]
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void setId(int id)
float getThreshLow() const
float getRatioHigh() const
int getFgrId() const
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
tuple dataset
Definition: dataset.py:400
static std::vector< std::string > checklist dat
cond::Time_t Time_t
Definition: Time.h:17
void setConfigTag(std::string x)
Definition: IODConfig.h:31
void setLocation(std::string loc)
Definition: LocationDef.cc:33
tuple cout
Definition: gather_cfg.py:121
float getThreshHigh() const
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
tuple size
Write out results.