CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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(0));
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 zdcSection = "UNKNOWN";
172  return zdcSection;
173 }
174 
175 
177  if ( _section.find("ZDC EM") != std::string::npos ) return HcalZDCDetId::EM;
178  else if ( _section.find("ZDC HAD") != std::string::npos ) return HcalZDCDetId::HAD;
179  else if ( _section.find("ZDC LUM") != std::string::npos ) return HcalZDCDetId::LUM;
180  else return HcalZDCDetId::Unknown;
181 }
182 
183 
184 
186  int _n_channels = 0;
187  static ConnectionManager conn;
188  conn.connect();
189  std::string query = "select ";
190  query += " channel_map_id,subdet,ieta,iphi,depth ";
191  query += "from ";
192  query += " cms_hcl_hcal_cond.hcal_channels ";
193  query += "where ";
194  query += " subdet='HB' or subdet='HE' or subdet='HF' or subdet='HO' ";
195  try {
196  oracle::occi::Statement* stmt = conn.getStatement(query);
197  oracle::occi::ResultSet *rs = stmt->executeQuery();
198  geom_to_rawid.clear();
199  rawid_to_geom.clear();
200  while (rs->next()) {
201  _n_channels++;
202  int _rawid = rs->getInt(1);
203  int _geomId = getGeomId( getSubdetector(rs->getString(2)),
204  rs->getInt(3),
205  rs->getInt(4),
206  rs->getInt(5)
207  );
208  geom_to_rawid.insert(std::pair<int, int>(_geomId, _rawid));
209  rawid_to_geom.insert(std::pair<int, int>(_rawid, _geomId));
210  }
211  listIsRead = true;
212  }
213  catch (SQLException& e) {
214  std::cerr << ::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()) << std::endl;
215  XCEPT_RAISE(hcal::exception::ConfigurationDatabaseException,::toolbox::toString("Oracle exception : %s",e.getMessage().c_str()));
216  }
217  conn.disconnect();
218  return _n_channels;
219 }
220 
221 
222 int HcalAssistant::getGeomId(int _rawid){
223  if (listIsRead){
224  std::map<int,int>::const_iterator _geomId = rawid_to_geom.find(_rawid);
225  if (_geomId!=rawid_to_geom.end()){
226  return _geomId->second;
227  }
228  else return -1;
229  }
230  else return -1;
231 }
232 
233 
234 
235 int HcalAssistant::getRawId(int _geomId){
236  if (listIsRead){
237  std::map<int,int>::const_iterator _rawid = geom_to_rawid.find(_geomId);
238  if (_rawid!=geom_to_rawid.end()){
239  return _rawid->second;
240  }
241  else return -1;
242  }
243  else return -1;
244 }
245 
246 
248  std::string s_det = getSubdetectorString(_geomId);
249  if ( s_det.find("HB") != std::string::npos ||
250  s_det.find("HE") != std::string::npos ||
251  s_det.find("HF") != std::string::npos ||
252  s_det.find("HO") != std::string::npos ||
253  s_det.find("HT") != std::string::npos )
254  {
255  HcalDetId _id( getSubdetector(s_det),
256  getHcalIeta(_geomId),
257  getHcalIphi(_geomId),
258  getHcalDepth(_geomId)
259  );
260  return _id.rawId();
261  }
262  else if ( s_det.find("ZDC") != std::string::npos )
263  {
264  // FIXME: implement for ZDC channels
265  return -1;
266  }
267  else{
268  return -1;
269  }
270 }
271 
272 
274  return getHcalSubdetector( getGeomId(_rawid) );
275 }
276 
277 
278 int HcalAssistant::getIeta(int _rawid){
279  return getHcalIeta( getGeomId(_rawid) );
280 }
281 
282 
283 
284 int HcalAssistant::getIphi(int _rawid){
285  return getHcalIphi( getGeomId(_rawid) );
286 }
287 
288 
289 
290 int HcalAssistant::getDepth(int _rawid){
291  return getHcalDepth( getGeomId(_rawid) );
292 }
293 
294 
295 
296 int HcalAssistant::getRawId(HcalSubdetector _det, int _ieta, int _iphi, int _depth){
297  return getRawId( getGeomId(_det, _ieta, _iphi, _depth) );
298 }
299 
300 
301 
302 
303 int HcalAssistant::a_to_i(char * inbuf){
304  int result;
305  sscanf(inbuf,"%d",&result);
306  return result;
307 }
std::string getSubdetectorString(HcalSubdetector _det)
HcalSubdetector getHcalSubdetector(int _geomId)
virtual ~HcalAssistant()
int getHcalDepth(int _geomId)
std::string getRandomQuote(void)
std::string getZDCSectionString(HcalZDCDetId::Section _section)
#define _depth
Definition: Pythia6jets.h:5
oracle::occi::Statement * getStatement(const std::string &query)
int getRawIdFromCmssw(int _geomId)
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
int a_to_i(char *inbuf)
int getRawId(HcalSubdetector _det, int _ieta, int _iphi, int _depth)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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
tuple result
Definition: query.py:137
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)
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
int getDepth(int _rawid)
int getListOfChannelsFromDb()
Signal rand(Signal arg)
Definition: vlib.cc:442
tuple query
Definition: o2o.py:269
int getHcalIphi(int _geomId)
tuple conn
Definition: results_mgr.py:53
int getIeta(int _rawid)
std::string getUserName(void)