CMS 3D CMS Logo

HcalAssistant.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalOnlineDb
4 // Class : HcalAssistant
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Gena Kukartsev, kukarzev@fnal.gov
10 // Created: Thu Jul 16 11:39:22 CEST 2009
11 //
12 
13 #include <ctime>
14 #include <unistd.h>
15 #include <sys/types.h>
16 #include <pwd.h>
19 #include "CaloOnlineTools/HcalOnlineDb/interface/ConfigurationDatabaseException.hh"
22 
23 #ifdef HAVE_XDAQ
24 #include <toolbox/string.h>
25 #else
26 #include "CaloOnlineTools/HcalOnlineDb/interface/xdaq_compat.h" // Includes typedef for log4cplus::Logger
27 #endif
28 
29 using namespace std;
30 using namespace oracle::occi;
31 
33  addQuotes();
34  srand(time(nullptr));
35  listIsRead = false;
36 }
37 
39 
41  quotes.push_back("Fear is the path to the Dark Side...");
42  quotes.push_back("You don't know the power of the Dark Side...");
43  quotes.push_back("You must learn the ways of the Force!");
44  quotes.push_back("Where's the money, Lebowski?!");
45  quotes.push_back("You see what happens when you find a stranger in the Alps!!!?");
46  quotes.push_back(
47  "You hear this? This is the sound of inevitability. This is the sound of your death. Goodbye, mr. Anderson");
48  quotes.push_back("Welcome to the desert of the Real");
49  quotes.push_back("In Tyler we trust");
50  quotes.push_back("How about a little snack?..Let's have a snack now, we can get friendly later");
51  quotes.push_back("Is he human? Hey, no need for name calling!");
52  quotes.push_back("Frankly, my dear, I don't give a damn");
53  quotes.push_back("I've a feeling we're not in Kansas anymore");
54  quotes.push_back("What we've got here is failure to communicate");
55  quotes.push_back("I love the smell of napalm in the morning!");
56  quotes.push_back("I see stupid people");
57  quotes.push_back("Stella! Hey, Stella!");
58  quotes.push_back("Houston, we have a problem");
59  quotes.push_back("Mrs. Robinson, you're trying to seduce me. Aren't you?");
60  quotes.push_back("I feel the need - the need for speed!");
61  quotes.push_back("He's got emotional problems. What, beyond pacifism?");
62  return quotes.size();
63 }
64 
66  int _quotes_array_size = quotes.size();
67  int _num = rand() % _quotes_array_size;
68  return quotes[_num];
69 }
70 
72  struct passwd* _pwd = getpwuid(geteuid());
73  std::string _name(_pwd->pw_name);
74  return _name;
75 }
76 
77 int HcalAssistant::getGeomId(HcalSubdetector _det, int _ieta, int _iphi, int _depth) {
78  int _geomId = _det + 10 * _depth + 100 * _iphi + 10000 * abs(_ieta);
79  if (_ieta < 0) {
80  _geomId = -_geomId;
81  }
82  return _geomId;
83 }
84 
85 int HcalAssistant::getHcalIeta(int _geomId) {
86  int _ieta = _geomId / 10000;
87  return _ieta;
88 }
89 
90 int HcalAssistant::getHcalIphi(int _geomId) {
91  int _iphi = abs(_geomId % 10000) / 100;
92  return _iphi;
93 }
94 
95 int HcalAssistant::getHcalDepth(int _geomId) {
96  int _depth = abs(_geomId % 100) / 10;
97  return _depth;
98 }
99 
101  int _det = abs(_geomId) % 10;
102  if (_det == 1)
103  return HcalBarrel;
104  else if (_det == 2)
105  return HcalEndcap;
106  else if (_det == 3)
107  return HcalOuter;
108  else if (_det == 4)
109  return HcalForward;
110  else if (_det == 5)
111  return HcalTriggerTower;
112  else if (_det == 0)
113  return HcalEmpty;
114  else
115  return HcalOther;
116 }
117 
119  int _det = abs(_geomId) % 10;
120  std::string s_det = "";
121  if (_det == 1)
122  s_det = "HB";
123  else if (_det == 2)
124  s_det = "HE";
125  else if (_det == 3)
126  s_det = "HO";
127  else if (_det == 4)
128  s_det = "HF";
129  else if (_det == 5)
130  s_det = "HT";
131  else if (_det == 6)
132  s_det = "ZDC";
133  else if (_det == 0)
134  s_det = "Empty";
135  else
136  s_det = "Other";
137  return s_det;
138 }
139 
141  if (_det.find("HB") != std::string::npos)
142  return HcalBarrel;
143  else if (_det.find("HE") != std::string::npos)
144  return HcalEndcap;
145  else if (_det.find("HF") != std::string::npos)
146  return HcalForward;
147  else if (_det.find("HO") != std::string::npos)
148  return HcalOuter;
149  else if (_det.find("HT") != std::string::npos)
150  return HcalTriggerTower;
151  else
152  return HcalOther;
153 }
154 
156  std::string sDet;
157  if (_det == HcalBarrel)
158  sDet = "HB";
159  else if (_det == HcalEndcap)
160  sDet = "HE";
161  else if (_det == HcalForward)
162  sDet = "HF";
163  else if (_det == HcalOuter)
164  sDet = "HO";
165  else if (_det == HcalTriggerTower)
166  sDet = "HT";
167  else
168  sDet = "other";
169  return sDet;
170 }
171 
173  std::string zdcSection;
174  if (_section == HcalZDCDetId::EM)
175  zdcSection = "ZDC EM";
176  else if (_section == HcalZDCDetId::HAD)
177  zdcSection = "ZDC HAD";
178  else if (_section == HcalZDCDetId::LUM)
179  zdcSection = "ZDC LUM";
180  else if (_section == HcalZDCDetId::RPD)
181  zdcSection = "ZDC RPD";
182  else
183  zdcSection = "UNKNOWN";
184  return zdcSection;
185 }
186 
188  if (_section.find("ZDC EM") != std::string::npos)
189  return HcalZDCDetId::EM;
190  else if (_section.find("ZDC HAD") != std::string::npos)
191  return HcalZDCDetId::HAD;
192  else if (_section.find("ZDC LUM") != std::string::npos)
193  return HcalZDCDetId::LUM;
194  else if (_section.find("ZDC RPD") != std::string::npos)
195  return HcalZDCDetId::RPD;
196  else
197  return HcalZDCDetId::Unknown;
198 }
199 
201  int _n_channels = 0;
202  static ConnectionManager conn;
203  conn.connect();
204  std::string query = "select ";
205  query += " channel_map_id,subdet,ieta,iphi,depth ";
206  query += "from ";
207  query += " cms_hcl_hcal_cond.hcal_channels ";
208  query += "where ";
209  query += " subdet='HB' or subdet='HE' or subdet='HF' or subdet='HO' ";
210  try {
211  oracle::occi::Statement* stmt = conn.getStatement(query);
212  oracle::occi::ResultSet* rs = stmt->executeQuery();
213  geom_to_rawid.clear();
214  rawid_to_geom.clear();
215  while (rs->next()) {
216  _n_channels++;
217  int _rawid = rs->getInt(1);
218  int _geomId = getGeomId(getSubdetector(rs->getString(2)), rs->getInt(3), rs->getInt(4), rs->getInt(5));
219  geom_to_rawid.insert(std::pair<int, int>(_geomId, _rawid));
220  rawid_to_geom.insert(std::pair<int, int>(_rawid, _geomId));
221  }
222  listIsRead = true;
223  } catch (SQLException& e) {
224  std::cerr << ::toolbox::toString("Oracle exception : %s", e.getMessage().c_str()) << std::endl;
225  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,
226  ::toolbox::toString("Oracle exception : %s", e.getMessage().c_str()));
227  }
228  conn.disconnect();
229  return _n_channels;
230 }
231 
232 int HcalAssistant::getGeomId(int _rawid) {
233  if (listIsRead) {
234  std::map<int, int>::const_iterator _geomId = rawid_to_geom.find(_rawid);
235  if (_geomId != rawid_to_geom.end()) {
236  return _geomId->second;
237  } else
238  return -1;
239  } else
240  return -1;
241 }
242 
243 int HcalAssistant::getRawId(int _geomId) {
244  if (listIsRead) {
245  std::map<int, int>::const_iterator _rawid = geom_to_rawid.find(_geomId);
246  if (_rawid != geom_to_rawid.end()) {
247  return _rawid->second;
248  } else
249  return -1;
250  } else
251  return -1;
252 }
253 
255  std::string s_det = getSubdetectorString(_geomId);
256  if (s_det.find("HB") != std::string::npos || s_det.find("HE") != std::string::npos ||
257  s_det.find("HF") != std::string::npos || s_det.find("HO") != std::string::npos ||
258  s_det.find("HT") != std::string::npos) {
259  HcalDetId _id(getSubdetector(s_det), getHcalIeta(_geomId), getHcalIphi(_geomId), getHcalDepth(_geomId));
260  return _id.rawId();
261  } else if (s_det.find("ZDC") != std::string::npos) {
262  // FIXME: implement for ZDC channels
263  return -1;
264  } else {
265  return -1;
266  }
267 }
268 
269 int HcalAssistant::getSubdetector(int _rawid) { return getHcalSubdetector(getGeomId(_rawid)); }
270 
271 int HcalAssistant::getIeta(int _rawid) { return getHcalIeta(getGeomId(_rawid)); }
272 
273 int HcalAssistant::getIphi(int _rawid) { return getHcalIphi(getGeomId(_rawid)); }
274 
275 int HcalAssistant::getDepth(int _rawid) { return getHcalDepth(getGeomId(_rawid)); }
276 
277 int HcalAssistant::getRawId(HcalSubdetector _det, int _ieta, int _iphi, int _depth) {
278  return getRawId(getGeomId(_det, _ieta, _iphi, _depth));
279 }
280 
281 int HcalAssistant::a_to_i(char* inbuf) {
282  int result;
283  sscanf(inbuf, "%d", &result);
284  return result;
285 }
HcalOther
Definition: HcalAssistant.h:38
HcalAssistant::getHcalDepth
int getHcalDepth(int _geomId)
Definition: HcalAssistant.cc:95
HcalAssistant::getRawId
int getRawId(HcalSubdetector _det, int _ieta, int _iphi, int _depth)
Definition: HcalAssistant.cc:277
HcalZDCDetId::HAD
Definition: HcalZDCDetId.h:23
HcalAssistant::getListOfChannelsFromDb
int getListOfChannelsFromDb()
Definition: HcalAssistant.cc:200
HcalZDCDetId::Section
Section
Definition: HcalZDCDetId.h:23
HcalAssistant::getUserName
std::string getUserName(void)
Definition: HcalAssistant.cc:71
HcalAssistant::getIphi
int getIphi(int _rawid)
Definition: HcalAssistant.cc:273
HcalAssistant::getZDCSectionString
std::string getZDCSectionString(HcalZDCDetId::Section _section)
Definition: HcalAssistant.cc:172
SiStripCommissioningClient_cfg.conn
conn
Definition: SiStripCommissioningClient_cfg.py:5
protons_cff.time
time
Definition: protons_cff.py:39
HcalAssistant::getRawIdFromCmssw
int getRawIdFromCmssw(int _geomId)
Definition: HcalAssistant.cc:254
HcalBarrel
Definition: HcalAssistant.h:33
HcalEmpty
Definition: HcalAssistant.h:32
HcalAssistant::getHcalIphi
int getHcalIphi(int _geomId)
Definition: HcalAssistant.cc:90
HcalAssistant::getDepth
int getDepth(int _rawid)
Definition: HcalAssistant.cc:275
HcalAssistant::addQuotes
int addQuotes()
Definition: HcalAssistant.cc:40
HcalAssistant::getGeomId
int getGeomId(HcalSubdetector _det, int _ieta, int _iphi, int _depth)
Definition: HcalAssistant.cc:77
HcalAssistant::getHcalSubdetector
HcalSubdetector getHcalSubdetector(int _geomId)
Definition: HcalAssistant.cc:100
toolbox::toString
std::string toString(const char *format,...)
Definition: xdaq_compat.cc:4
HcalAssistant.h
query
Definition: query.py:1
oracle::occi
Definition: ConnectionManager.h:7
HcalAssistant::getZDCSection
HcalZDCDetId::Section getZDCSection(std::string _section)
Definition: HcalAssistant.cc:187
HcalOuter
Definition: HcalAssistant.h:35
HcalAssistant::a_to_i
int a_to_i(char *inbuf)
Definition: HcalAssistant.cc:281
xdaq_compat.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalAssistant::getRandomQuote
std::string getRandomQuote(void)
Definition: HcalAssistant.cc:65
HcalAssistant::getIeta
int getIeta(int _rawid)
Definition: HcalAssistant.cc:271
HcalZDCDetId::RPD
Definition: HcalZDCDetId.h:23
HcalDetId.h
HcalAssistant::~HcalAssistant
virtual ~HcalAssistant()
Definition: HcalAssistant.cc:38
HcalZDCDetId::Unknown
Definition: HcalZDCDetId.h:23
HcalAssistant::getSubdetector
HcalSubdetector getSubdetector(std::string _det)
Definition: HcalAssistant.cc:140
HcalDetId
Definition: HcalDetId.h:12
ConnectionManager
Definition: ConnectionManager.h:14
HcalSubdetector
HcalSubdetector
Definition: HcalAssistant.h:31
HcalAssistant::getSubdetectorString
std::string getSubdetectorString(HcalSubdetector _det)
Definition: HcalAssistant.cc:155
HcalForward
Definition: HcalAssistant.h:36
std
Definition: JetResolutionObject.h:76
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalEndcap
Definition: HcalAssistant.h:34
HcalTriggerTower
Definition: HcalAssistant.h:37
HcalAssistant::HcalAssistant
HcalAssistant()
Definition: HcalAssistant.cc:32
HcalZDCDetId::LUM
Definition: HcalZDCDetId.h:23
Oracle.h
mps_fire.result
result
Definition: mps_fire.py:311
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ConnectionManager.h
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
HcalZDCDetId::EM
Definition: HcalZDCDetId.h:23
HcalAssistant::getHcalIeta
int getHcalIeta(int _geomId)
Definition: HcalAssistant.cc:85
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37