StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtDb.h
1 /* StFgtDb.h
2  *
3  * FGT database table observer for real database interactions.
4  *
5  * \author W. Witzke (wowitz0@uky.edu)
6  *
7  */
8 
9 #ifndef _ST_FGT_DB_H_
10 #define _ST_FGT_DB_H_
11 
12 #include <cstdlib>
13 #include "tables/St_fgtElosCutoff_Table.h"
14 #include "tables/St_fgtSimuParams_Table.h"
15 #include "tables/St_fgtPedestal_Table.h"
16 #include "tables/St_fgtMapping_Table.h"
17 #include "tables/St_fgtGain_Table.h"
18 #include "tables/St_fgtStatus_Table.h"
19 #include "tables/St_fgtAlignment_Table.h"
20 #include "StFgtUtil/geometry/StFgtGeom.h"
21 
22 class StFgtDb
23 {
24  public:
25  // The following three functions should not normally be called
26  // directly by users. They are for use by the factory methods defined
27  // in the class being observed by this DB interface implementation.
28 
29  StFgtDb(
30  ) : m_map(NULL), m_rmap(NULL), m_status(NULL), m_pedestal(NULL), m_gain(NULL), m_alignment(NULL)
31  { }
32 
33  StFgtDb(
34  fgtMapping_st * map,
35  fgtMapping_st * rmap,
36  fgtStatus_st * status,
37  fgtPedestal_st * pedestal,
38  fgtGain_st * gain,
39  fgtAlignment_st * alignment
40  ) : m_map(map), m_rmap(rmap), m_status(status),
41  m_pedestal(pedestal), m_gain(gain), m_alignment(alignment)
42  { }
43 
44  virtual void updateTables(
45  fgtMapping_st * map,
46  fgtMapping_st * rmap,
47  fgtStatus_st * status,
48  fgtPedestal_st * pedestal,
49  fgtGain_st * gain,
50  fgtElosCutoff_st* mLossTab,
51  fgtSimuParams_st* mSimuParTab,
52  fgtAlignment_st* alignment
53  )
54  {
55  m_map = map;
56  m_rmap = rmap;
57  m_status = status;
58  m_pedestal = pedestal;
59  m_gain = gain;
60  m_eLoss=mLossTab;
61  m_simPar= mSimuParTab;
62  m_alignment = alignment;
63  }
64 
65  //----------------------------------------------------------
66  // User functions start here.
67 
68 
69  // The ordinate, lowerSpan and upperSpan are all in centimeters or
70  // radians, depending on the layer.
71  virtual Int_t getPhysicalCoordinateFromGeoId(
72  Int_t geoId,
73  Short_t & disc, Short_t & quadrant, Char_t & layer,
74  Double_t & ordinate, Double_t & lowerSpan, Double_t & upperSpan
75  );
76 
77  // The ordinate, lowerSpan and upperSpan are all in centimeters or
78  // radians, depending on the layer.
79  virtual Int_t getPhysicalCoordinateFromGeoName(
80  const std::string & geoName,
81  Short_t & disc, Short_t & quadrant, Char_t & layer,
82  Double_t & ordinate, Double_t & lowerSpan, Double_t & upperSpan
83  );
84 
85 
86  //geoId is a unique number used to identify a specific strip
87  //on a specific disk/quadrant/layer/strip. Please NOTE:
88  //The set of geoIds IS NOT CONTINUOUS simply becuase strip
89  //number is not continuous. On the R plane strips 280-399
90  //are not implemented.
91 
92 
93  virtual Int_t getGeoIdFromElecCoord(
94  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
95  )
96  {
97  Int_t eId = StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
98 
99  if ( eId < 0 )
100  return kFgtError;
101 
102  return m_map->Mapping[ eId ];
103  }
104 
105 
106  virtual Int_t getElecCoordFromGeoId(
107  Int_t geoId, Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& channel
108  );
109 
110  virtual std::string getGeoNameFromElecCoord(
111  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
112  )
113  {
114  Int_t geoId = getGeoIdFromElecCoord( rdo, arm, apv, channel );
115 
116  if ( geoId < 0 )
117  return kFgtErrorString;
118 
119  return StFgtGeom::translateGeoIdToGeoName( geoId );
120  }
121 
122 
123  virtual Int_t getElecCoordFromGeoName(
124  const std::string & geoName,
125  Int_t& rdo, Int_t& arm, Int_t& apv, Int_t& channel
126  );
127 
128  virtual Int_t getPhysCoordFromElecCoord(
129  Int_t rdo, Int_t arm, Int_t apv, Int_t channel,
130  Short_t & disc, Short_t & quadrant, Char_t & layer,
131  Double_t & ordinate, Double_t & lowerSpan, Double_t & upperSpan
132  )
133  {
134  return StFgtGeom::getPhysicalCoordinate(
135  getGeoIdFromElecCoord( rdo, arm, apv, channel ),
136  disc, quadrant, layer, ordinate, lowerSpan, upperSpan
137  );
138  }
139 
140  virtual Double_t getPedestalFromGeoId( Int_t geoId );
141 
142  virtual Double_t getPedestalFromElecId( Int_t elecId);
143 
144  virtual Double_t getPedestalFromGeoName( const std::string & geoName )
145  {
146  Int_t geoId = StFgtGeom::translateGeoNameToGeoId( geoName );
147 
148  if ( geoId < 0 )
149  return kFgtError;
150 
151  return getPedestalFromGeoId( geoId );
152  }
153 
154  virtual Double_t getPedestalFromElecCoord(
155  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
156  )
157  {
158  Int_t eId =
159  StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
160 
161  if ( eId < 0 )
162  return kFgtError;
163 
164  return m_pedestal->AdcPedestal[ eId ];
165  }
166 
167  virtual Double_t getPedestalSigmaFromGeoId( Int_t geoId );
168 
169  virtual Double_t getPedestalSigmaFromElecId( Int_t elecId );
170 
171  virtual Double_t getPedestalSigmaFromGeoName(
172  const std::string & geoName
173  )
174  {
175  Int_t geoId = StFgtGeom::translateGeoNameToGeoId( geoName );
176 
177  if ( geoId < 0 )
178  return kFgtError;
179 
180  return getPedestalSigmaFromGeoId( geoId );
181  }
182 
183  virtual Double_t getPedestalSigmaFromElecCoord(
184  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
185  )
186  {
187  Int_t eId =
188  StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
189 
190  if ( eId < 0 )
191  return kFgtError;
192 
193  return m_pedestal->AdcPedestalRMS[ eId ];
194  }
195 
196  virtual Char_t getPedestalStatusFromGeoId( Int_t geoId );
197 
198  virtual Char_t getPedestalStatusFromElecId( Int_t elecId );
199 
200 
201  virtual Char_t getPedestalStatusFromGeoName(
202  const std::string & geoName
203  )
204  {
205  Int_t geoId = StFgtGeom::translateGeoNameToGeoId( geoName );
206 
207  if ( geoId < 0 )
208  return kFgtErrorChar;
209 
210  return getPedestalStatusFromGeoId( geoId );
211  }
212 
213  virtual Char_t getPedestalStatusFromElecCoord(
214  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
215  )
216  {
217  Int_t eId =
218  StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
219 
220  if ( eId < 0 )
221  return kFgtErrorChar;
222 
223  return m_pedestal->Status[ eId ];
224  }
225 
226 
227  virtual Char_t getStatusFromGeoId( Int_t geoId );
228 
229  virtual Char_t getStatusFromElecId( Int_t elecId );
230 
231  virtual Char_t getStatusFromGeoName( const std::string & geoName )
232  {
233  Int_t geoId = StFgtGeom::translateGeoNameToGeoId( geoName );
234 
235  if ( geoId < 0 )
236  return kFgtErrorChar;
237 
238  return getStatusFromGeoId( geoId );
239  }
240 
241  virtual Char_t getStatusFromElecCoord(
242  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
243  )
244  {
245  Int_t eId =
246  StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
247 
248  if ( eId < 0 )
249  return kFgtErrorChar;
250 
251  return m_status->Status[ eId ];
252  }
253 
254  virtual Double_t getGainFromGeoId( Int_t geoId );
255 
256  virtual Double_t getGainFromElecId( Int_t elecId );
257 
258  virtual Double_t getGainFromGeoName( const std::string & geoName )
259  {
260  Int_t geoId = StFgtGeom::translateGeoNameToGeoId( geoName );
261 
262  if ( geoId < 0 )
263  return kFgtError;
264 
265  return getGainFromGeoId( geoId );
266  }
267 
268  virtual Double_t getGainFromElecCoord(
269  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
270  )
271  {
272  Int_t eId =
273  StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
274 
275  if ( eId < 0 )
276  return kFgtError;
277 
278  return m_gain->Gain[ eId ];
279  }
280 
281  virtual Char_t getGainStatusFromGeoId( Int_t geoId );
282 
283  virtual Char_t getGainStatusFromElecId( Int_t elecId );
284 
285  virtual Char_t getGainStatusFromGeoName( const std::string & geoName )
286  {
287  Int_t geoId = StFgtGeom::translateGeoNameToGeoId( geoName );
288 
289  if ( geoId < 0 )
290  return kFgtErrorChar;
291 
292  return getGainStatusFromGeoId( geoId );
293  }
294 
295  virtual Char_t getGainStatusFromElecCoord(
296  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
297  )
298  {
299  Int_t eId =
300  StFgtGeom::encodeElectronicId( rdo, arm, apv, channel );
301 
302  if ( eId < 0 )
303  return kFgtErrorChar;
304 
305  return m_gain->Status[ eId ];
306  }
307 
308  virtual Double_t getMapping(
309  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
310  );
311 
312  virtual bool isR(
313  Int_t rdo, Int_t arm, Int_t apv, Int_t channel
314  );
315 
316 
317  virtual Double_t getEloss(Int_t bin)
318  {
319  return m_eLoss[0].cutoff[bin];
320  };
321 
322  virtual Double_t getSimuParam(Int_t bin)
323  {
324  return m_simPar[0].param[bin];
325  };
326 
327  virtual fgtAlignment_st* getAlignment() {return m_alignment;}
328 
329  // This gives XYZ from R and PHI obtained by StFgtGeom::getPhysicalCoordinate(STAR coordinate)
330  // If option=0, no alighment parameter is considered and gives ideal position
331  // If option=1 (default), then alignment parameter is taken from DB, and it will apply offsets and rotation around StFgtGeom::getQuadCenterXYZ()
332  // If option=2, then alignment parameter is taken from last argument, and it will apply offsets and rotation around StFgtGeom::getQuadCenterXYZ()
333  virtual void getStarXYZ(Short_t disc, Short_t quad, Double_t r, Double_t phi, TVector3 &xyz, Int_t opt=1, fgtAlignment_st* par=0);
334 
335  //dump of FGT status/peds/pedSigma for each strip
336  void printFgtDumpCSV1(TString fname, int myDate, int myTime);
337 
338  virtual ~StFgtDb() {}
339 
340 
341  private:
342  fgtMapping_st * m_map;
343  fgtMapping_st * m_rmap;
344  fgtStatus_st * m_status;
345  fgtPedestal_st * m_pedestal;
346  fgtGain_st * m_gain;
347  fgtElosCutoff_st* m_eLoss;
348  fgtSimuParams_st* m_simPar;
349  fgtAlignment_st* m_alignment;
350 };
351 
352 
353 
354  // The ordinate, lowerSpan and upperSpan are all in centimeters or
355  // radians, depending on the layer.
356 inline Int_t StFgtDb::getPhysicalCoordinateFromGeoId(
357  Int_t geoId,
358  Short_t & disc, Short_t & quadrant, Char_t & layer,
359  Double_t & ordinate, Double_t & lowerSpan, Double_t & upperSpan
360  )
361  {
362  return StFgtGeom::getPhysicalCoordinate(
363  geoId, disc, quadrant, layer, ordinate, lowerSpan, upperSpan
364  );
365  }
366 
367  // The ordinate, lowerSpan and upperSpan are all in centimeters or
368  // radians, depending on the layer.
369 inline Int_t StFgtDb::getPhysicalCoordinateFromGeoName(
370  const std::string & geoName,
371  Short_t & disc, Short_t & quadrant, Char_t & layer,
372  Double_t & ordinate, Double_t & lowerSpan, Double_t & upperSpan
373  )
374  {
375  return StFgtGeom::getPhysicalCoordinate(
376  geoName, disc, quadrant, layer, ordinate, lowerSpan, upperSpan
377  );
378  }
379 
380 
381 
382 #endif
383 
384 /*
385  * $ Id: $
386  * $ Log: $
387  *
388  */