CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
popcon::EcalTPGBadTTHandler Class Reference

#include <EcalTPGBadTTHandler.h>

Inheritance diagram for popcon::EcalTPGBadTTHandler:
popcon::PopConSourceHandler< EcalTPGTowerStatus >

Public Member Functions

 EcalTPGBadTTHandler (edm::ParameterSet const &)
 
void getNewObjects () override
 
std::string id () const override
 
std::map< std::string, int > makeTTEEDetId ()
 
void readFromFile (const char *inputFile)
 
void writeFile (const char *inputFile)
 
 ~EcalTPGBadTTHandler () override
 
- Public Member Functions inherited from popcon::PopConSourceHandler< EcalTPGTowerStatus >
void initialize (const cond::persistency::Session &dbSession, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry)
 
Ref lastPayload () const
 
cond::LogDBEntry_t const & logDBEntry () const
 
std::pair< Container const *, std::string const > operator() (const cond::persistency::Session &session, cond::TagInfo_t const &tagInfo, cond::LogDBEntry_t const &logDBEntry) const
 
 PopConSourceHandler ()
 
Container const & returnData ()
 
cond::TagInfo_t const & tagInfo () const
 
std::string const & userTextLog () const
 
virtual ~PopConSourceHandler ()
 

Public Attributes

EcalCondDBInterfaceeconn
 

Private Member Functions

std::string to_string (char value[])
 

Private Attributes

unsigned int m_firstRun
 
std::string m_gentag
 
int m_i_badTT
 
unsigned int m_i_run_number
 
std::string m_i_tag
 
int m_i_version
 
unsigned int m_lastRun
 
std::string m_location
 
std::string m_locationsource
 
std::string m_name
 
std::string m_pass
 
unsigned int m_runnr
 
std::string m_runtype
 
std::string m_sid
 
std::string m_user
 
std::map< std::string, int > mapDetEEId
 
const EcalTPGTowerStatusmytowerStat
 

Additional Inherited Members

- Public Types inherited from popcon::PopConSourceHandler< EcalTPGTowerStatus >
typedef std::map< Time_t, std::shared_ptr< EcalTPGTowerStatus > > Container
 
typedef std::unique_ptr< EcalTPGTowerStatusRef
 
typedef PopConSourceHandler< EcalTPGTowerStatusself
 
typedef cond::Time_t Time_t
 
typedef EcalTPGTowerStatus value_type
 
- Protected Member Functions inherited from popcon::PopConSourceHandler< EcalTPGTowerStatus >
cond::persistency::SessiondbSession () const
 
- Protected Attributes inherited from popcon::PopConSourceHandler< EcalTPGTowerStatus >
Container m_iovs
 
std::vector< std::pair< EcalTPGTowerStatus *, Time_t > > m_to_transfer
 
std::string m_userTextLog
 

Detailed Description

Definition at line 44 of file EcalTPGBadTTHandler.h.

Constructor & Destructor Documentation

◆ EcalTPGBadTTHandler()

popcon::EcalTPGBadTTHandler::EcalTPGBadTTHandler ( edm::ParameterSet const &  ps)

Definition at line 24 of file EcalTPGBadTTHandler.cc.

References edm::ParameterSet::getParameter(), m_firstRun, m_gentag, m_lastRun, m_location, m_locationsource, m_pass, m_runtype, m_sid, m_user, and AlCaHLTBitMon_QueryRunRegistry::string.

25  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalTPGBadTTHandler")) {
26  edm::LogInfo("EcalTPGBadTTHandler") << "EcalTPGTowerStatus Source handler constructor.";
27  m_firstRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("firstRun").c_str()));
28  m_lastRun = static_cast<unsigned int>(atoi(ps.getParameter<std::string>("lastRun").c_str()));
29  m_sid = ps.getParameter<std::string>("OnlineDBSID");
30  m_user = ps.getParameter<std::string>("OnlineDBUser");
31  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
32  m_locationsource = ps.getParameter<std::string>("LocationSource");
33  m_location = ps.getParameter<std::string>("Location");
34  m_gentag = ps.getParameter<std::string>("GenTag");
35  m_runtype = ps.getParameter<std::string>("RunType");
36 
37  edm::LogInfo("EcalTPGBadTTHandler") << m_sid << "/" << m_user << "/" << m_location << "/" << m_gentag;
38 }
Log< level::Info, false > LogInfo

◆ ~EcalTPGBadTTHandler()

popcon::EcalTPGBadTTHandler::~EcalTPGBadTTHandler ( )
override

Definition at line 40 of file EcalTPGBadTTHandler.cc.

40 {}

Member Function Documentation

◆ getNewObjects()

void popcon::EcalTPGBadTTHandler::getNewObjects ( )
overridevirtual

Implements popcon::PopConSourceHandler< EcalTPGTowerStatus >.

Definition at line 42 of file EcalTPGBadTTHandler.cc.

References gather_cfg::cout, writedatasetfile::dataset, MillePedeFileConverter_cfg::e, test_db_connect::econn, cppFunctionSkipper::exception, Exception, FEConfigMainInfo::getBttId(), RunTPGConfigDat::getConfigTag(), RunList::getRuns(), FEConfigBadTTDat::getStatus(), FEConfigBadTTDat::getTCCId(), FEConfigBadTTDat::getTTId(), RunTPGConfigDat::getVersion(), l1ctLayer2EG_cff::id, ecalpyutils::ism(), test_db_connect::my_locdef, test_db_connect::my_rundef, EgHLTOffHistBins_cfi::nr, EcalLogicID::NULLID, AlCaHLTBitMon_ParallelJobs::p, DetId::rawId(), IODConfig::setConfigTag(), RunTag::setGeneralTag(), FEConfigBadTTInfo::setId(), RunTag::setLocationDef(), RunTag::setRunTypeDef(), EcalTPGTowerStatus::setValue(), FEConfigMainInfo::setVersion(), EBDetId::SMCRYSTALMODE, str, AlCaHLTBitMon_QueryRunRegistry::string, and dumpRecoGeometry_cfg::tagInfo.

42  {
43  edm::LogInfo("EcalTPGBadTTHandler") << "Started GetNewObjects!!!";
44 
45  unsigned int max_since = 0;
46  max_since = static_cast<unsigned int>(tagInfo().lastInterval.since);
47  edm::LogInfo("EcalTPGBadTTHandler") << "max_since : " << max_since;
48  edm::LogInfo("EcalTPGBadTTHandler") << "retrieved last payload ";
49 
50  // here we retrieve all the runs after the last from online DB
51  edm::LogInfo("EcalTPGBadTTHandler") << "Retrieving run list from ONLINE DB ... ";
52 
53  edm::LogInfo("EcalTPGBadTTHandler") << "Making connection...";
55  edm::LogInfo("EcalTPGBadTTHandler") << "Done.";
56 
57  if (!econn) {
58  std::cout << " connection parameters " << m_sid << "/" << m_user << std::endl;
59  throw cms::Exception("OMDS not available");
60  }
61 
63  my_locdef.setLocation(m_location);
64 
66  my_rundef.setRunType(m_runtype);
67 
68  RunTag my_runtag;
69  my_runtag.setLocationDef(my_locdef);
70  my_runtag.setRunTypeDef(my_rundef);
71  my_runtag.setGeneralTag(m_gentag);
72 
73  readFromFile("last_tpg_badTT_settings.txt");
74 
75  unsigned int min_run;
76 
77  if (m_firstRun < m_i_run_number) {
78  min_run = m_i_run_number + 1;
79  } else {
80  min_run = m_firstRun;
81  }
82  if (min_run < max_since) {
83  min_run = max_since + 1; // we have to add 1 to the last transferred one
84  }
85 
86  std::cout << "m_i_run_number" << m_i_run_number << "m_firstRun " << m_firstRun << "max_since " << max_since
87  << std::endl;
88 
89  unsigned int max_run = m_lastRun;
90  edm::LogInfo("EcalTPGBadTTHandler") << "min_run= " << min_run << "max_run= " << max_run;
91 
92  RunList my_list;
93  // my_list=econn->fetchRunListByLocation(my_runtag, min_run, max_run, my_locdef);
94  my_list = econn->fetchGlobalRunListByLocation(my_runtag, min_run, max_run, my_locdef);
95 
96  std::vector<RunIOV> run_vec = my_list.getRuns();
97  size_t num_runs = run_vec.size();
98 
99  std::cout << "number of runs is : " << num_runs << std::endl;
100 
101  std::string str = "";
102 
103  unsigned int irun = 0;
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  // retrieve the data :
115  std::map<EcalLogicID, RunTPGConfigDat> dataset;
116  econn->fetchDataSet(&dataset, &run_vec[kr]);
117 
118  std::string the_config_tag = "";
119  int the_config_version = 0;
120 
121  std::map<EcalLogicID, RunTPGConfigDat>::const_iterator it;
122 
123  int nr = 0;
124  for (it = dataset.begin(); it != dataset.end(); it++) {
125  ++nr;
126  //EcalLogicID ecalid = it->first;
127 
128  RunTPGConfigDat dat = it->second;
129  the_config_tag = dat.getConfigTag();
130  the_config_version = dat.getVersion();
131  }
132 
133  // it is all the same for all SM... get the last one
134 
135  // here we should check if it is the same as previous run.
136 
137  if ((the_config_tag != m_i_tag || the_config_version != m_i_version) && nr > 0) {
138  std::cout << " run= " << irun << " tag " << the_config_tag << " version=" << the_config_version << std::endl;
139  std::cout << "the tag is different from last transferred run ... retrieving last config set from DB"
140  << std::endl;
141 
142  FEConfigMainInfo fe_main_info;
143  fe_main_info.setConfigTag(the_config_tag);
144  fe_main_info.setVersion(the_config_version);
145 
146  try {
147  econn->fetchConfigSet(&fe_main_info);
148 
149  // now get TPGTowerStatus
150  int badttId = fe_main_info.getBttId();
151 
152  if (badttId != m_i_badTT) {
153  FEConfigBadTTInfo fe_badTT_info;
154  fe_badTT_info.setId(badttId);
155 
156  econn->fetchConfigSet(&fe_badTT_info);
157 
158  std::vector<FEConfigBadTTDat> dataset_TpgBadTT;
159 
160  econn->fetchConfigDataSet(&dataset_TpgBadTT, &fe_badTT_info);
161 
162  EcalTPGTowerStatus* towerStatus = new EcalTPGTowerStatus;
163  typedef std::vector<FEConfigBadTTDat>::const_iterator CIfeped;
164  EcalLogicID ecid_xt;
165  FEConfigBadTTDat rd_badTT;
166 
167  // reset the map
168  // EB
169  for (int ism = 1; ism <= 36; ism++) {
170  for (int ito = 1; ito <= 68; ito++) {
171  int tow_eta = (ito - 1) / 4;
172  int tow_phi = ((ito - 1) - tow_eta * 4);
173  int axt = (tow_eta * 5) * 20 + tow_phi * 5 + 1;
175  const EcalTrigTowerDetId towid = id.tower();
176  int tower_status = 0;
177  towerStatus->setValue(towid.rawId(), tower_status);
178  }
179  }
180  //EE
181  for (size_t itower = 0; itower < my_TTEcalLogicId_EE.size(); itower++) {
182  int towid = my_TTEcalLogicId_EE[itower].getLogicID();
183  int tower_status = 0;
184  towerStatus->setValue(towid, tower_status);
185  }
186 
187  // now put at 1 those that are bad
188  int icells = 0;
189  for (CIfeped p = dataset_TpgBadTT.begin(); p != dataset_TpgBadTT.end(); p++) {
190  rd_badTT = *p;
191 
192  int tcc_num = rd_badTT.getTCCId();
193  int tt_num = rd_badTT.getTTId();
194 
195  std::cout << " tcc/tt" << tcc_num << "/" << tt_num << std::endl;
196 
197  if (tcc_num > 36 && tcc_num <= 72) {
198  // SM number
199  int smid = tcc_num - 54;
200  if (tcc_num < 55)
201  smid = tcc_num - 18;
202  // TT number
203  int towerid = tt_num;
204 
205  int tow_eta = (towerid - 1) / 4;
206  int tow_phi = ((towerid - 1) - tow_eta * 4);
207  int axt = (tow_eta * 5) * 20 + tow_phi * 5 + 1;
208 
209  EBDetId id(smid, axt, EBDetId::SMCRYSTALMODE);
210  const EcalTrigTowerDetId towid = id.tower();
211  towerStatus->setValue(towid.rawId(), rd_badTT.getStatus());
212 
213  ++icells;
214  } else {
215  // EE data
216 
217  // TCC number
218  int tccid = tcc_num;
219  // TT number
220  int towerid = tt_num;
221 
222  bool set_the_tower = false;
223  int towid;
224  for (size_t itower = 0; itower < my_TTEcalLogicId_EE.size(); itower++) {
225  if (!set_the_tower) {
226  if (my_TTEcalLogicId_EE[itower].getID1() == tccid &&
227  my_TTEcalLogicId_EE[itower].getID2() == towerid) {
228  towid = my_TTEcalLogicId_EE[itower].getLogicID();
229  set_the_tower = true;
230  break;
231  }
232  }
233  }
234 
235  if (set_the_tower) {
236  towerStatus->setValue(towid, rd_badTT.getStatus());
237 
238  } else {
239  std::cout << " these may be the additional towers TCC/TT " << tccid << "/" << towerid << std::endl;
240  }
241 
242  ++icells;
243  }
244  }
245 
246  edm::LogInfo("EcalTPGBadTTHandler") << "Finished badTT reading.";
247 
248  Time_t snc = (Time_t)irun;
249 
250  m_to_transfer.push_back(std::make_pair((EcalTPGTowerStatus*)towerStatus, snc));
251 
252  m_i_run_number = irun;
253  m_i_tag = the_config_tag;
254  m_i_version = the_config_version;
255  m_i_badTT = badttId;
256 
257  writeFile("last_tpg_badTT_settings.txt");
258 
259  } else {
260  m_i_run_number = irun;
261  m_i_tag = the_config_tag;
262  m_i_version = the_config_version;
263 
264  writeFile("last_tpg_badTT_settings.txt");
265 
266  // std::cout<< " even if the tag/version is not the same, the badTT id is the same -> no transfer needed "<< std::endl;
267  }
268 
269  }
270 
271  catch (std::exception& e) {
272  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
273  << std::endl;
274  std::cout << e.what() << std::endl;
275  m_i_run_number = irun;
276  }
277 
278  } else if (nr == 0) {
279  m_i_run_number = irun;
280  // std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
281  } else {
282  m_i_run_number = irun;
283  m_i_tag = the_config_tag;
284  m_i_version = the_config_version;
285 
286  writeFile("last_tpg_badTT_settings.txt");
287  }
288  }
289  }
290 
291  delete econn;
292 
293  edm::LogInfo("EcalTPGBadTTHandler") << "Ecal - > end of getNewObjects -----------";
294 }
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
std::vector< RunIOV > getRuns()
Definition: RunList.cc:25
int getStatus() const
RunList fetchGlobalRunListByLocation(const RunTag &tag, int min_run, int max_run, const LocationDef &locDef) noexcept(false)
Iov_t lastInterval
Definition: Types.h:73
Definition: RunTag.h:13
int getBttId() const
int getTTId() const
Time_t since
Definition: Types.h:53
int getVersion() const
void fetchConfigSet(ICONF *iconf) noexcept(false)
void setVersion(int id)
void fetchDataSet(std::map< EcalLogicID, DATT > *fillMap, IOVT *iov) noexcept(false)
std::vector< EcalLogicID > getEcalLogicIDSetOrdered(std::string name, int fromId1, int toId1, int fromId2=EcalLogicID::NULLID, int toId2=EcalLogicID::NULLID, int fromId3=EcalLogicID::NULLID, int toId3=EcalLogicID::NULLID, std::string mapsTo="", int orderedBy=EcalLogicID::NULLID) noexcept(false)
void writeFile(const char *inputFile)
std::vector< std::pair< EcalTPGTowerStatus *, Time_t > > m_to_transfer
int getTCCId() const
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
Log< level::Info, false > LogInfo
std::string id() const override
EcalCondDBInterface * econn
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
void readFromFile(const char *inputFile)
std::string getConfigTag() const
void setConfigTag(std::string x)
Definition: IODConfig.h:29
static const int NULLID
Definition: EcalLogicID.h:35
void setValue(const uint32_t &id, const uint16_t &val)
void fetchConfigDataSet(std::vector< DATT > *fillMap, ICONF *iconf) noexcept(false)
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
static const int SMCRYSTALMODE
Definition: EBDetId.h:159
#define str(s)
int ism(int ieta, int iphi)
Definition: EcalPyUtils.cc:49

◆ id()

std::string popcon::EcalTPGBadTTHandler::id ( ) const
inlineoverridevirtual

Implements popcon::PopConSourceHandler< EcalTPGTowerStatus >.

Definition at line 53 of file EcalTPGBadTTHandler.h.

References m_name.

53 { return m_name; }

◆ makeTTEEDetId()

std::map<std::string, int> popcon::EcalTPGBadTTHandler::makeTTEEDetId ( )

◆ readFromFile()

void popcon::EcalTPGBadTTHandler::readFromFile ( const char *  inputFile)

Definition at line 296 of file EcalTPGBadTTHandler.cc.

References makeListRunsInFiles::inputFile, mps_splice::line, str, and cond::impl::to_string().

296  {
297  //-------------------------------------------------------------
298 
299  m_i_tag = "";
300  m_i_version = 0;
301  m_i_run_number = 0;
302  m_i_badTT = 0;
303 
304  FILE* inpFile; // input file
305  inpFile = fopen(inputFile, "r");
306  if (!inpFile) {
307  edm::LogError("EcalTPGBadTTHandler") << "*** Can not open file: " << inputFile;
308  return;
309  }
310 
311  char line[256];
312 
313  std::ostringstream str;
314 
315  fgets(line, 255, inpFile);
317  str << "gen tag " << m_i_tag << std::endl; // should I use this?
318 
319  fgets(line, 255, inpFile);
320  m_i_version = atoi(line);
321  str << "version= " << m_i_version << std::endl;
322 
323  fgets(line, 255, inpFile);
324  m_i_run_number = atoi(line);
325  str << "run_number= " << m_i_run_number << std::endl;
326 
327  fgets(line, 255, inpFile);
328  m_i_badTT = atoi(line);
329  str << "badTT_config= " << m_i_badTT << std::endl;
330 
331  fclose(inpFile); // close inp. file
332 }
Log< level::Error, false > LogError
std::string to_string(char value[])
#define str(s)

◆ to_string()

std::string popcon::EcalTPGBadTTHandler::to_string ( char  value[])
inlineprivate

Definition at line 61 of file EcalTPGBadTTHandler.h.

References relativeConstraints::value.

61  {
62  std::ostringstream streamOut;
63  streamOut << value;
64  return streamOut.str();
65  }

◆ writeFile()

void popcon::EcalTPGBadTTHandler::writeFile ( const char *  inputFile)

Definition at line 334 of file EcalTPGBadTTHandler.cc.

References makeListRunsInFiles::inputFile.

334  {
335  //-------------------------------------------------------------
336 
337  std::ofstream myfile;
338  myfile.open(inputFile);
339  myfile << m_i_tag << std::endl;
340  myfile << m_i_version << std::endl;
341  myfile << m_i_run_number << std::endl;
342  myfile << m_i_badTT << std::endl;
343 
344  myfile.close();
345 }

Member Data Documentation

◆ econn

EcalCondDBInterface* popcon::EcalTPGBadTTHandler::econn

Definition at line 58 of file EcalTPGBadTTHandler.h.

◆ m_firstRun

unsigned int popcon::EcalTPGBadTTHandler::m_firstRun
private

Definition at line 69 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_gentag

std::string popcon::EcalTPGBadTTHandler::m_gentag
private

Definition at line 74 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_i_badTT

int popcon::EcalTPGBadTTHandler::m_i_badTT
private

Definition at line 85 of file EcalTPGBadTTHandler.h.

◆ m_i_run_number

unsigned int popcon::EcalTPGBadTTHandler::m_i_run_number
private

Definition at line 84 of file EcalTPGBadTTHandler.h.

◆ m_i_tag

std::string popcon::EcalTPGBadTTHandler::m_i_tag
private

Definition at line 82 of file EcalTPGBadTTHandler.h.

◆ m_i_version

int popcon::EcalTPGBadTTHandler::m_i_version
private

Definition at line 83 of file EcalTPGBadTTHandler.h.

◆ m_lastRun

unsigned int popcon::EcalTPGBadTTHandler::m_lastRun
private

Definition at line 70 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_location

std::string popcon::EcalTPGBadTTHandler::m_location
private

Definition at line 73 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_locationsource

std::string popcon::EcalTPGBadTTHandler::m_locationsource
private

Definition at line 78 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_name

std::string popcon::EcalTPGBadTTHandler::m_name
private

Definition at line 79 of file EcalTPGBadTTHandler.h.

Referenced by id().

◆ m_pass

std::string popcon::EcalTPGBadTTHandler::m_pass
private

Definition at line 77 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_runnr

unsigned int popcon::EcalTPGBadTTHandler::m_runnr
private

Definition at line 80 of file EcalTPGBadTTHandler.h.

◆ m_runtype

std::string popcon::EcalTPGBadTTHandler::m_runtype
private

Definition at line 81 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_sid

std::string popcon::EcalTPGBadTTHandler::m_sid
private

Definition at line 75 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ m_user

std::string popcon::EcalTPGBadTTHandler::m_user
private

Definition at line 76 of file EcalTPGBadTTHandler.h.

Referenced by EcalTPGBadTTHandler().

◆ mapDetEEId

std::map<std::string, int> popcon::EcalTPGBadTTHandler::mapDetEEId
private

Definition at line 71 of file EcalTPGBadTTHandler.h.

◆ mytowerStat

const EcalTPGTowerStatus* popcon::EcalTPGBadTTHandler::mytowerStat
private

Definition at line 67 of file EcalTPGBadTTHandler.h.