StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StFgtDbMaker.cxx
1 // $Id: StFgtDbMaker.cxx,v 1.22 2013/01/31 15:42:19 akio Exp $
2 /* \class StFgtDbMaker
3 \author Stephen Gliske
4 */
5 
6 #include "StFgtDbMaker.h"
7 #include "TDataSetIter.h"
8 #include "StMessMgr.h"
9 #include "tables/St_fgtElosCutoff_Table.h"
10 #include "tables/St_fgtSimuParams_Table.h"
11 #include "tables/St_fgtPedestal_Table.h"
12 #include "tables/St_fgtMapping_Table.h"
13 #include "tables/St_fgtGain_Table.h"
14 #include "tables/St_fgtStatus_Table.h"
15 #include "tables/St_fgtAlignment_Table.h"
16 #include "St_db_Maker/St_db_Maker.h"
17 
18 ClassImp(StFgtDbMaker)
19 
20 //_____________________________________________________________________________
21 StFgtDbMaker::StFgtDbMaker(const char *name)
22  : StMaker(name)
23 {
24 
25  m_tables = new StFgtDb();
26  m_rmap = 0;
27  m_geom=0;
28 }
29 
30 //_____________________________________________________________________________
31 StFgtDbMaker::~StFgtDbMaker()
32 {
33  if ( m_tables )
34  delete m_tables;
35 }
36 
37 //-----------------------------------------------------------------------------
38 void StFgtDbMaker::setFlavor( const char * flav, const char * tabname )
39 {
40  StMaker::SetFlavor( flav, tabname );
41 }
42 
43 //_____________________________________________________________________________
44 Int_t StFgtDbMaker::Init()
45 {
46  LOG_DEBUG << "StFgtDbMaker::Init()" <<endm;
47 
48  return StMaker::Init();
49 }
50 
51 //_____________________________________________________________________________
52 Int_t StFgtDbMaker::InitRun(Int_t runNumber)
53 {
54  LOG_INFO << Form("StFgtDbMaker::InitRun(), run=%d",runNumber)<<endm;
55  LOG_INFO << Form("StFgtDbMaker::InitRun(), Event DateTime=%s",GetDateTime().AsString())<<endm;
56  LOG_INFO << Form("StFgtDbMaker::InitRun(), Database Time=%s",GetDBTime().AsString())<<endm;
57 
58  // clear old pointers to DB tables, just in case. Do not delete the data which are owned by StDbMaker
59  m_LossTab =0;
60 
61 
63  St_fgtElosCutoff *eLossDataset=0;
64  St_fgtSimuParams *simuParamsDataset=0;
65  St_fgtMapping * mapDataset = 0;
66  St_fgtGain * gainDataset = 0;
67  St_fgtPedestal * pedDataset = 0;
68  St_fgtStatus * statusDataset = 0;
69  St_fgtAlignment *alignmentDataset = 0;
70 
72  LOG_INFO << "::RequestDataBase() for Elos cut off ..."<< endl;
73  TDataSet *ELossDB = GetDataBase("Calibrations/fgt/fgtElosCutoff");
74  if (!ELossDB)
75  {
76  LOG_FATAL
77  << "ERROR: no table found in db for eloss, or malformed local db config"
78  << endm;
79  }
80 
82  LOG_INFO << "::RequestDataBase() for slow-simu params ..."<< endl;
83  TDataSet *SimuParamsDB = GetDataBase("Calibrations/fgt/fgtSimuParams");
84  if (!SimuParamsDB)
85  {
86  LOG_FATAL
87  << "ERROR: no table found in db for slow-simu params , or malformed local db config"
88  << endm;
89  }
90 
91  LOG_INFO << "::RequestDataBase() for calibration tables..."<< endl;
92  TDataSet *MapDB = GetDataBase("Calibrations/fgt/fgtMapping");
93  if (!MapDB)
94  {
95  LOG_FATAL
96  << "ERROR: no table found in db for map, or malformed local db config"
97  << endm;
98  }
99  TDataSet *PedDB = GetDataBase("Calibrations/fgt/fgtPedestal");
100  if (!PedDB)
101  {
102  LOG_FATAL
103  << "ERROR: no table found in db for pedestals, or malformed local db config"
104  << endm;
105  }
106  TDataSet *StatusDB = GetDataBase("Calibrations/fgt/fgtStatus");
107  if (!StatusDB)
108  {
109  LOG_FATAL
110  << "ERROR: no table found in db for pedestals, or malformed local db config"
111  << endm;
112  }
113  TDataSet *GainDB = GetDataBase("Calibrations/fgt/fgtGain");
114  if (!GainDB)
115  {
116  LOG_FATAL
117  << "ERROR: no table found in db for pedestals, or malformed local db config"
118  << endm;
119  }
120  TDataSet *AlignmentDB = GetDataBase("Calibrations/fgt/fgtAlignment");
121  if (!AlignmentDB)
122  {
123  LOG_FATAL
124  << "ERROR: no table found in db for pedestals, or malformed local db config"
125  << endm;
126  }
127 
128 
129  eLossDataset=(St_fgtElosCutoff*)ELossDB->Find("fgtElosCutoff");
130  Int_t rows = eLossDataset->GetNRows();
131  if (rows > 1)
132  {
133  LOG_FATAL << " found INDEXED fgtElosCutoff table with " << rows
134  << " rows, this is fatal, fix DB content" << endm;
135  }
136 
137 
138  simuParamsDataset=(St_fgtSimuParams*)SimuParamsDB->Find("fgtSimuParams");
139  rows =simuParamsDataset->GetNRows();
140  if (rows > 1)
141  {
142  LOG_FATAL << " found INDEXED fgtSimuParams table with " << rows
143  << " rows, this is fatal, fix DB content" << endm;
144  }
145 
146 
147  mapDataset = (St_fgtMapping *)
148  MapDB->Find("fgtMapping");
149  rows = mapDataset->GetNRows();
150  if (rows > 1)
151  {
152  LOG_FATAL << " found INDEXED table for mapping with " << rows
153  << " rows, this is fatal, fix DB content" << endm;
154  }
155 
156  gainDataset = (St_fgtGain*)
157  GainDB->Find("fgtGain");
158  rows = gainDataset->GetNRows();
159  if (rows > 1)
160  {
161  LOG_FATAL << " found INDEXED table for gains with " << rows
162  << " rows, this is fatal, fix DB content" << endm;
163  }
164 
165  pedDataset = (St_fgtPedestal*)
166  PedDB->Find("fgtPedestal");
167  rows = pedDataset->GetNRows();
168  if (rows > 1)
169  {
170  LOG_FATAL << " found INDEXED table for pedestals with " << rows
171  << " rows, this is fatal, fix DB content" << endm;
172  }
173  statusDataset = (St_fgtStatus*)
174  StatusDB->Find("fgtStatus");
175  rows = statusDataset->GetNRows();
176  if (rows > 1)
177  {
178  LOG_FATAL << " found INDEXED table for status with " << rows
179  << " rows, this is fatal, fix DB content" << endm;
180  }
181 
182  alignmentDataset = (St_fgtAlignment*) AlignmentDB->Find("fgtAlignment");
183  rows = alignmentDataset->GetNRows();
184  if (rows > 1)
185  {
186  LOG_FATAL << " found INDEXED table for alignment with " << rows
187  << " rows, this is fatal, fix DB content" << endm;
188  }
189 
190 
191  if (pedDataset && statusDataset && mapDataset && gainDataset && eLossDataset && simuParamsDataset && alignmentDataset)
192  {
193  if ( m_rmap )
194  delete m_rmap;
195  m_rmap = new fgtMapping_st();
196 
197  fgtMapping_st * map = mapDataset->GetTable();
198 
199  for ( int ii = 0; ii < 51200; ++ii )
200  {
201  if (map->Mapping[ii]>=0)
202  m_rmap->Mapping[ map->Mapping[ii] ] = ii;
203 
204  }
205 
206  dynamic_cast< StFgtDb* >(m_tables)->updateTables(
207  map, m_rmap,
208  statusDataset->GetTable(),
209  pedDataset->GetTable(),
210  gainDataset->GetTable(),
211  eLossDataset->GetTable(),
212  simuParamsDataset->GetTable(),
213  alignmentDataset->GetTable()
214  );
215 
216  LOG_INFO
217  <<
218  Form(
219  "%s :: map, gain, pedestal and status tables received, comments",
220  GetName()
221  )
222  << endm;
223 
224  displayBeginEndTime(mapDataset);
225  displayBeginEndTime(statusDataset);
226  displayBeginEndTime(pedDataset);
227  displayBeginEndTime(gainDataset);
228  displayBeginEndTime(alignmentDataset);
229  displayBeginEndTime(eLossDataset); LOG_INFO <<eLossDataset->GetTable()->comment<<endl;
230  displayBeginEndTime(simuParamsDataset); LOG_INFO <<simuParamsDataset->GetTable()->comment<<endl;
231 
232  }
233  else
234  {
235  if ( !pedDataset )
236  {
237  LOG_FATAL << Form("%s :: pedestal table failed,",GetName())
238  << endm;
239  }
240  if ( !mapDataset )
241  {
242  LOG_FATAL << Form("%s :: map table failed,",GetName())
243  << endm;
244  }
245  if ( !gainDataset )
246  {
247  LOG_FATAL << Form("%s :: gain table failed,",GetName())
248  << endm;
249  }
250  if ( !statusDataset )
251  {
252  LOG_FATAL << Form("%s :: status table failed,",GetName())
253  << endm;
254  }
255  if ( !eLossDataset )
256  {
257  LOG_FATAL << Form("%s :: eLoss table failed,",GetName())
258  << endm;
259  }
260  if ( !simuParamsDataset )
261  {
262  LOG_FATAL << Form("%s :: SimuParams table failed,",GetName())
263  << endm;
264  }
265  if ( !alignmentDataset )
266  {
267  LOG_FATAL << Form("%s :: Alignment table failed,",GetName())
268  << endm;
269  }
270  }
271 
272  return kStOK;
273 }
274 
275 //_____________________________________________________________________________
276 void StFgtDbMaker::displayBeginEndTime(TTable* table) {
277  TDatime datime[2];
278  St_db_Maker::GetValidity(table,datime);
279  string tableName = table->GetName();
280  string beginTime = datime[0].AsSQLString();
281  string endTime = datime[1].AsSQLString();
282 
283  map<string, pair<string, string> >::iterator iter = mValidRanges.find(tableName);
284  if(iter == mValidRanges.end()) {
285  mValidRanges[tableName] = make_pair(beginTime, endTime);
286  LOG_INFO << Form("loaded a new %20s table with beginTime %s and endTime %s", tableName.c_str(), beginTime.c_str(), endTime.c_str()) << endm;
287  cout << Form("loaded a new %20s table with beginTime %s and endTime %s", tableName.c_str(), beginTime.c_str(), endTime.c_str()) << endl;
288  }
289  else if( beginTime != (iter->second).first ) {
290  (iter->second).first = beginTime;
291  (iter->second).second = endTime;
292  LOG_INFO << Form("loaded a new %20s table with beginTime %s and endTime %s", tableName.c_str(), beginTime.c_str(), endTime.c_str()) << endm;
293  cout << Form("loaded a new %20s table with beginTime %s and endTime %s", tableName.c_str(), beginTime.c_str(), endTime.c_str()) << endl;
294  }
295 }
296 
297 //_____________________________________________________________________________
299 {
300  LOG_DEBUG << "Make" << endm;
301 
302  return kStOK;
303 }
304 
305 //_____________________________________________________________________________
306 void StFgtDbMaker::Clear(const char*)
307 {
308  LOG_DEBUG << "Clear" << endm;
309  StMaker::Clear();
310 }
311 
312 //_____________________________________________________________________________
314 {
315  LOG_DEBUG << "Finish" << endm;
316  return kStOK;
317 }
318 
319 //_____________________________________________________________________________
320 
321 
322 
323 
324 
325 // $Log: StFgtDbMaker.cxx,v $
326 // Revision 1.22 2013/01/31 15:42:19 akio
327 // Adding Alignment table and getStarXYZ()
328 //
329 // Revision 1.21 2012/07/31 18:24:30 jeromel
330 // Removed virtual + fixed name
331 //
332 // Revision 1.20 2012/06/03 16:52:18 balewski
333 // added access to fgtSimuParam table, all I/O .C code is saved in macros
334 //
335 // Revision 1.19 2012/03/19 01:18:52 rfatemi
336 // Modified for removal of StFgtDbImpl and StFgtDbIdealImpl
337 //
338 // Revision 1.18 2012/03/14 01:07:11 rfatemi
339 // added comments
340 //
341 // Revision 1.17 2012/03/10 01:59:22 rfatemi
342 // Review comments
343 //
344 // Revision 1.16 2012/02/22 20:07:44 rfatemi
345 // Changed name from updateValidity to displayBeginEndTime
346 //
347 // Revision 1.15 2012/02/22 04:04:18 rfatemi
348 // Added beginTime's for each table
349 //
350 // Revision 1.14 2012/01/31 21:07:43 rfatemi
351 // changes for StFgtDbIdealImpl.h
352 //
353 // Revision 1.13 2012/01/31 17:02:46 wwitzke
354 // Added date/time printout to StFgtDbMaker.cxx InitRun().
355 //
356 // Revision 1.12 2012/01/19 22:59:31 rfatemi
357 // Don't read negative DB numbers into reverse maps
358 //
359 // Revision 1.11 2012/01/18 17:24:55 sgliske
360 // fixed bug on line 225 that made ideal flavor always fail
361 //
362 // Revision 1.10 2011/12/02 03:53:18 avossen
363 // fixed eLoss db tables
364 //
365 // Revision 1.9 2011/11/14 02:31:15 wwitzke
366 // Fixed bug with where getTables() can be called.
367 //
368 // Revision 1.8 2011/11/14 02:17:26 wwitzke
369 // Update to fix seg fault. Again.
370 //
371 // Revision 1.7 2011/11/14 01:49:33 wwitzke
372 // Fixed seg fault bug.
373 //
374 // Revision 1.5 2011/11/13 23:51:49 wwitzke
375 // Modified StFgtDbMaker to pull calibration data from the database.
376 //
377 // Revision 1.4 2011/10/26 19:32:34 balewski
378 // now fgt-geom is owned by fgtDb-maker
379 //
380 // Revision 1.3 2011/10/06 19:03:58 balewski
381 // access Elos table from STAR DB
382 //
383 // Revision 1.2 2011/10/04 02:59:34 balewski
384 // added guestimates of gains, grid absorption, charge sharing
385 //
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
Int_t InitRun(Int_t runNumber)
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:40
Definition: TTable.h:48
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362