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(), EcalPhiSymFlatTableProducers_cfi::id, ecalpyutils::ism(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, 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  for (CIfeped p = dataset_TpgBadTT.begin(); p != dataset_TpgBadTT.end(); p++) {
189  rd_badTT = *p;
190 
191  int tcc_num = rd_badTT.getTCCId();
192  int tt_num = rd_badTT.getTTId();
193 
194  std::cout << " tcc/tt" << tcc_num << "/" << tt_num << std::endl;
195 
196  if (tcc_num > 36 && tcc_num <= 72) {
197  // SM number
198  int smid = tcc_num - 54;
199  if (tcc_num < 55)
200  smid = tcc_num - 18;
201  // TT number
202  int towerid = tt_num;
203 
204  int tow_eta = (towerid - 1) / 4;
205  int tow_phi = ((towerid - 1) - tow_eta * 4);
206  int axt = (tow_eta * 5) * 20 + tow_phi * 5 + 1;
207 
208  EBDetId id(smid, axt, EBDetId::SMCRYSTALMODE);
209  const EcalTrigTowerDetId towid = id.tower();
210  towerStatus->setValue(towid.rawId(), rd_badTT.getStatus());
211 
212  } else {
213  // EE data
214 
215  // TCC number
216  int tccid = tcc_num;
217  // TT number
218  int towerid = tt_num;
219 
220  bool set_the_tower = false;
221  int towid;
222  for (size_t itower = 0; itower < my_TTEcalLogicId_EE.size(); itower++) {
223  if (!set_the_tower) {
224  if (my_TTEcalLogicId_EE[itower].getID1() == tccid &&
225  my_TTEcalLogicId_EE[itower].getID2() == towerid) {
226  towid = my_TTEcalLogicId_EE[itower].getLogicID();
227  set_the_tower = true;
228  break;
229  }
230  }
231  }
232 
233  if (set_the_tower) {
234  towerStatus->setValue(towid, rd_badTT.getStatus());
235 
236  } else {
237  std::cout << " these may be the additional towers TCC/TT " << tccid << "/" << towerid << std::endl;
238  }
239  }
240  }
241 
242  edm::LogInfo("EcalTPGBadTTHandler") << "Finished badTT reading.";
243 
244  Time_t snc = (Time_t)irun;
245 
246  m_to_transfer.push_back(std::make_pair((EcalTPGTowerStatus*)towerStatus, snc));
247 
248  m_i_run_number = irun;
249  m_i_tag = the_config_tag;
250  m_i_version = the_config_version;
251  m_i_badTT = badttId;
252 
253  writeFile("last_tpg_badTT_settings.txt");
254 
255  } else {
256  m_i_run_number = irun;
257  m_i_tag = the_config_tag;
258  m_i_version = the_config_version;
259 
260  writeFile("last_tpg_badTT_settings.txt");
261 
262  // std::cout<< " even if the tag/version is not the same, the badTT id is the same -> no transfer needed "<< std::endl;
263  }
264 
265  }
266 
267  catch (std::exception& e) {
268  std::cout << "ERROR: THIS CONFIG DOES NOT EXIST: tag=" << the_config_tag << " version=" << the_config_version
269  << std::endl;
270  std::cout << e.what() << std::endl;
271  m_i_run_number = irun;
272  }
273 
274  } else if (nr == 0) {
275  m_i_run_number = irun;
276  // std::cout<< " no tag saved to RUN_TPGCONFIG_DAT by EcalSupervisor -> no transfer needed "<< std::endl;
277  } else {
278  m_i_run_number = irun;
279  m_i_tag = the_config_tag;
280  m_i_version = the_config_version;
281 
282  writeFile("last_tpg_badTT_settings.txt");
283  }
284  }
285  }
286 
287  delete econn;
288 
289  edm::LogInfo("EcalTPGBadTTHandler") << "Ecal - > end of getNewObjects -----------";
290 }
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 292 of file EcalTPGBadTTHandler.cc.

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

292  {
293  //-------------------------------------------------------------
294 
295  m_i_tag = "";
296  m_i_version = 0;
297  m_i_run_number = 0;
298  m_i_badTT = 0;
299 
300  FILE* inpFile; // input file
301  inpFile = fopen(inputFile, "r");
302  if (!inpFile) {
303  edm::LogError("EcalTPGBadTTHandler") << "*** Can not open file: " << inputFile;
304  return;
305  }
306 
307  char line[256];
308 
309  std::ostringstream str;
310 
311  fgets(line, 255, inpFile);
313  str << "gen tag " << m_i_tag << std::endl; // should I use this?
314 
315  fgets(line, 255, inpFile);
316  m_i_version = atoi(line);
317  str << "version= " << m_i_version << std::endl;
318 
319  fgets(line, 255, inpFile);
320  m_i_run_number = atoi(line);
321  str << "run_number= " << m_i_run_number << std::endl;
322 
323  fgets(line, 255, inpFile);
324  m_i_badTT = atoi(line);
325  str << "badTT_config= " << m_i_badTT << std::endl;
326 
327  fclose(inpFile); // close inp. file
328 }
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 330 of file EcalTPGBadTTHandler.cc.

References makeListRunsInFiles::inputFile.

330  {
331  //-------------------------------------------------------------
332 
333  std::ofstream myfile;
334  myfile.open(inputFile);
335  myfile << m_i_tag << std::endl;
336  myfile << m_i_version << std::endl;
337  myfile << m_i_run_number << std::endl;
338  myfile << m_i_badTT << std::endl;
339 
340  myfile.close();
341 }

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.