CMS 3D CMS Logo

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