CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalTPGTPModeHandler.cc
Go to the documentation of this file.
2 
11 
13 
14 #include <iostream>
15 #include <fstream>
16 #include <map>
17 
18 #include <ctime>
19 #include <unistd.h>
20 
21 #include <string>
22 #include <cstdio>
23 #include <typeinfo>
24 #include <sstream>
25 
27  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGTPModeHandler")) {
28  edm::LogInfo("EcalTPGTPModeHandler") << "Ecal TPG TPMode Source handler constructor.";
29  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
30  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
31  m_sid = ps.getParameter<std::string>("OnlineDBSID");
32  m_user = ps.getParameter<std::string>("OnlineDBUser");
33  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
34  m_locationsource = ps.getParameter<std::string>("LocationSource");
35  m_location = ps.getParameter<std::string>("Location");
36  m_gentag = ps.getParameter<std::string>("GenTag");
37  m_runtype = ps.getParameter<std::string>("RunType");
38  m_file_type = ps.getParameter<std::string>("fileType"); // xml/txt
39  m_file_name = ps.getParameter<std::string>("fileName");
40 
41  edm::LogInfo("EcalTPGTPModeHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
42 }
43 
45 
47  if (m_file_type == "txt") {
48  readtxtFile();
49  } else {
50  edm::LogVerbatim("EcalTPGTPModeHandler") << "Started GetNewObjects!!!";
51 
52  //check whats already inside of database
53  if (tagInfo().size) {
54  //check whats already inside of database
55  edm::LogVerbatim("EcalTPGTPModeHandler") << "got offlineInfo = ";
56  edm::LogVerbatim("EcalTPGTPModeHandler") << "tag name = " << tagInfo().name;
57  edm::LogVerbatim("EcalTPGTPModeHandler") << "size = " << tagInfo().size;
58  } else {
59  edm::LogVerbatim("EcalTPGTPModeHandler") << " First object for this tag ";
60  }
61 
62  unsigned int max_since = 0;
63  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
64  edm::LogVerbatim("EcalTPGTPModeHandler") << "max_since : " << max_since;
65 
66  edm::LogVerbatim("EcalTPGTPModeHandler") << "retrieved last payload ";
67 
68  // here we retrieve all the runs after the last from online DB
69 
70  edm::LogVerbatim("EcalTPGTPModeHandler") << "Retrieving run list from ONLINE DB ... ";
71 
72  edm::LogVerbatim("EcalTPGTPModeHandler") << "Making connection...";
73  auto econn = std::make_shared<EcalCondDBInterface>(m_sid, m_user, m_pass);
74  edm::LogVerbatim("EcalTPGTPModeHandler") << "Done.";
75 
76  if (!econn) {
77  throw cms::Exception("OMDS not available") << " connection parameters " << m_sid << "/" << m_user;
78  }
79 
81  my_locdef.setLocation(m_location);
82 
84  my_rundef.setRunType(m_runtype);
85 
86  RunTag my_runtag;
87  my_runtag.setLocationDef(my_locdef);
88  my_runtag.setRunTypeDef(my_rundef);
89  my_runtag.setGeneralTag(m_gentag);
90 
91  readFromFile("last_tpg_TPMode_settings.txt");
92 
93  unsigned int min_run;
94 
95  if (m_firstRun < m_i_run_number) {
96  min_run = m_i_run_number + 1;
97  } else {
98  min_run = m_firstRun;
99  }
100 
101  if (min_run < max_since) {
102  min_run = max_since + 1; // we have to add 1 to the last transferred one
103  }
104 
105  edm::LogVerbatim("EcalTPGTPModeHandler")
106  << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since;
107 
108  unsigned int max_run = m_lastRun;
109  edm::LogVerbatim("EcalTPGTPModeHandler") << "min_run= " << min_run << " max_run= " << max_run;
110 
111  RunList my_list;
112  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
113 
114  std::vector<RunIOV> run_vec = my_list.getRuns();
115  size_t num_runs = run_vec.size();
116 
117  edm::LogVerbatim("EcalTPGTPModeHandler") << "number of runs is : " << num_runs;
118 
119  unsigned int irun = 0;
120  if (num_runs > 0) {
121  for (size_t kr = 0; kr < run_vec.size(); kr++) {
122  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
123  edm::LogVerbatim("EcalTPGTPModeHandler") << " **************** ";
124  edm::LogVerbatim("EcalTPGTPModeHandler") << " **************** ";
125  edm::LogVerbatim("EcalTPGTPModeHandler") << " run= " << irun;
126 
127  // retrieve the data :
128  std::map<EcalLogicID, RunTPGConfigDat> dataset;
129  econn->fetchDataSet(&dataset, &run_vec[kr]);
130 
131  std::string the_config_tag = "";
132  int the_config_version = 0;
133 
134  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
135 
136  int nr = 0;
137  for (it = dataset.begin(); it != dataset.end(); it++) {
138  ++nr;
139  EcalLogicID ecalid = it->first;
140  RunTPGConfigDat dat = it->second;
141  the_config_tag = dat.getConfigTag();
142  the_config_version = dat.getVersion();
143  }
144 
145  // it is all the same for all SM... get the last one
146  edm::LogVerbatim("EcalTPGTPModeHandler")
147  << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version;
148 
149  // here we should check if it is the same as previous run.
150 
151  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
152  edm::LogVerbatim("EcalTPGTPModeHandler")
153  << "the tag is different from last transferred run ... retrieving last config set from DB";
154 
155  FEConfigMainInfo fe_main_info;
156  fe_main_info.setConfigTag(the_config_tag);
157  fe_main_info.setVersion(the_config_version);
158 
159  try {
160  edm::LogVerbatim("EcalTPGTPModeHandler") << " before fetch config set";
161  econn->fetchConfigSet(&fe_main_info);
162  edm::LogVerbatim("EcalTPGTPModeHandler") << " after fetch config set";
163 
164  // now get TPGTPMode
165  int wId = fe_main_info.getWei2Id();
166  if (wId != m_i_TPMode) {
167  FEConfigOddWeightInfo fe_odd_weight_info;
168  fe_odd_weight_info.setId(wId);
169  econn->fetchConfigSet(&fe_odd_weight_info);
170  std::map<EcalLogicID, FEConfigOddWeightModeDat> dataset_mode;
171  econn->fetchDataSet(&dataset_mode, &fe_odd_weight_info);
172 
173  typedef std::map<EcalLogicID, FEConfigOddWeightModeDat>::const_iterator CIfem;
174  FEConfigOddWeightModeDat rd_mode;
175 
176  int rd_modev[19] = {0};
177  int k = 0;
178  for (CIfem p = dataset_mode.begin(); p != dataset_mode.end(); p++) {
179  rd_mode = p->second;
180  rd_modev[0] = rd_mode.getEnableEBOddFilter();
181  rd_modev[1] = rd_mode.getEnableEEOddFilter();
182  rd_modev[2] = rd_mode.getEnableEBOddPeakFinder();
183  rd_modev[3] = rd_mode.getEnableEEOddPeakFinder();
184  rd_modev[4] = rd_mode.getDisableEBEvenPeakFinder();
185  rd_modev[5] = rd_mode.getDisableEEEvenPeakFinder();
186  rd_modev[6] = rd_mode.getFenixEBStripOutput();
187  rd_modev[7] = rd_mode.getFenixEEStripOutput();
188  rd_modev[8] = rd_mode.getFenixEBStripInfobit2();
189  rd_modev[9] = rd_mode.getFenixEEStripInfobit2();
190  rd_modev[10] = rd_mode.getFenixEBTcpOutput();
191  rd_modev[11] = rd_mode.getFenixEBTcpInfobit1();
192  rd_modev[12] = rd_mode.getFenixEETcpOutput();
193  rd_modev[13] = rd_mode.getFenixEETcpInfobit1();
194 
195  edm::LogVerbatim("EcalTPGTPModeHandler") << "here is the value for the weight mode: ";
196  edm::LogVerbatim("EcalTPGTPModeHandler") << " EnableEBOddFilter:" << rd_modev[0];
197  edm::LogVerbatim("EcalTPGTPModeHandler") << " EnableEEOddFilter:" << rd_modev[1];
198  edm::LogVerbatim("EcalTPGTPModeHandler") << " EnableEBOddPeakFinder:" << rd_modev[2];
199  edm::LogVerbatim("EcalTPGTPModeHandler") << " EnableEEOddPeakFinder:" << rd_modev[3];
200  edm::LogVerbatim("EcalTPGTPModeHandler") << " DisableEBEvenPeakFinder:" << rd_modev[4];
201  edm::LogVerbatim("EcalTPGTPModeHandler") << " DisableEEEvenPeakFinder:" << rd_modev[5];
202  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEBStripOutput:" << rd_modev[6];
203  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEEStripOutput:" << rd_modev[7];
204  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEBStripInfobit2:" << rd_modev[8];
205  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEEStripInfobit2:" << rd_modev[9];
206  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEBTcpOutput:" << rd_modev[10];
207  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEBTcpinfobit1:" << rd_modev[11];
208  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEETcpOutput:" << rd_modev[12];
209  edm::LogVerbatim("EcalTPGTPModeHandler") << " FenixEETcpinfobit1:" << rd_modev[13];
210  k = k + 1;
211  }
212 
213  edm::LogVerbatim("EcalTPGTPModeHandler") << "*****************************************";
214  edm::LogVerbatim("EcalTPGTPModeHandler") << "read done " << wId;
215  edm::LogVerbatim("EcalTPGTPModeHandler") << "*****************************************";
216 
217  EcalTPGTPMode* tpMode = new EcalTPGTPMode;
218  tpMode->EnableEBOddFilter = rd_modev[0];
219  tpMode->EnableEEOddFilter = rd_modev[1];
220  tpMode->EnableEBOddPeakFinder = rd_modev[2];
221  tpMode->EnableEEOddPeakFinder = rd_modev[3];
222  tpMode->DisableEBEvenPeakFinder = rd_modev[4];
223  tpMode->DisableEEEvenPeakFinder = rd_modev[5];
224  tpMode->FenixEBStripOutput = rd_modev[6];
225  tpMode->FenixEEStripOutput = rd_modev[7];
226  tpMode->FenixEBStripInfobit2 = rd_modev[8];
227  tpMode->FenixEEStripInfobit2 = rd_modev[9];
228  tpMode->EBFenixTcpOutput = rd_modev[10];
229  tpMode->EBFenixTcpInfobit1 = rd_modev[11];
230  tpMode->EEFenixTcpOutput = rd_modev[12];
231  tpMode->EEFenixTcpInfobit1 = rd_modev[13];
232  tpMode->FenixPar15 = 0;
233  tpMode->FenixPar16 = 0;
234  tpMode->FenixPar17 = 0;
235  tpMode->FenixPar18 = 0;
236  Time_t snc = (Time_t)irun;
237  m_to_transfer.push_back(std::make_pair((EcalTPGTPMode*)tpMode, snc));
238 
239  m_i_run_number = irun;
240  m_i_tag = the_config_tag;
241  m_i_version = the_config_version;
242  m_i_TPMode = wId;
243 
244  writeFile("last_tpg_TPMode_settings.txt");
245 
246  } else {
247  m_i_run_number = irun;
248  m_i_tag = the_config_tag;
249  m_i_version = the_config_version;
250 
251  writeFile("last_tpg_TPMode_settings.txt");
252 
253  edm::LogVerbatim("EcalTPGTPModeHandler")
254  << " even if the tag/version is not the same, the weight group id is the same -> no transfer needed ";
255  }
256 
257  }
258 
259  catch (std::exception& e) {
260  throw cms::Exception("FileReadError") << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag
261  << " version=" << the_config_version << "\n"
262  << e.what();
263  }
264  edm::LogVerbatim("EcalTPGTPModeHandler") << " **************** ";
265 
266  } else if (nr == 0) {
267  m_i_run_number = irun;
268  edm::LogVerbatim("EcalTPGTPModeHandler")
269  << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed ";
270  edm::LogVerbatim("EcalTPGTPModeHandler") << " **************** ";
271  } else {
272  m_i_run_number = irun;
273  m_i_tag = the_config_tag;
274  m_i_version = the_config_version;
275  edm::LogVerbatim("EcalTPGTPModeHandler") << " the tag/version is the same -> no transfer needed ";
276  edm::LogVerbatim("EcalTPGTPModeHandler") << " **************** ";
277  writeFile("last_tpg_TPMode_settings.txt");
278  }
279  }
280  }
281 
282  } // usual way
283  edm::LogVerbatim("EcalTPGTPModeHandler") << "Ecal - > end of getNewObjects -----------";
284 }
285 
287  edm::LogVerbatim("EcalTPGTPModeHandler") << " reading the input file " << m_file_name;
288  std::ifstream fInput;
289  fInput.open(m_file_name);
290  if (!fInput.is_open()) {
291  throw cms::Exception("FileOpenError") << "ERROR : cannot open file " << m_file_name;
292  }
293  std::map<std::string, int> values;
294  EcalTPGTPMode* tpMode = new EcalTPGTPMode;
295 
297  int value;
298  while (fInput.good()) {
299  fInput >> key >> value;
300  values[key] = value;
301  }
302 
303  try {
304  tpMode->EnableEBOddFilter = values["EnableEBOddFilter"];
305  tpMode->EnableEEOddFilter = values["EnableEEOddFilter"];
306  tpMode->EnableEBOddPeakFinder = values["EnableEBOddPeakFinder"];
307  tpMode->EnableEEOddPeakFinder = values["EnableEEOddPeakFinder"];
308  tpMode->DisableEBEvenPeakFinder = values["DisableEBEvenPeakFinder"];
309  tpMode->DisableEEEvenPeakFinder = values["DisableEEEvenPeakFinder"];
310  tpMode->FenixEBStripOutput = values["FenixEBStripOutput"];
311  tpMode->FenixEEStripOutput = values["FenixEEStripOutput"];
312  tpMode->FenixEBStripInfobit2 = values["FenixEBStripInfobit2"];
313  tpMode->FenixEEStripInfobit2 = values["FenixEEStripInfobit2"];
314  tpMode->EBFenixTcpOutput = values["EBFenixTcpOutput"];
315  tpMode->EBFenixTcpInfobit1 = values["EBFenixTcpInfobit1"];
316  tpMode->EEFenixTcpOutput = values["EEFenixTcpOutput"];
317  tpMode->EEFenixTcpInfobit1 = values["EEFenixTcpInfobit1"];
318 
319  Time_t snc = (Time_t)m_firstRun;
320  m_to_transfer.push_back(std::make_pair((EcalTPGTPMode*)tpMode, snc));
321 
322  } catch (std::exception& e) {
323  throw cms::Exception("FileReadError") << "EcalTPGTPModeHandler::readtxtFile error : " << e.what();
324  }
325  edm::LogVerbatim("EcalTPGTPModeHandler") << " **************** ";
326 }
327 
329  m_i_tag = "";
330  m_i_version = 0;
331  m_i_run_number = 0;
332  m_i_TPMode = 0;
333 
334  FILE* inpFile; // input file
335  inpFile = fopen(inputFile, "r");
336  if (!inpFile) {
337  edm::LogError("EcalTPGTPModeHandler") << "*** Can not open file: " << inputFile;
338  return;
339  }
340 
341  char line[256];
342 
343  std::ostringstream str;
344 
345  fgets(line, 255, inpFile);
346  m_i_tag = to_string(line);
347  str << "gen tag " << m_i_tag << std::endl;
348 
349  fgets(line, 255, inpFile);
350  m_i_version = atoi(line);
351  str << "version= " << m_i_version << std::endl;
352 
353  fgets(line, 255, inpFile);
354  m_i_run_number = atoi(line);
355  str << "run_number= " << m_i_run_number << std::endl;
356 
357  fgets(line, 255, inpFile);
358  m_i_TPMode = atoi(line);
359  str << "TPMode_config= " << m_i_TPMode << std::endl;
360 
361  fclose(inpFile); // close inp. file
362 }
363 
365  std::ofstream myfile;
366  myfile.open(inputFile);
367  myfile << m_i_tag << std::endl;
368  myfile << m_i_version << std::endl;
369  myfile << m_i_run_number << std::endl;
370  myfile << m_i_TPMode << std::endl;
371 
372  myfile.close();
373 }
Log< level::Info, true > LogVerbatim
uint16_t FenixPar15
Definition: EcalTPGTPMode.h:32
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
void readFromFile(const char *inputFile)
uint16_t EBFenixTcpInfobit1
Definition: EcalTPGTPMode.h:28
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
std::string getConfigTag() const
uint16_t FenixEBStripOutput
Definition: EcalTPGTPMode.h:23
uint16_t FenixEEStripInfobit2
Definition: EcalTPGTPMode.h:26
uint16_t EBFenixTcpOutput
Definition: EcalTPGTPMode.h:27
int getVersion() const
uint16_t FenixPar16
Definition: EcalTPGTPMode.h:33
uint16_t EEFenixTcpInfobit1
Definition: EcalTPGTPMode.h:30
Definition: RunTag.h:13
bool EnableEEOddFilter
Definition: EcalTPGTPMode.h:18
uint16_t FenixEBStripInfobit2
Definition: EcalTPGTPMode.h:25
uint16_t FenixPar17
Definition: EcalTPGTPMode.h:34
Log< level::Error, false > LogError
void setVersion(int id)
void readFromFile(CaloCluster &c, FILE *file)
int getWei2Id() const
uint16_t EEFenixTcpOutput
Definition: EcalTPGTPMode.h:29
uint16_t FenixEEStripOutput
Definition: EcalTPGTPMode.h:24
bool DisableEBEvenPeakFinder
Definition: EcalTPGTPMode.h:21
EcalTPGTPModeHandler(edm::ParameterSet const &)
bool EnableEBOddPeakFinder
Definition: EcalTPGTPMode.h:19
bool EnableEEOddPeakFinder
Definition: EcalTPGTPMode.h:20
tuple key
prepare the HTCondor submission files and eventually submit them
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
void writeFile(const char *inputFile)
Log< level::Info, false > LogInfo
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:21
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
static std::vector< std::string > checklist dat
bool DisableEEEvenPeakFinder
Definition: EcalTPGTPMode.h:22
cond::Time_t Time_t
Definition: Time.h:18
void setConfigTag(std::string x)
Definition: IODConfig.h:29
void setLocation(std::string loc)
Definition: LocationDef.cc:20
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
#define str(s)
uint16_t FenixPar18
Definition: EcalTPGTPMode.h:35
bool EnableEBOddFilter
Definition: EcalTPGTPMode.h:17
tuple size
Write out results.