CMS 3D CMS Logo

EcalTPGSpikeThresholdHandler.cc
Go to the documentation of this file.
7 
9 
10 
12 
14 
15 
16 
23 
28 
29 
30 
31 #include<iostream>
32 #include<fstream>
33 
34 #include <time.h>
35 #include <unistd.h>
36 
37 #include <string>
38 #include <cstdio>
39 #include <typeinfo>
40 #include <sstream>
41 
43  : m_name(ps.getUntrackedParameter<std::string>("name","EcalTPGSpikeThresholdHandler")) {
44 
45  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "EcalTPGSpike Source handler constructor";
46  m_firstRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("firstRun").c_str()));
47  m_lastRun=static_cast<unsigned int>(atoi( ps.getParameter<std::string>("lastRun").c_str()));
48  m_sid= ps.getParameter<std::string>("OnlineDBSID");
49  m_user= ps.getParameter<std::string>("OnlineDBUser");
50  m_pass= ps.getParameter<std::string>("OnlineDBPassword");
51  m_locationsource= ps.getParameter<std::string>("LocationSource");
52  m_location=ps.getParameter<std::string>("Location");
53  m_gentag=ps.getParameter<std::string>("GenTag");
54  m_runtype=ps.getParameter<std::string>("RunType");
55 
56  edm::LogInfo("EcalTPGSpikeThresholdHandler") << m_sid<<"/"<<m_user<<"/"<<m_location<<"/"<<m_gentag;
57 }
58 
60 {
61 }
62 
63 
65 {
66 
67 
68  using namespace edm;
69  using namespace std;
70 
71  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "Started GetNewObjects!!!";
72 
73  //check whats already inside of database
74  if (tagInfo().size){
75  //check whats already inside of database
76  std::cout << "got offlineInfo = " << std::endl;
77  std::cout << "tag name = " << tagInfo().name << std::endl;
78  std::cout << "size = " << tagInfo().size << std::endl;
79  } else {
80  std::cout << " First object for this tag " << std::endl;
81  }
82 
83  unsigned int max_since=0;
84  max_since=static_cast<unsigned int>(tagInfo().lastInterval.first);
85  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "max_since : " << max_since;
86  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "retrieved last payload ";
87 
88  // here we retrieve all the runs after the last from online DB
89  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "Retrieving run list from ONLINE DB ... ";
90 
91  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "Making connection...";
93  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "Done.";
94 
95  if (!econn)
96  {
97  std::cout << " connection parameters " <<m_sid <<"/"<<m_user<<std::endl;
98  // cerr << e.what() << std::endl;
99  throw cms::Exception("OMDS not available");
100  }
101 
102 
103  LocationDef my_locdef;
104  my_locdef.setLocation(m_location);
105 
106  RunTypeDef my_rundef;
107  my_rundef.setRunType(m_runtype);
108 
109  RunTag my_runtag;
110  my_runtag.setLocationDef( my_locdef );
111  my_runtag.setRunTypeDef( my_rundef );
112  my_runtag.setGeneralTag(m_gentag);
113 
114 
115  readFromFile("last_tpg_spikeThreshold_settings.txt");
116 
117 
118  unsigned int min_run=m_i_run_number+1;
119 
121  min_run=m_i_run_number+1;
122  } else {
123  min_run=m_firstRun;
124  }
125 
126 
127  if(min_run<max_since) {
128  min_run= max_since+1; // we have to add 1 to the last transferred one
129  }
130 
131  std::cout<<"m_i_run_number"<< m_i_run_number <<"m_firstRun "<<m_firstRun<< "max_since " <<max_since<< std::endl;
132 
133  unsigned int max_run=m_lastRun;
134  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "min_run= " << min_run << " max_run= " << max_run;
135 
136  RunList my_list;
137  my_list=econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
138  //my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
139 
140  std::vector<RunIOV> run_vec= my_list.getRuns();
141  size_t num_runs=run_vec.size();
142 
143  std::cout <<"number of runs is : "<< num_runs<< std::endl;
144 
145  std::string str="";
146 
147  unsigned int irun;
148  if(num_runs>0){
149 
150  for(size_t kr=0; kr<run_vec.size(); kr++){
151 
152  irun=static_cast<unsigned int>(run_vec[kr].getRunNumber());
153 
154  std::cout<<" **************** "<<std::endl;
155  std::cout<<" run= "<<irun<<std::endl;
156 
157  // retrieve the data :
158  std::map<EcalLogicID, RunTPGConfigDat> dataset;
159  econn->fetchDataSet(&dataset, &run_vec[kr]);
160 
161  std::string the_config_tag="";
162  int the_config_version=0;
163 
164  std::map< EcalLogicID, RunTPGConfigDat>::const_iterator it;
165 
166  int nr=0;
167  for( it=dataset.begin(); it!=dataset.end(); it++ )
168  {
169  ++nr;
170  //EcalLogicID ecalid = it->first;
171 
172  RunTPGConfigDat dat = it->second;
173  the_config_tag=dat.getConfigTag();
174  the_config_version=dat.getVersion();
175  }
176 
177 
178  // it is all the same for all SM... get the last one
179 
180 
181  std::cout<<" run= "<<irun<<" tag "<<the_config_tag<<" version="<<the_config_version <<std::endl;
182 
183  // here we should check if it is the same as previous run.
184 
185 
186  if((the_config_tag != m_i_tag || the_config_version != m_i_version ) && nr>0 ) {
187  std::cout<<"the tag is different from last transferred run ... retrieving last config set from DB"<<std::endl;
188 
189  FEConfigMainInfo fe_main_info;
190  fe_main_info.setConfigTag(the_config_tag);
191  fe_main_info.setVersion(the_config_version);
192 
193  try{
194  std::cout << " before fetch config set" << std::endl;
195  econn-> fetchConfigSet(&fe_main_info);
196  std::cout << " after fetch config set" << std::endl;
197 
198 
199  // now get TPGSpikeThreshold
200  int spikeId=fe_main_info.getSpiId();
201 
202  if( spikeId != m_i_spikeTh ) {
203 
204  FEConfigSpikeInfo fe_spike_info;
205  fe_spike_info.setId(spikeId);
206  econn-> fetchConfigSet(&fe_spike_info);
207  std::map<EcalLogicID, FEConfigSpikeDat> dataset_TpgSpike;
208  econn->fetchDataSet(&dataset_TpgSpike, &fe_spike_info);
209 
211  typedef std::map<EcalLogicID, FEConfigSpikeDat>::const_iterator CIfelut;
212  EcalLogicID ecid_xt;
213  FEConfigSpikeDat rd_spike;
214  int itowers=0;
215 
216  for (CIfelut p = dataset_TpgSpike.begin(); p != dataset_TpgSpike.end(); p++)
217  {
218  ecid_xt = p->first;
219  rd_spike = p->second;
220 
221  std::string ecid_name=ecid_xt.getName();
222 
223  if(ecid_name=="EB_trigger_tower") {
224  // SM number
225  int smid=ecid_xt.getID1();
226  // TT number
227  int towerid=ecid_xt.getID2();
228 
229 
230  int tow_eta=(towerid-1)/4;
231  int tow_phi=((towerid-1)-tow_eta*4);
232 
233  int axt=(tow_eta*5)*20 + tow_phi*5 +1 ;
234 
235  EBDetId id(smid, axt, EBDetId::SMCRYSTALMODE ) ;
236  const EcalTrigTowerDetId towid= id.tower();
237 
238  //std::cout << " TTid = " << towid.rawId() << " SpikeTh = " <<rd_spike.getSpikeThreshold() << std::endl;
239 
240  lut->setValue(towid.rawId(), rd_spike.getSpikeThreshold());
241  ++itowers;
242  }
243  ++itowers;
244  }
245 
246  std::cout <<" The number of towers is = " << itowers << std::endl;
247 
248  Time_t snc= (Time_t) irun;
249 
250  m_to_transfer.push_back(std::make_pair((EcalTPGSpike*)lut,snc));
251 
252  m_i_run_number=irun;
253  m_i_tag=the_config_tag;
254  m_i_version=the_config_version;
255  m_i_spikeTh=spikeId;
256 
257  writeFile("last_tpg_spikeThreshold_settings.txt");
258 
259  } else {
260 
261  m_i_run_number=irun;
262  m_i_tag=the_config_tag;
263  m_i_version=the_config_version;
264 
265  writeFile("last_tpg_spikeThreshold_settings.txt");
266 
267  std::cout<< " even if the tag/version is not the same, the lutGroup id is the same -> no transfer needed "<< std::endl;
268 
269  }
270 
271  }
272 
273  catch (std::exception &e) {
274  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" <<the_config_tag
275  <<" version="<<the_config_version<< std::endl;
276  std::cout << e.what() << std::endl;
277  m_i_run_number=irun;
278 
279  }
280  std::cout<<" **************** "<<std::endl;
281 
282  } else if(nr==0) {
283  m_i_run_number=irun;
284  std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
285  std::cout<<" **************** "<<std::endl;
286  } else {
287  m_i_run_number=irun;
288  m_i_tag=the_config_tag;
289  m_i_version=the_config_version;
290  std::cout<< " the tag/version is the same -> no transfer needed "<< std::endl;
291  std::cout<<" **************** "<<std::endl;
292  writeFile("last_tpg_spikeThreshold_settings.txt");
293  }
294  }
295  }
296 
297  delete econn;
298 
299  edm::LogInfo("EcalTPGSpikeThresholdHandler") << "Ecal - > end of getNewObjects -----------";
300 }
301 
303  //-------------------------------------------------------------
304 
305  m_i_tag="";
306  m_i_version=0;
307  m_i_run_number=0;
308  m_i_spikeTh=0;
309 
310  FILE *inpFile; // input file
311  inpFile = fopen(inputFile,"r");
312  if(!inpFile) {
313  edm::LogError("EcalTPGSpikeThresholdHandler")<<"*** Can not open file: "<<inputFile;
314  return;
315  }
316 
317  char line[256];
318 
319  std::ostringstream str;
320 
321  fgets(line,255,inpFile);
322  m_i_tag=to_string(line);
323  str << "gen tag " << m_i_tag << std::endl ; // should I use this?
324 
325  fgets(line,255,inpFile);
326  m_i_version=atoi(line);
327  str << "version= " << m_i_version << std::endl ;
328 
329  fgets(line,255,inpFile);
330  m_i_run_number=atoi(line);
331  str << "run_number= " << m_i_run_number << std::endl ;
332 
333  fgets(line,255,inpFile);
334  m_i_spikeTh=atoi(line);
335  str << "spikeTh_config= " << m_i_spikeTh << std::endl ;
336 
337 
338  fclose(inpFile); // close inp. file
339 
340 }
341 
343  //-------------------------------------------------------------
344 
345 
346  std::ofstream myfile;
347  myfile.open (inputFile);
348  myfile << m_i_tag <<std::endl;
349  myfile << m_i_version <<std::endl;
350  myfile << m_i_run_number <<std::endl;
351  myfile << m_i_spikeTh <<std::endl;
352 
353  myfile.close();
354 
355 }
size
Write out results.
T getParameter(std::string const &) const
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:70
std::vector< RunIOV > getRuns()
Definition: RunList.cc:35
RunList fetchGlobalRunListByLocation(const RunTag &tag, int min_run, int max_run, const LocationDef &locDef) noexcept(false)
std::string getConfigTag() const
int getVersion() const
Definition: RunTag.h:13
EcalTPGSpikeThresholdHandler(edm::ParameterSet const &)
size_t size
Definition: Types.h:77
void setVersion(int id)
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
void setValue(const uint32_t &id, const uint16_t &val)
Definition: EcalTPGSpike.cc:10
std::string name
Definition: Types.h:73
int getID2() const
Definition: EcalLogicID.cc:51
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
cond::ValidityInterval lastInterval
Definition: Types.h:75
std::string getName() const
Definition: EcalLogicID.cc:36
int getSpiId() const
int getID1() const
Definition: EcalLogicID.cc:46
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
void setConfigTag(std::string x)
Definition: IODConfig.h:31
HLT enums.
void setLocation(std::string loc)
Definition: LocationDef.cc:33
int getSpikeThreshold() const
void setGeneralTag(std::string tag)
Definition: RunTag.cc:36
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
cond::TagInfo_t const & tagInfo() const