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