CMS 3D CMS Logo

EcalTPGLutGroupHandler.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", "EcalTPGLutGroupHandler")) {
39  edm::LogInfo("EcalTPGLutGroupHandler") << "EcalTPGLutGroup 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("EcalTPGLutGroupHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
51 }
52 
54 
56  using namespace edm;
57  using namespace std;
58 
59  edm::LogInfo("EcalTPGLutGroupHandler") << "Started GetNewObjects!!!";
60 
61  /*
62  // geometry
63  ESHandle<CaloGeometry> theGeometry;
64  ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
65  evtSetup.get<CaloGeometryRecord>().get( theGeometry );
66  evtSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",theEndcapGeometry_handle);
67  evtSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
68  evtSetup.get<IdealGeometryRecord>().get(eTTmap_);
69  theEndcapGeometry_ = &(*theEndcapGeometry_handle);
70  theBarrelGeometry_ = &(*theBarrelGeometry_handle);
71 
72  // electronics mapping
73  ESHandle< EcalElectronicsMapping > ecalmapping;
74  evtSetup.get< EcalMappingRcd >().get(ecalmapping);
75  theMapping_ = ecalmapping.product();
76 
77  const std::vector<DetId> & eeCells = theEndcapGeometry_->getValidDetIds(DetId::Ecal, EcalEndcap);
78 
79  */
80 
81  //check whats already inside of database
82  if (tagInfo().size) {
83  //check whats already inside of database
84  std::cout << "got offlineInfo = " << std::endl;
85  std::cout << "tag name = " << tagInfo().name << std::endl;
86  std::cout << "size = " << tagInfo().size << std::endl;
87  } else {
88  std::cout << " First object for this tag " << std::endl;
89  }
90 
91  unsigned int max_since = 0;
92  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
93  edm::LogInfo("EcalTPGLutGroupHandler") << "max_since : " << max_since;
94  edm::LogInfo("EcalTPGLutGroupHandler") << "retrieved last payload ";
95 
96  // here we retrieve all the runs after the last from online DB
97  edm::LogInfo("EcalTPGLutGroupHandler") << "Retrieving run list from ONLINE DB ... ";
98 
99  edm::LogInfo("EcalTPGLutGroupHandler") << "Making connection...";
100  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
101  edm::LogInfo("EcalTPGLutGroupHandler") << "Done.";
102 
103  if (!econn) {
104  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
105  // cerr << e.what() << std::endl;
106  throw cms::Exception("OMDS not available");
107  }
108 
110  my_locdef.setLocation(m_location);
111 
113  my_rundef.setRunType(m_runtype);
114 
115  RunTag my_runtag;
116  my_runtag.setLocationDef(my_locdef);
117  my_runtag.setRunTypeDef(my_rundef);
118  my_runtag.setGeneralTag(m_gentag);
119 
120  readFromFile("last_tpg_lutGroup_settings.txt");
121 
122  unsigned int min_run = m_i_run_number + 1;
123 
124  if (m_firstRun < m_i_run_number) {
125  min_run = m_i_run_number + 1;
126  } else {
127  min_run = m_firstRun;
128  }
129 
130  if (min_run < max_since) {
131  min_run = max_since + 1; // we have to add 1 to the last transferred one
132  }
133 
134  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
135  << std::endl;
136 
137  unsigned int max_run = m_lastRun;
138  edm::LogInfo("EcalTPGLutGroupHandler") << "min_run= " << min_run << " max_run= " << max_run;
139 
140  RunList my_list;
141  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
142  // my_list=econn->fetchRunListByLocation(my_runtag,min_run,max_run,my_locdef);
143 
144  std::vector<RunIOV> run_vec = my_list.getRuns();
145  size_t num_runs = run_vec.size();
146 
147  std::cout << "number of runs is : " << num_runs << std::endl;
148 
149  std::string str = "";
150 
151  unsigned int irun;
152  if (num_runs > 0) {
153  // going to query the ecal logic id
154  std::vector<EcalLogicID> my_TTEcalLogicId_EE;
155  my_TTEcalLogicId_EE = econn->getEcalLogicIDSetOrdered(
156  "EE_trigger_tower", 1, 200, 1, 70, EcalLogicID::NULLID, EcalLogicID::NULLID, "EE_offline_towerid", 12);
157  std::cout << " GOT the logic ID for the EE trigger towers " << std::endl;
158 
159  for (size_t kr = 0; kr < run_vec.size(); kr++) {
160  irun = static_cast<unsigned int>(run_vec[kr].getRunNumber());
161 
162  std::cout << " **************** " << std::endl;
163  std::cout << " run= " << irun << std::endl;
164 
165  // retrieve the data :
166  std::map<EcalLogicID, RunTPGConfigDat> dataset;
167  econn->fetchDataSet(&dataset, &run_vec[kr]);
168 
169  std::string the_config_tag = "";
170  int the_config_version = 0;
171 
172  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
173 
174  int nr = 0;
175  for (it = dataset.begin(); it != dataset.end(); it++) {
176  ++nr;
177  //EcalLogicID ecalid = it->first;
178 
179  RunTPGConfigDat dat = it->second;
180  the_config_tag = dat.getConfigTag();
181  the_config_version = dat.getVersion();
182  }
183 
184  // it is all the same for all SM... get the last one
185 
186  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
187 
188  // here we should check if it is the same as previous run.
189 
190  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
191  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
192  << std::endl;
193 
194  FEConfigMainInfo fe_main_info;
195  fe_main_info.setConfigTag(the_config_tag);
196  fe_main_info.setVersion(the_config_version);
197 
198  try {
199  std::cout << " before fetch config set" << std::endl;
200  econn->fetchConfigSet(&fe_main_info);
201  std::cout << " after fetch config set" << std::endl;
202 
203  // now get TPGLutGroup
204  int lutId = fe_main_info.getLUTId();
205 
206  if (lutId != m_i_lutGroup) {
207  FEConfigLUTInfo fe_lut_info;
208  fe_lut_info.setId(lutId);
209  econn->fetchConfigSet(&fe_lut_info);
210  std::map<EcalLogicID, FEConfigLUTDat> dataset_TpgLut;
211  econn->fetchDataSet(&dataset_TpgLut, &fe_lut_info);
212 
213  EcalTPGLutGroup *lut = new EcalTPGLutGroup();
214  typedef std::map<EcalLogicID, FEConfigLUTDat>::const_iterator CIfelut;
215  EcalLogicID ecid_xt;
216  FEConfigLUTDat rd_lut;
217  int itowers = 0;
218 
219  for (CIfelut p = dataset_TpgLut.begin(); p != dataset_TpgLut.end(); p++) {
220  ecid_xt = p->first;
221  rd_lut = p->second;
222 
223  std::string ecid_name = ecid_xt.getName();
224 
225  if (ecid_name == "EB_trigger_tower") {
226  // SM number
227  int smid = ecid_xt.getID1();
228  // TT number
229  int towerid = ecid_xt.getID2();
230 
231  int tow_eta = (towerid - 1) / 4;
232  int tow_phi = ((towerid - 1) - tow_eta * 4);
233 
234  int axt = (tow_eta * 5) * 20 + tow_phi * 5 + 1;
235 
236  EBDetId id(smid, axt, EBDetId::SMCRYSTALMODE);
237  const EcalTrigTowerDetId towid = id.tower();
238 
239  /*
240  char ch[10];
241  sprintf(ch,"%d%d", smid, towerid);
242  std::string S="";
243  S.insert(0,ch);
244 
245  unsigned int towerEBId = 0;
246  towerEBId = atoi(S.c_str());
247  */
248 
249  lut->setValue(towid.rawId(), rd_lut.getLUTGroupId());
250  ++itowers;
251  } else if (ecid_name == "EE_trigger_tower") {
252  // EE data
253  // TCC number
254  int tccid = ecid_xt.getID1();
255  // TT number
256  int towerid = ecid_xt.getID2();
257 
258  bool set_the_tower = false;
259  int towid;
260  for (size_t itower = 0; itower < my_TTEcalLogicId_EE.size(); itower++) {
261  if (!set_the_tower) {
262  if (my_TTEcalLogicId_EE[itower].getID1() == tccid &&
263  my_TTEcalLogicId_EE[itower].getID2() == towerid) {
264  towid = my_TTEcalLogicId_EE[itower].getLogicID();
265  set_the_tower = true;
266  break;
267  }
268  }
269  }
270 
271  if (set_the_tower) {
272  lut->setValue(towid, rd_lut.getLUTGroupId());
273  } else {
274  std::cout << " these may be the additional towers TCC/TT " << tccid << "/" << towerid << std::endl;
275  }
276 
277  ++itowers;
278  }
279  }
280 
281  Time_t snc = (Time_t)irun;
282 
283  m_to_transfer.push_back(std::make_pair((EcalTPGLutGroup *)lut, snc));
284 
285  m_i_run_number = irun;
286  m_i_tag = the_config_tag;
287  m_i_version = the_config_version;
288  m_i_lutGroup = lutId;
289 
290  writeFile("last_tpg_lutGroup_settings.txt");
291 
292  } else {
293  m_i_run_number = irun;
294  m_i_tag = the_config_tag;
295  m_i_version = the_config_version;
296 
297  writeFile("last_tpg_lutGroup_settings.txt");
298 
299  std::cout << " even if the tag/version is not the same, the lutGroup id is the same -> no transfer needed "
300  << std::endl;
301  }
302 
303  }
304 
305  catch (std::exception &e) {
306  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
307  << std::endl;
308  std::cout << e.what() << std::endl;
309  m_i_run_number = irun;
310  }
311  std::cout << " **************** " << std::endl;
312 
313  } else if (nr == 0) {
314  m_i_run_number = irun;
315  std::cout << " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed " << std::endl;
316  std::cout << " **************** " << std::endl;
317  } else {
318  m_i_run_number = irun;
319  m_i_tag = the_config_tag;
320  m_i_version = the_config_version;
321  std::cout << " the tag/version is the same -> no transfer needed " << std::endl;
322  std::cout << " **************** " << std::endl;
323  writeFile("last_tpg_lutGroup_settings.txt");
324  }
325  }
326  }
327 
328  delete econn;
329 
330  edm::LogInfo("EcalTPGLutGroupHandler") << "Ecal - > end of getNewObjects -----------";
331 }
332 
334  //-------------------------------------------------------------
335 
336  m_i_tag = "";
337  m_i_version = 0;
338  m_i_run_number = 0;
339  m_i_lutGroup = 0;
340 
341  FILE *inpFile; // input file
342  inpFile = fopen(inputFile, "r");
343  if (!inpFile) {
344  edm::LogError("EcalTPGLutGroupHandler") << "*** Can not open file: " << inputFile;
345  return;
346  }
347 
348  char line[256];
349 
350  std::ostringstream str;
351 
352  fgets(line, 255, inpFile);
353  m_i_tag = to_string(line);
354  str << "gen tag " << m_i_tag << std::endl; // should I use this?
355 
356  fgets(line, 255, inpFile);
357  m_i_version = atoi(line);
358  str << "version= " << m_i_version << std::endl;
359 
360  fgets(line, 255, inpFile);
361  m_i_run_number = atoi(line);
362  str << "run_number= " << m_i_run_number << std::endl;
363 
364  fgets(line, 255, inpFile);
365  m_i_lutGroup = atoi(line);
366  str << "lutGroup_config= " << m_i_lutGroup << std::endl;
367 
368  fclose(inpFile); // close inp. file
369 }
370 
372  //-------------------------------------------------------------
373 
374  std::ofstream myfile;
375  myfile.open(inputFile);
376  myfile << m_i_tag << std::endl;
377  myfile << m_i_version << std::endl;
378  myfile << m_i_run_number << std::endl;
379  myfile << m_i_lutGroup << std::endl;
380 
381  myfile.close();
382 }
EcalCondDBInterface
Definition: EcalCondDBInterface.h:37
l1tpf_impl::readFromFile
void readFromFile(CaloCluster &c, FILE *file)
Definition: DiscretePFInputsIO.h:22
popcon::EcalTPGLutGroupHandler::m_firstRun
unsigned int m_firstRun
Definition: EcalTPGLutGroupHandler.h:73
cond::time::Time_t
cond::Time_t Time_t
Definition: Time.h:18
MessageLogger.h
RunList
Definition: RunList.h:16
FEConfigLUTDat::getLUTGroupId
int getLUTGroupId() const
Definition: FEConfigLUTDat.h:21
popcon::EcalTPGLutGroupHandler::getNewObjects
void getNewObjects() override
Definition: EcalTPGLutGroupHandler.cc:55
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
RunTag
Definition: RunTag.h:13
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EcalLogicID::getName
std::string getName() const
Definition: EcalLogicID.cc:26
EBDetId.h
FEConfigMainInfo
Definition: FEConfigMainInfo.h:14
EEDetId.h
test_db_connect.econn
econn
Definition: test_db_connect.py:10
popcon::PopConSourceHandler< EcalTPGLutGroup >::Time_t
cond::Time_t Time_t
Definition: PopConSourceHandler.h:34
LocationDef
Definition: LocationDef.h:12
DeadROCCounter.getRunNumber
def getRunNumber(filename)
Definition: DeadROCCounter.py:7
RunTPGConfigDat.h
EcalTPGLutGroupHandler.h
EcalTrigTowerDetId
Definition: EcalTrigTowerDetId.h:14
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
popcon::EcalTPGLutGroupHandler::m_location
std::string m_location
Definition: EcalTPGLutGroupHandler.h:80
EcalLogicID::getID1
int getID1() const
Definition: EcalLogicID.cc:30
FEConfigMainInfo::setVersion
void setVersion(int id)
Definition: FEConfigMainInfo.h:78
EcalTPGLutGroup
Definition: EcalTPGLutGroup.h:13
popcon::EcalTPGLutGroupHandler::readFromFile
void readFromFile(const char *inputFile)
Definition: EcalTPGLutGroupHandler.cc:333
EcalLogicID::getID2
int getID2() const
Definition: EcalLogicID.cc:32
popcon::EcalTPGLutGroupHandler::m_user
std::string m_user
Definition: EcalTPGLutGroupHandler.h:83
FEConfigMainInfo.h
RunTag::setGeneralTag
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
test_db_connect.my_rundef
my_rundef
Definition: test_db_connect.py:13
EcalTPGGroups::setValue
void setValue(const uint32_t &rawId, const uint32_t &ObjectId)
Definition: EcalTPGGroups.cc:7
popcon::EcalTPGLutGroupHandler::writeFile
void writeFile(const char *inputFile)
Definition: EcalTPGLutGroupHandler.cc:371
EcalMappingRcd.h
str
#define str(s)
Definition: TestProcessor.cc:52
EcalLogicID
Definition: EcalLogicID.h:7
RunTPGConfigDat
Definition: RunTPGConfigDat.h:11
CaloGeometryRecord.h
FEConfigLUTDat
Definition: FEConfigLUTDat.h:11
EcalTrigTowerDetId.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
popcon::EcalTPGLutGroupHandler::m_sid
std::string m_sid
Definition: EcalTPGLutGroupHandler.h:82
EcalSubdetector.h
RunTypeDef
Definition: RunTypeDef.h:12
test_db_connect.my_locdef
my_locdef
Definition: test_db_connect.py:11
EcalTPGLutGroup.h
cppFunctionSkipper.exception
exception
Definition: cppFunctionSkipper.py:10
popcon::EcalTPGLutGroupHandler::EcalTPGLutGroupHandler
EcalTPGLutGroupHandler(edm::ParameterSet const &)
Definition: EcalTPGLutGroupHandler.cc:37
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
EgHLTOffHistBins_cfi.nr
nr
Definition: EgHLTOffHistBins_cfi.py:4
FEConfigLUTDat.h
popcon::EcalTPGLutGroupHandler::m_pass
std::string m_pass
Definition: EcalTPGLutGroupHandler.h:84
EcalElectronicsMapping.h
dtResolutionTest_cfi.inputFile
inputFile
Definition: dtResolutionTest_cfi.py:14
FEConfigLUTInfo
Definition: FEConfigLUTInfo.h:11
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
FEConfigLUTInfo.h
EcalLogicID.h
CaloCellGeometry.h
EcalLogicID::NULLID
static const int NULLID
Definition: EcalLogicID.h:35
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
writedatasetfile.dataset
dataset
Definition: writedatasetfile.py:19
RunTPGConfigDat::getVersion
int getVersion() const
Definition: RunTPGConfigDat.h:22
RunTag::setLocationDef
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
popcon::EcalTPGLutGroupHandler::m_runtype
std::string m_runtype
Definition: EcalTPGLutGroupHandler.h:88
Exception
Definition: hltDiff.cc:245
CaloGeometry.h
RunList::getRuns
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
RunTPGConfigDat::getConfigTag
std::string getConfigTag() const
Definition: RunTPGConfigDat.h:20
ParameterSetfwd.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dumpRecoGeometry_cfg.tagInfo
tagInfo
Definition: dumpRecoGeometry_cfg.py:194
popcon::EcalTPGLutGroupHandler::~EcalTPGLutGroupHandler
~EcalTPGLutGroupHandler() override
Definition: EcalTPGLutGroupHandler.cc:53
dataset
Definition: dataset.py:1
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
popcon::EcalTPGLutGroupHandler::m_locationsource
std::string m_locationsource
Definition: EcalTPGLutGroupHandler.h:85
IODConfig::setConfigTag
void setConfigTag(std::string x)
Definition: IODConfig.h:29
FEConfigLUTInfo::setId
void setId(int id)
Definition: FEConfigLUTInfo.h:24
popcon::EcalTPGLutGroupHandler::m_gentag
std::string m_gentag
Definition: EcalTPGLutGroupHandler.h:81
mps_splice.line
line
Definition: mps_splice.py:76
EBDetId::SMCRYSTALMODE
static const int SMCRYSTALMODE
Definition: EBDetId.h:159
popcon::EcalTPGLutGroupHandler::m_lastRun
unsigned int m_lastRun
Definition: EcalTPGLutGroupHandler.h:74
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
FEConfigMainInfo::getLUTId
int getLUTId() const
Definition: FEConfigMainInfo.h:40