StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTofrDaqMap.cxx
1 /*******************************************************************
2  *
3  * $Id: StTofrDaqMap.cxx,v 1.15 2012/12/17 22:57:20 geurts Exp $
4  *
5  * Author: Xin Dong
6  *****************************************************************
7  *
8  * Description: (1) Mapping between Daq channel numbers, ADC(TDC) channel
9  * numbers and TOFr cell numbers
10  * (2) Parameters initalize from dbase
11  *
12  *****************************************************************
13  *
14  * $Log: StTofrDaqMap.cxx,v $
15  * Revision 1.15 2012/12/17 22:57:20 geurts
16  * bugfix (tickets #2456/#2457)
17  *
18  * Revision 1.14 2012/12/14 06:35:59 geurts
19  * Changed global database calls to direct table access and/or removed deprecated database access code.
20  *
21  * Revision 1.13 2008/08/28 18:43:20 dongx
22  * Added MRPC-TOF simulation parameters
23  * Added TOF/VPD fast simulation parameters
24  *
25  * Revision 1.12 2008/03/27 00:15:38 dongx
26  * Update for Run8 finished.
27  *
28  * Revision 1.11 2007/11/22 00:04:13 dongx
29  * - update for tof8++
30  * - added ValidTrays() function
31  *
32  * Revision 1.8 2007/04/17 23:01:52 dongx
33  * replaced with standard STAR Loggers
34  *
35  * Revision 1.7 2007/02/06 20:20:44 dongx
36  * update for tofr5Maptable I/O (new release)
37  *
38  * Revision 1.6 2005/04/12 17:23:15 dongx
39  * Update for year 5 new data format, writter by Jing Liu
40  *
41  * Revision 1.5 2004/05/03 22:58:26 dongx
42  * using a switch to set the ouput message
43  *
44  * Revision 1.4 2004/04/09 15:17:19 jeromel
45  * void function returning a value is forbidden by standards
46  *
47  * Revision 1.3 2004/04/08 21:11:11 dongx
48  * remove assert() functions
49  *
50  * Revision 1.2 2004/03/09 17:43:04 dongx
51  * first release
52  *
53  *
54  *******************************************************************/
55 #include <iostream>
56 #include "tables/St_tofModuleConfig_Table.h"
57 #include "tables/St_tofCamacDaqMap_Table.h"
58 #include "tables/St_tofr5Maptable_Table.h"
59 #include "tables/St_tofDaqMap_Table.h"
60 #include "tables/St_tofTrayConfig_Table.h"
61 #include "StMessMgr.h"
62 #include "StMaker.h"
63 #include "StTofrDaqMap.h"
64 
65 StTofrDaqMap::StTofrDaqMap()
66 {
67  Reset();
68 }
69 
70 StTofrDaqMap::~StTofrDaqMap()
71 {
72  Reset();
73 }
74 
75 void StTofrDaqMap::init() {
76  Reset();
77 }
78 
79 void StTofrDaqMap::init(StMaker *maker) {
80  initFromDbase(maker);
81 }
82 
83 void StTofrDaqMap::initFromDbase(StMaker *maker) {
84 
85  gMessMgr->Info("StTofrDaqMap -- retrieving the daq mapping","OS");
87  // Load configuration parameters from dbase
88  // need "[shell] setenv Calibrations_tof reconV0"
90 
91  TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofModuleConfig");
92  if(!mDbTOFDataSet) {
93  gMessMgr->Error("unable to access TOF tofModuleConfig table","OS");
94  // assert(mDbTOFDataSet);
95  return; // kStErr;
96  }
97 
98  St_tofModuleConfig* tofModuleConf = static_cast<St_tofModuleConfig*>(mDbTOFDataSet->Find("tofModuleConfig"));
99  if(!tofModuleConf) {
100  gMessMgr->Error("unable to get tof Module Configuration parameters","OS");
101  // assert(tofModuleConf);
102  return; // kStErr;
103  }
104  tofModuleConfig_st* moduleConf = static_cast<tofModuleConfig_st*>(tofModuleConf->GetArray());
105  // Int_t numRows = tofModuleConf->GetNRows();
106  Int_t entries = (Int_t)(moduleConf[0].entries);
107  if(entries*mNCell!=mNTOFR) {
108  gMessMgr->Warning(" # TOFr channels incosistency in dbase");
109  }
110  for (Int_t i=0;i<entries;i++) {
111  for (Int_t j=0;j<mNCell;j++) {
112  Int_t ic = i*6+j;
113  Int_t id = (Int_t)(moduleConf[0].iChannel[ic]);
114  mTrayId[id] = (Int_t)(moduleConf[0].iTray[i]);
115  mModuleId[id] = (Int_t)(moduleConf[0].iModule[i]);
116  mCellId[id] = j+1;
117  if(maker->Debug()) {
118  LOG_INFO << " id=" << id << " tray=" << mTrayId[id] << " module=" << mModuleId[id] << " cell=" << mCellId[id] << endm;
119  }
120  }
121  }
122 
123  mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofCamacDaqMap");
124  if(!mDbTOFDataSet) {
125  gMessMgr->Error("unable to access TOF tofCamacDaqMap table","OS");
126  // assert(mDbTOFDataSet);
127  return; // kStErr;
128  }
129  St_tofCamacDaqMap* tofDaqMap = static_cast<St_tofCamacDaqMap*>(mDbTOFDataSet->Find("tofCamacDaqMap"));
130  if(!tofDaqMap) {
131  gMessMgr->Error("unable to get tof daq map","OS");
132  // assert(tofDaqMap);
133  return; // kStErr;
134  }
135  tofCamacDaqMap_st* tofmap = static_cast<tofCamacDaqMap_st*>(tofDaqMap->GetArray());
136  // Int_t ndaqRows = tofDaqMap->GetNRows();
137  Int_t daqentries = (Int_t)(tofmap[0].entries);
138  Int_t nChans = 0;
139  bool chanMatch = kTRUE;
140  for(Int_t i=0;i<daqentries;i++) {
141  // not tofr detector or TOTs
142  if(tofmap[0].detectorId[i]!=2||tofmap[0].adcChan[i]<0) continue;
143  if(nChans>=mNTOFR) {
144  break;
145  chanMatch = kFALSE;
146  }
147  Int_t daqChan = (Int_t)(tofmap[0].daqChannel[i]);
148  mAdc[daqChan] = (Int_t)(tofmap[0].adcChan[i]);
149  mTdc[daqChan] = (Int_t)(tofmap[0].tdcChan[i]);
150  nChans++;
151  }
152  if(!chanMatch || nChans!=mNTOFR) {
153  gMessMgr->Warning(" # TOFr daq channels inconsistency in dbase");
154  }
155 
156 }
157 // for tofr5------------------------------------------------------------------------
158 void StTofrDaqMap::initFromDbaseY5(StMaker *maker) {
159 
160  gMessMgr->Info("StTofrDaqMap -- retrieving the tofr5 channel mapping","OS");
162  // Load configuration parameters from dbase
163  // need "[shell] setenv Calibrations_tof reconV0"
165 
166  TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofr5Maptable");
167  if(!mDbTOFDataSet) {
168  gMessMgr->Error("unable to access Calibrations TOF parameters","OS");
169  // assert(mDbTOFDataSet);
170  return; // kStErr;
171  }
172 
173  St_tofr5Maptable* tofr5maptable = static_cast<St_tofr5Maptable*>(mDbTOFDataSet->Find("tofr5Maptable"));
174  if(!tofr5maptable) {
175  gMessMgr->Error("unable to get tof Module map table","OS");
176  return; // kStErr;
177  }
178  tofr5Maptable_st* maptable = static_cast<tofr5Maptable_st*>(tofr5maptable->GetArray());
179  for (Int_t i=0;i<mNTOFR5;i++) {
180  mGlobalTDCChan[i]=(Int_t)(maptable[0].tdigchan[i]);
181  mGlobalModuleChan[i]=(Int_t)(maptable[0].modulechan[i]);
182  if(maker->Debug()) {
183  LOG_INFO << " i=" << i << " TDC chan =" << mGlobalTDCChan[i] << " module chan=" <<mGlobalModuleChan[i]<<endm;
184  }
185  }
186 
187 
188  return;
189 }
190 
191 void StTofrDaqMap::initFromDbaseGeneral(StMaker *maker) {
192 
193  gMessMgr->Info("StTofrDaqMap -- retrieving the tof8++ channel mapping","OS");
195  // Load configuration parameters from dbase
196  // need "[shell] setenv Calibrations_tof reconV0"
198 
199  TDataSet *mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofDaqMap");
200  if(!mDbTOFDataSet) {
201  gMessMgr->Error("unable to access TOF tofDaqMap table","OS");
202  // assert(mDbTOFDataSet);
203  return; // kStErr;
204  }
205 
206  St_tofDaqMap* tofDaqMap = static_cast<St_tofDaqMap*>(mDbTOFDataSet->Find("tofDaqMap"));
207  if(!tofDaqMap) {
208  gMessMgr->Error("unable to get tof Module map table","OS");
209  return; // kStErr;
210  }
211  tofDaqMap_st* daqmap = static_cast<tofDaqMap_st*>(tofDaqMap->GetArray());
212  for (Int_t i=0;i<mNTOF;i++) {
213  mMRPC2TDIGChan[i] = (Int_t)(daqmap[0].MRPC2TDIGChanMap[i]);
214  mTDIG2MRPCChan[mMRPC2TDIGChan[i]] = i;
215  if(maker->Debug()) {
216  LOG_INFO << " MRPC = " << i << " TDC chan = " << mMRPC2TDIGChan[i] << endm;
217  }
218  }
219  for (Int_t i=0;i<mNVPD;i++) {
220  mWestPMT2TDIGLeChan[i] = (Int_t)(daqmap[0].PMT2TDIGLeChanMap[i]);
221  mWestPMT2TDIGTeChan[i] = (Int_t)(daqmap[0].PMT2TDIGTeChanMap[i]);
222  if(maker->Debug()) {
223  LOG_INFO << " VPD = " << i << " TDC Lechan = " << mWestPMT2TDIGLeChan[i] << " TDC TeChan = " << mWestPMT2TDIGTeChan[i] << endm;
224  }
225  mTDIGLe2WestPMTChan[mWestPMT2TDIGLeChan[i]] = i;
226  mTDIGTe2WestPMTChan[mWestPMT2TDIGTeChan[i]] = i;
227 
228  int j=i+mNVPD;
229 
230  mEastPMT2TDIGLeChan[i] = (Int_t)(daqmap[0].PMT2TDIGLeChanMap[j]);
231  mEastPMT2TDIGTeChan[i] = (Int_t)(daqmap[0].PMT2TDIGTeChanMap[j]);
232  if(maker->Debug()) {
233  LOG_INFO << " VPD = " << i << " TDC Lechan = " << mEastPMT2TDIGLeChan[i] << " TDC TeChan = " << mEastPMT2TDIGTeChan[i] << endm;
234  }
235  mTDIGLe2EastPMTChan[mEastPMT2TDIGLeChan[i]] = i;
236  mTDIGTe2EastPMTChan[mEastPMT2TDIGTeChan[i]] = i;
237  }
238 
239  // valid tray Id
240  mDbTOFDataSet = maker->GetDataBase("Calibrations/tof/tofTrayConfig");
241  if(!mDbTOFDataSet) {
242  gMessMgr->Error("unable to access TOF tofTrayConfig table","OS");
243  // assert(mDbTOFDataSet);
244  return; // kStErr;
245  }
246  St_tofTrayConfig* trayConfig = static_cast<St_tofTrayConfig*>(mDbTOFDataSet->Find("tofTrayConfig"));
247  if(!trayConfig) {
248  gMessMgr->Error("unable to get tof tray configuration","OS");
249  return; // kStErr;
250  }
251  tofTrayConfig_st* trayconf = static_cast<tofTrayConfig_st*>(trayConfig->GetArray());
252  if(maker->Debug()) LOG_INFO << " Valid Trays: " << endm;
253  for (Int_t i=0;i<mNValidTrays;i++) {
254  mValidTrayId[i] = (Int_t)(trayconf[0].iTray[i]);
255  if(maker->Debug()) {
256  cout << " " << mValidTrayId[i];
257  }
258  }
259  if(maker->Debug()) cout << endl;
260 
261  return;
262 }
263 
264 
265 void StTofrDaqMap::Reset() {
266  for(Int_t i=0;i<mNTOFR;i++) {
267  mTrayId[i] = 0;
268  mModuleId[i] = 0;
269  mCellId[i] = 0;
270  mAdc[i] = -1;
271  mTdc[i] = -1;
272  }
273  // tofr5
274  for(int i=0;i<mNTOFR5;i++){
275  mGlobalTDCChan[i]=0;
276  mGlobalModuleChan[i]=0;
277  }
278  // tof8++
279  for(int i=0;i<mNTOF;i++) {
280  mMRPC2TDIGChan[i] = -1;
281  mTDIG2MRPCChan[i] = -1;
282  mTDIGLe2WestPMTChan[i] = -1;
283  mTDIGTe2WestPMTChan[i] = -1;
284  mTDIGLe2EastPMTChan[i] = -1;
285  mTDIGTe2EastPMTChan[i] = -1;
286  }
287  for(int i=0;i<mNVPD;i++) {
288  mEastPMT2TDIGLeChan[i] = -1;
289  mEastPMT2TDIGTeChan[i] = -1;
290  mWestPMT2TDIGLeChan[i] = -1;
291  mWestPMT2TDIGTeChan[i] = -1;
292  }
293 
294  mNValidTrays = 0;
295 }
296 
297 IntVec StTofrDaqMap::DaqChan2Cell( const Int_t iTofrDaq )
298 {
299  IntVec map;
300  map.clear();
301  if ( iTofrDaq<0 || iTofrDaq>=mNTOFR ) {
302  LOG_INFO << " ERROR! Uncorrected iTofrDaq number for Tofr! " << endm;
303  return map;
304  }
305 
306  map.push_back(mTrayId[iTofrDaq]);
307  map.push_back(mModuleId[iTofrDaq]);
308  map.push_back(mCellId[iTofrDaq]);
309 
310  return map;
311 }
312 
313 
314 
315 Int_t StTofrDaqMap::Cell2DaqChan( const Int_t iTray, const Int_t iModule, const Int_t iCell )
316 {
317  Int_t daq = mDAQOVERFLOW;
318 
319  for(Int_t i=0;i<mNTOFR;i++) {
320  if( mTrayId[i]==iTray && mModuleId[i]==iModule && mCellId[i]==iCell ) {
321  daq = i;
322  break;
323  }
324  }
325 
326  return daq;
327 }
328 
329 
330 IntVec StTofrDaqMap::ADCChan2Cell( const Int_t iAdc )
331 {
332  Int_t daq = ADCChan2DaqChan(iAdc);
333 
334  IntVec map;
335  map.clear();
336  if(daq==mDAQOVERFLOW) {
337  gMessMgr->Warning(" iAdc is out of ADC channels");
338  return map;
339  }
340 
341  return DaqChan2Cell(daq);
342 }
343 
344 IntVec StTofrDaqMap::TDCChan2Cell( const Int_t iTdc )
345 {
346  Int_t daq = TDCChan2DaqChan(iTdc);
347 
348  IntVec map;
349  map.clear();
350  if(daq==mDAQOVERFLOW) {
351  gMessMgr->Warning(" iTdc is out of TDC channels");
352  return map;
353  }
354 
355  return DaqChan2Cell(daq);
356 }
357 
358 Int_t StTofrDaqMap::Cell2ADCChan( const Int_t iTray , const Int_t iModule, const Int_t iCell )
359 {
360  Int_t daq = Cell2DaqChan(iTray, iModule, iCell);
361  if(daq==mDAQOVERFLOW) {
362  return -1;
363  }
364  return mAdc[daq];
365 }
366 
367 Int_t StTofrDaqMap::Cell2TDCChan( const Int_t iTray , const Int_t iModule, const Int_t iCell )
368 {
369  Int_t daq = Cell2DaqChan(iTray, iModule, iCell);
370  if (daq==mDAQOVERFLOW) {
371  return -1;
372  }
373  return mTdc[daq];
374 }
375 
376 Int_t StTofrDaqMap::DaqChan2ADCChan( const Int_t iTofrDaq )
377 {
378  if(iTofrDaq<0 || iTofrDaq>=mNTOFR ) {
379  LOG_INFO << " ERROR! Uncorrected iTofrDaq number for Tofr! " << endm;
380  return -1;
381  }
382 
383  return mAdc[iTofrDaq];
384 }
385 
386 Int_t StTofrDaqMap::DaqChan2TDCChan( const Int_t iTofrDaq )
387 {
388  if(iTofrDaq<0 || iTofrDaq>=mNTOFR ) {
389  LOG_INFO << " ERROR! Uncorrected iTofrDaq number for Tofr! " << endm;
390  return -1;
391  }
392 
393  return mTdc[iTofrDaq];
394 }
395 
396 
397 Int_t StTofrDaqMap::ADCChan2DaqChan( const Int_t iAdc )
398 {
399  Int_t daq = mDAQOVERFLOW;
400  for(Int_t i=0;i<mNTOFR;i++) {
401  if(mAdc[i]==iAdc) {
402  daq = i;
403  break;
404  }
405  }
406 
407  return daq;
408 }
409 
410 Int_t StTofrDaqMap::TDCChan2DaqChan( const Int_t iTdc )
411 {
412  Int_t daq = mDAQOVERFLOW;
413  for(Int_t i=0;i<mNTOFR;i++) {
414  if(mTdc[i]==iTdc) {
415  daq = i;
416  break;
417  }
418  }
419  return daq;
420 }
421 
422 //tofr5
423 
424 IntVec StTofrDaqMap::Tofr5TDCChan2Cell( const Int_t iTdc)
425 {
426  IntVec map;
427  map.clear();
428 
429  if ( iTdc<0 || iTdc>=mNTOFR5 ) {
430  LOG_INFO << " ERROR! Uncorrected TDC Channel number for Tofr5! " << endm;
431  return map;
432  }
433 
434  Int_t Tray=93; // only tray 93 is installed in tofr5
435  Int_t ModuleChan = mGlobalModuleChan[iTdc];
436  Int_t Module = ModuleChan/6+1;
437  Int_t Cell = ModuleChan%6+1;
438  map.push_back(Tray);
439  map.push_back(Module);
440  map.push_back(Cell);
441 
442  return map;
443 }
444 
445 Int_t StTofrDaqMap::Tofr5Cell2TDCChan( const Int_t iTray , const Int_t iModule, const Int_t iCell )
446 {
447 
448  if(iTray!=93 ) {
449  LOG_INFO<<"ERROR!!! Wrong tray number !"<<endm;
450  return -1;
451  }
452  if(iModule<1 || iModule>32 ) {
453  LOG_INFO<<"ERROR!!! Wrong module number !"<<endm;
454  return -1;
455  }
456  if(iCell <1 || iCell > 6) {
457  LOG_INFO<<"ERROR!!! Wrong cell number ! "<<endm;
458  return -1;
459  }
460 
461  Int_t modulechan = (iModule-1)*6+(iCell-1);
462 
463 // if (modulechan<1 || modulechan>=mNTOFR5) {
464  if (modulechan<0 || modulechan>=mNTOFR5) {
465  LOG_INFO<<"ERROR!!! Wrong Module Cell channel number!"<<endm;
466  return -1;
467  }
468 
469  return mGlobalTDCChan[modulechan];
470 }
471 
472 //tof8++
473 IntVec StTofrDaqMap::TDIGChan2Cell( const Int_t iTdc)
474 {
475  IntVec map;
476  map.clear();
477 
478  if ( iTdc<0 || iTdc>=mNTOF ) {
479  LOG_INFO << " ERROR! Uncorrected TDC Channel number for Tof! " << endm;
480  return map;
481  }
482 
483  Int_t ModuleChan = mTDIG2MRPCChan[iTdc];
484  Int_t Module = ModuleChan / mNCell + 1;
485  Int_t Cell = ModuleChan % mNCell + 1;
486  map.push_back(Module);
487  map.push_back(Cell);
488 
489  return map;
490 }
491 
492 Int_t StTofrDaqMap::Cell2TDIGChan( const Int_t iModule, const Int_t iCell )
493 {
494 
495  if(iModule<1 || iModule>mNModule ) {
496  LOG_INFO<<"ERROR!!! Wrong module number !"<<endm;
497  return -1;
498  }
499  if(iCell <1 || iCell > mNCell) {
500  LOG_INFO<<"ERROR!!! Wrong cell number ! "<<endm;
501  return -1;
502  }
503 
504  Int_t modulechan = (iModule-1)*mNCell+(iCell-1);
505 
506 // if (modulechan<1 || modulechan>=mNTOF) {
507  if (modulechan<0 || modulechan>=mNTOF) {
508  LOG_INFO<<"ERROR!!! Wrong Module Cell channel number!"<<endm;
509  return -1;
510  }
511 
512  return mMRPC2TDIGChan[modulechan];
513 }
514 
515 Int_t StTofrDaqMap::WestPMT2TDIGLeChan( const Int_t iTube )
516 {
517  if ( iTube<1 || iTube>mNVPD ) {
518  LOG_INFO<<"ERROR!!! Wrong vpd tube number ! "<<endm;
519  return -1;
520  }
521 
522  return mWestPMT2TDIGLeChan[iTube-1];
523 }
524 
525 Int_t StTofrDaqMap::WestPMT2TDIGTeChan( const Int_t iTube )
526 {
527  if ( iTube<1 || iTube>mNVPD ) {
528  LOG_INFO<<"ERROR!!! Wrong vpd tube number ! "<<endm;
529  return -1;
530  }
531 
532  return mWestPMT2TDIGTeChan[iTube-1];
533 }
534 
535 Int_t StTofrDaqMap::TDIGLeChan2WestPMT( const Int_t iTdc )
536 {
537  if ( iTdc<0 || iTdc>=mNTOF ) {
538  LOG_INFO<<"ERROR!!! Wrong tdc channel number ! "<<endm;
539  return -1;
540  }
541 
542  return mTDIGLe2WestPMTChan[iTdc] + 1;
543 }
544 
545 Int_t StTofrDaqMap::TDIGTeChan2WestPMT( const Int_t iTdc )
546 {
547  if ( iTdc<0 || iTdc>=mNTOF ) {
548  LOG_INFO<<"ERROR!!! Wrong tdc channel number ! "<<endm;
549  return -1;
550  }
551 
552  return mTDIGTe2WestPMTChan[iTdc] + 1;
553 }
554 
555 Int_t StTofrDaqMap::EastPMT2TDIGLeChan( const Int_t iTube )
556 {
557  if ( iTube<1 || iTube>mNVPD ) {
558  LOG_INFO<<"ERROR!!! Wrong vpd tube number ! "<<endm;
559  return -1;
560  }
561 
562  return mEastPMT2TDIGLeChan[iTube-1];
563 }
564 
565 Int_t StTofrDaqMap::EastPMT2TDIGTeChan( const Int_t iTube )
566 {
567  if ( iTube<1 || iTube>mNVPD ) {
568  LOG_INFO<<"ERROR!!! Wrong vpd tube number ! "<<endm;
569  return -1;
570  }
571 
572  return mEastPMT2TDIGTeChan[iTube-1];
573 }
574 
575 Int_t StTofrDaqMap::TDIGLeChan2EastPMT( const Int_t iTdc )
576 {
577  if ( iTdc<0 || iTdc>=mNTOF ) {
578  LOG_INFO<<"ERROR!!! Wrong tdc channel number ! "<<endm;
579  return -1;
580  }
581 
582  return mTDIGLe2EastPMTChan[iTdc] + 1;
583 }
584 
585 Int_t StTofrDaqMap::TDIGTeChan2EastPMT( const Int_t iTdc )
586 {
587  if ( iTdc<0 || iTdc>=mNTOF ) {
588  LOG_INFO<<"ERROR!!! Wrong tdc channel number ! "<<endm;
589  return -1;
590  }
591 
592  return mTDIGTe2EastPMTChan[iTdc] + 1;
593 }
594 
595 IntVec StTofrDaqMap::ValidTrays()
596 {
597  IntVec trayId;
598  for(int i=0;i<mNValidTrays;i++) {
599  trayId.push_back(mValidTrayId[i]);
600  }
601 
602  return trayId;
603 }
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362