CMS 3D CMS Logo

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