CMS 3D CMS Logo

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