CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  int itowers = 0;
170 
171  for (CIfefgr p = dataset_TpgFineGrainEE.begin(); p != dataset_TpgFineGrainEE.end(); p++) {
172  ecid_xt = p->first;
173  rd_fgr = p->second;
174 
175  std::string ecid_name = ecid_xt.getName();
176 
177  if (ecid_name == "EE_trigger_tower") {
178  int tccid = ecid_xt.getID1();
179  // TT number
180  int towerid = ecid_xt.getID2();
181 
182  bool set_the_tower = false;
183  int towid;
184  for (size_t itower = 0; itower < my_TTEcalLogicId_EE.size(); itower++) {
185  if (!set_the_tower) {
186  if (my_TTEcalLogicId_EE[itower].getID1() == tccid &&
187  my_TTEcalLogicId_EE[itower].getID2() == towerid) {
188  towid = my_TTEcalLogicId_EE[itower].getLogicID();
189  set_the_tower = true;
190  break;
191  }
192  }
193  }
194 
195  if (set_the_tower) {
196  fgrMap->setValue(towid, rd_fgr.getLUTValue());
197 
198  } else {
199  std::cout << " these may be the additional towers TCC/TT " << tccid << "/" << towerid << std::endl;
200  }
201 
202  ++itowers;
203  }
204  }
205 
206  Time_t snc = (Time_t)irun;
207 
208  m_to_transfer.push_back(std::make_pair((EcalTPGFineGrainTowerEE *)fgrMap, snc));
209 
210  m_i_run_number = irun;
211  m_i_tag = the_config_tag;
212  m_i_version = the_config_version;
213  m_i_fgrTTEE = fgrId;
214 
215  writeFile("last_tpg_fgrTTEE_settings.txt");
216 
217  } else {
218  m_i_run_number = irun;
219  m_i_tag = the_config_tag;
220  m_i_version = the_config_version;
221 
222  writeFile("last_tpg_fgrTTEE_settings.txt");
223 
224  std::cout << " even if the tag/version is not the same, the fgrTTEE id is the same -> no transfer needed "
225  << std::endl;
226  }
227 
228  } catch (std::exception &e) {
229  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
230  << std::endl;
231  std::cout << e.what() << std::endl;
232  m_i_run_number = irun;
233  }
234  std::cout << " **************** " << std::endl;
235 
236  } else if (nr == 0) {
237  m_i_run_number = irun;
238  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
239  std::cout << " **************** " << std::endl;
240  } else {
241  m_i_run_number = irun;
242  m_i_tag = the_config_tag;
243  m_i_version = the_config_version;
244  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
245  std::cout << " **************** " << std::endl;
246  writeFile("last_tpg_fgrTTEE_settings.txt");
247  }
248  }
249  }
250 
251  delete econn;
252  edm::LogInfo("EcalTPGFineGrainTowerEEHandler") << "Ecal - > end of getNewObjects -----------";
253 }
254 
256  //-------------------------------------------------------------
257 
258  m_i_tag = "";
259  m_i_version = 0;
260  m_i_run_number = 0;
261  m_i_fgrTTEE = 0;
262 
263  FILE *inpFile; // input file
264  inpFile = fopen(inputFile, "r");
265  if (!inpFile) {
266  edm::LogError("EcalTPGFineGrainTowerEEHandler") << "*** Can not open file: " << inputFile;
267  return;
268  }
269 
270  char line[256];
271 
272  std::ostringstream str;
273 
274  fgets(line, 255, inpFile);
275  m_i_tag = to_string(line);
276  str << "gen tag " << m_i_tag << std::endl; // should I use this?
277 
278  fgets(line, 255, inpFile);
279  m_i_version = atoi(line);
280  str << "version= " << m_i_version << std::endl;
281 
282  fgets(line, 255, inpFile);
283  m_i_run_number = atoi(line);
284  str << "run_number= " << m_i_run_number << std::endl;
285 
286  fgets(line, 255, inpFile);
287  m_i_fgrTTEE = atoi(line);
288  str << "fgrTTEE_config= " << m_i_fgrTTEE << std::endl;
289 
290  fclose(inpFile); // close inp. file
291 }
292 
294  //-------------------------------------------------------------
295 
296  std::ofstream myfile;
297  myfile.open(inputFile);
298  myfile << m_i_tag << std::endl;
299  myfile << m_i_version << std::endl;
300  myfile << m_i_run_number << std::endl;
301  myfile << m_i_fgrTTEE << std::endl;
302 
303  myfile.close();
304 }
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
std::string getConfigTag() const
int getVersion() const
Definition: RunTag.h:13
std::string to_string(const V &value)
Definition: OMSAccess.h:71
Log< level::Error, false > LogError
void setVersion(int id)
void readFromFile(CaloCluster &c, FILE *file)
int getID2() const
Definition: EcalLogicID.cc:32
std::string getName() const
Definition: EcalLogicID.cc:26
int getID1() const
Definition: EcalLogicID.cc:30
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
int getFgrId() const
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
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 setLocation(std::string loc)
Definition: LocationDef.cc:20
tuple cout
Definition: gather_cfg.py:144
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
#define str(s)
tuple size
Write out results.