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