HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hwalltrbunpacker.cc
Go to the documentation of this file.
1 //*-- AUTHOR : Jerzy Pietraszko, Ilse Koenig
2 //*-- Created : 03/02/2006
3 // Modified by M.Golubeva 01.11.2006
4 
5 //_HADES_CLASS_DESCRIPTION
6 /////////////////////////////////////////////////////////////
7 //
8 // HWallTrbUnpacker
9 //
10 // Class for unpacking TRB data and filling
11 // the Forward Wall Raw category
12 // Base subevent decoding is performed by decode function
13 // see: htrbbaseunpacker.h
14 //
15 /////////////////////////////////////////////////////////////
16 
17 using namespace std;
18 #include "hwalltrbunpacker.h"
19 #include "walldef.h"
20 #include "htrblookup.h"
21 #include "hwallraw.h"
22 //#include "hwallrefhitpar.h"
23 #include "hdebug.h"
24 #include "hades.h"
25 #include "hevent.h"
26 #include "hspectrometer.h"
27 #include "hdetector.h"
28 #include "hruntimedb.h"
29 #include "hcategory.h"
30 #include "hldsubevt.h"
31 #include "heventheader.h"
32 #include <iostream>
33 #include <iomanip>
34 #include <stdlib.h>
35 
37 
38 HWallTrbUnpacker::HWallTrbUnpacker (UInt_t id):HTrbBaseUnpacker (id) {
39  // constructor
40  pRawCat = NULL;
41  debugWallFlag=0;
42  doRefTimeCorr=0;
43  noTimeRefCorr=false;
44 }
45 
46 Bool_t HWallTrbUnpacker::init (void) {
47 
48  // creates the raw category and gets the pointer to the lookup table
50  if (!pRawCat) {
51  pRawCat = gHades->getSetup ()->getDetector ("Wall")->buildCategory (catWallRaw);
52  if (!pRawCat)
53  return kFALSE;
54  gHades->getCurrentEvent ()->addCategory (catWallRaw, pRawCat, "Wall");
55  }
56  loc.set (1, 0);
57  lookup = (HTrbLookup *) (gHades->getRuntimeDb ()->getContainer ("TrbLookup"));
58  if (!lookup) return kFALSE;
59 
60  return kTRUE;
61 }
62 
63 
65 {
66 
67  HWallRaw *pRaw = 0; // pointer to Raw category
68 
69  if (gHades->isCalibration ()) {
70  //calibration event
71  return 1;
72  }//if (gHades->isCalibration ())
73 
74  // decode subevent data
75  if (pSubEvt) { // pSubEvt - make sure that there is something for decoding
76 
77  // decode the subevent and fill arrays, see: htrbbaseunpacker.h
78  if(!decode()) return(-1);
79 
80  if(!noTimeRefCorr){
81  switch(trbDataVer){
82  case 0:// old
83  case 2:// Wall/Veto
84  // RPC style
85  correctRefTimeCh31();
86  break;
87  case 3:
88  // new scheme for high rates
89  correctRefTimeCh127();
90  break;
91  // case 4:
92  // W.K. electronics
93  // correctRefTimeWKStyle();
94  // break;
95  default:
96  // do nothing
97  break;
98  }
99  }
100 
101  // get the part of the lookup table which belongs to the subevent ID
102  // in order to check which TRBchannel belongs to the WallDetector
103 
104  ///////////////////////////////
105  //
106  // Be Carefull !! I am changing SubEvent ID
107  // Should not be a case !! Only for tests
108  // My test HLD data are with SubEventId = 545
109  // In Hydra Allowed SubEvents Ids for TRB starts from 800...
110  //
111  //////////////////////////////
112 
113 
114  HTrbLookupBoard *board = lookup->getBoard (subEvtId);
115  if (!board) {
116  // Problem: unpacker for specific SubId was called but for this SubId
117  // no channel in lookup table axist.
118  //
119  Warning ("execute", "SubEvent: %i unpacked but channel in Lookup table does not exist", subEvtId);
120  }//if (!board)
121 
122  //fill RAW category for Forward Wall detector
123  for (Int_t i = 0; i < 128; i++) {
124  if (trbLeadingMult[i] < 1) continue; //Leading Time data for this channel exist
125  // fill wall raw category
126  HTrbLookupChan *chan = board->getChannel (i);
127  if (chan && 'W' == (Char_t) (chan->getDetector ())) { //Channel belongs to Wall det
128  loc[0] = (Int_t)chan->getCell();
129  pRaw = (HWallRaw *) pRawCat->getObject (loc);
130 
131  if (!pRaw) {
132  pRaw = (HWallRaw *) pRawCat->getSlot (loc);
133  if (pRaw) {
134  pRaw = new (pRaw) HWallRaw;
135  pRaw->setCell ((Int_t) chan->getCell ());
136  for(Int_t chmult=0; chmult< trbLeadingMult[i]; chmult++){
137  pRaw->fill( trbLeadingTime[i][chmult], trbADC[i][chmult]);
138  }
139  }//if (pRaw)
140  else {
141  Error ("execute()", "Can't get slot");
142  cerr << "Can't get slot: Cell " <<(Int_t)chan->getCell() << endl;
143  return -1;
144  }
145  }//if (!pRaw)
146  else {
147  Error ("execute()", "Slot already exists! This should not happen with TRB board data.");
148  cerr << "Slot already exists: Cell " <<(Int_t)chan->getCell() << endl;
149  }
150 
151  // fill time info for channel: mod, fiber
152  // btw: HHodoRaw will care itself if there are more hits and
153  // handle this cases correctly by itself --- B.S.
154  // todo: convert invalid time from unpacker -> invalid time in hodo class ... all negative are invalid?
155 
156 
157  }//if (chan && 'W' == (Char_t) (chan->getDetector ()))
158  }// for(Int_t i=0; i<128; i++)
159 
160  }//if(pSubEvt)
161 
162  return 1;
163 
164 }
virtual Bool_t addCategory(Cat_t aCat, HCategory *cat, Option_t opt[])=0
HRuntimeDb * getRuntimeDb(void)
Definition: hades.h:111
HEvent *& getCurrentEvent(void)
Definition: hades.cc:422
void setCell(Int_t c)
Definition: hwallraw.h:54
ClassImp(HWallTrbUnpacker) HWallTrbUnpacker
HSpectrometer * getSetup(void)
Definition: hades.h:112
HDetector * getDetector(const Char_t *name)
virtual HCategory * buildCategory(Cat_t)
Definition: hdetector.h:37
Hades * gHades
Definition: hades.cc:1213
HParSet * getContainer(const Text_t *)
Definition: hruntimedb.cc:124
const Cat_t catWallRaw
Definition: walldef.h:6
virtual HCategory * getCategory(Cat_t aCat)=0
Bool_t isCalibration()
Definition: hades.cc:276
Bool_t fill(const Float_t, const Float_t)
Definition: hwallraw.cc:95