HYDRA_development_version
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
hpiontrackertrb3unpacker.cc
Go to the documentation of this file.
1 //_HADES_CLASS_DESCRIPTION
2 /////////////////////////////////////////////////////////////
3 //
4 // HPionTrackerTrb3Unpacker
5 //
6 // Class for unpacking TRB3 data and filling
7 // the PionTracker Raw category
8 //
9 /////////////////////////////////////////////////////////////
10 
12 #include "hades.h"
13 #include "hcategory.h"
14 #include "hdebug.h"
15 #include "hevent.h"
16 #include "heventheader.h"
17 #include "hldsource.h"
18 #include "hldsubevt.h"
19 #include "hruntimedb.h"
20 #include "hspectrometer.h"
21 #include "hpiontrackerdetector.h"
22 #include "hpiontrackerraw.h"
23 #include "hpiontrackertrb3lookup.h"
24 #include "hpiontrackerdef.h"
25 #include <iostream>
26 
27 using namespace std;
28 
29 #define PR(x) std::cout << "++DEBUG: " << #x << " = |" << x << "| (" << __FILE__ << ", " << __LINE__ << ")\n";
30 #define PRh(x) std::cout << "++DEBUG: " << #x << " = hex |" << std::hex << x << std::dec << "| (" << __FILE__ << ", " << __LINE__ << ")\n";
31 
33 
35 {
36  // constructor
37  subEvtId = id;
38  uTrbNetAddress = 0;
39  nEvt = 0;
40 
41  debugFlag = 0;
42  quietMode = kFALSE;
43  reportCritical = kFALSE;
44 
45  pRawCat = NULL;
46  pLookup = NULL;
47  pTrbBoard = NULL;
48 }
49 
51 {
52  // creates the raw category and gets the pointer to the TRB3 lookup table
53 
55 
56  if (!det)
57  {
58  Error ("init", "No PionTracker found.");
59  return kFALSE;
60  }
61 
62  pRawCat = det->buildCategory (catPionTrackerRaw);
63  loc.set (2, 0, 0);
64 // loc.set (1, 0);
65 
66  pLookup = (HPionTrackerTrb3Lookup *) (gHades->getRuntimeDb()->getContainer ("PionTrackerTrb3Lookup"));
67 
68  if (!pLookup)
69  {
70  Error ("init", "No Pointer to parameter container PionTrackerTrb3Lookup.");
71  return kFALSE;
72  }
73 
74  return kTRUE;
75 }
76 
78 {
79  // decodes the subevent of the PionTracker and fills the Raw category
80  if (gHades->isCalibration())
81  {
82  //calibration event
83  return 1;
84  }
85 
86  if (gHades->getCurrentEvent()->getHeader()->getId() == 0xe)
87  {
88  //scaler event
89  return 1;
90  }
91 
92  nEvt = gHades->getCurrentEvent()->getHeader()->getEventSeqNumber(); // Evt Seq. Nb.
93 
94  if (NULL == pSubEvt)
95  {
96 #if DEBUG_LEVEL > 0
97  Warning ("execute", "EvtId: 0x%x, Unpacker 0x%x ==> no data",
98  gHades->getCurrentEvent()->getHeader()->getId(), subEvtId);
99 #endif
100  return 1;
101  }
102 
103  // decode subevent data
104 
105 // pSubEvt - make sure that there is something for decoding
106  if (!pSubEvt)
107  return 1;
108 
109  UInt_t * databeg = pSubEvt->getData();
110  UInt_t * dataend = pSubEvt->getEnd();
111 
113 
114  size_t data_size = dataend - databeg;
115 
116  if (data_size == 0) return 0;
117 
118  size_t datanum = 0;
119  size_t datacnt = 0;
120 
121  ptstate sm = sm_wait_for_board;
122 
123  ptheaderset pths;// = { des_none, -1, -1, -1, -1, -1 };
124  ptdataset ptds;// = { -1, -1, -1, -1, -1 };
125 
126  for (size_t cnt = 0; cnt < data_size; ++cnt)
127  {
128  UInt_t d = * (databeg + cnt);
129 
130  switch (sm)
131  {
132  case sm_wait_for_board:
133  datanum = (d >> 16) & 0xFFFF; // No. of the data words from one TRB board
134  uTrbNetAddress = d & 0xFFFF; // TRB net Adddress (Old TRB subevent id)
135 // PRh(uTrbNetAddress);
136  if (datanum == 0)
137  {
138  continue;
139  }
140 
141  datacnt = 0;
142 
143  // which module
144  if (uTrbNetAddress == 0x5555)
145  {
146  cnt += datanum;
147  continue;
148  }
149 
150  pTrbBoard = pLookup->getBoard (uTrbNetAddress);
151 
152  if (!pTrbBoard)
153  {
154  Warning ("HPionTrackerTrb3Unpacker::execute",
155  "Evt Nr : %i TrbNetAdress: %x (%i) unpacked but TRB Board not in lookup table",
156  nEvt, uTrbNetAddress, uTrbNetAddress);
157  // skip proper number of words and continue iwth next board
158  cnt += datanum;
159  continue;
160  }
161 
162  // next step is sub-sub-event header
163  sm = sm_header;
164 
165  break;
166 
167  // decode sub-sub-event header
168  case sm_header:
169  pths = decodeSubevent(d);
170  ++datacnt;
171  sm = sm_data;
172 
173  break;
174 
175  // decode sub-sub-event data
176  case sm_data:
177  {
178  ++datacnt;
179 
180  if (d == 0xffffffff)
181  {
182  if (datacnt != datanum)
183  {
184  Error ("execute()", "Event %d --> datanum and datacnt differs. datanum=%lu, datacnt=%lu", nEvt, datanum, datacnt);
185  }
186 
187  sm = sm_wait_for_board;
188 
189  break;
190  }
191  else
192  {
193  switch (pths.design)
194  {
195  case des_cosy13:
196  ptds = decodeData_Cosy13(d, pths);
197  break;
198  case des_140115:
199  ptds = decodeData_140115(d, pths);
200  break;
201  default:
202  continue;
203  }
204  fillRaw (ptds);
205  }
206  }
207  break;
208 
209  default:
210  datacnt = 0;
211  sm = sm_wait_for_board;
212  break;
213  }
214  }
215 
216  // decode subsubevent data of this TRB
217  // .....
218  // call function fillRaw to store the data of a channel
219  // .....
220 
221  return 1;
222 }
223 
224 
226 {
227  ptheaderset pths;
228 
229  bool olddesign = ((h >> 30) & 0x03) == 0x00;
230  if (olddesign)
231  {
232  pths.design = des_cosy13;
233 
234  pths.tsref = h & 0xfff;
235  pths.evcnt = (h >> 12) & 0x3ff;
236  pths.romode = (h >> 22) & 0x3;
237  pths.version = 0;
238  pths.boardid = (h >> 24) & 0xff;
239  }
240  else
241  {
242  pths.design = des_140115;
243 
244  pths.tsref = h & 0xfff;
245  pths.evcnt = (h >> 12) & 0x3ff;
246  pths.romode = (h >> 22) & 0x3;
247  pths.version = (h >> 26) & 0xf;
248  pths.boardid = (h >> 30) & 0x3;
249  }
250 
251  return pths;
252 }
253 
255 {
256  ptdataset ptds;
257  ptds.ts = (d >> 0) & 0xfff;
258  ptds.adc = (d >> 12) & 0xfff;
259  ptds.strip = (d >> 24) & 0x7f;
260  ptds.pileup = (d >> 31) & 0x01;
261  ptds.overflow = 0;
262 
263  return ptds;
264 }
265 
267 {
268  ptdataset ptds;//PR(hs.romode);
269  switch (hs.romode)
270  {
271  case 0x00:
272  ptds.ts = d & 0x7ff;
273  ptds.adc = (d >> 11) & 0xfff;
274  ptds.overflow = (d >> 23) & 0x01;
275  ptds.pileup = (d >> 24) & 0x01;
276  ptds.strip = (d >> 25) & 0x7f;
277  break;
278  case 0x01:
279  ptds.ts = d & 0xfff;
280  ptds.adc = (d >> 11) & 0xffe; // adc[11:1]
281  ptds.overflow = (d >> 23) & 0x01;
282  ptds.pileup = (d >> 24) & 0x01;
283  ptds.strip = (d >> 25) & 0x7f;
284  break;
285  case 0x02:
286  ptds.ts = d & 0x3fff;
287  ptds.adc = (d >> 11) & 0xff8; // adc[11:1]
288  ptds.overflow = (d >> 23) & 0x01;
289  ptds.pileup = (d >> 24) & 0x01;
290  ptds.strip = (d >> 25) & 0x7f;
291  break;
292  case 0x03:
293  ptds.ts = d & 0x3fff;
294  ptds.adc = (d >> 13) & 0xffe; // adc[11:1]
295  ptds.overflow = -1;
296  ptds.pileup = -1;
297  ptds.strip = (d >> 25) & 0x7f;
298  break;
299  default:
300  ptds.ts = -1;
301  ptds.adc = -1;
302  ptds.overflow = -1;
303  ptds.pileup = -1;
304  ptds.strip = 0;
305  break;
306  }
307 
308  return ptds;
309 }
310 
312 {
313  return fillRaw(ptds.strip, ptds.ts, ptds.adc, ptds.pileup, ptds.overflow);
314 }
315 
316 
317 Bool_t HPionTrackerTrb3Unpacker::fillRaw (Int_t channel, Float_t time, Float_t charge, Char_t pileup, Char_t overflow)
318 {
319  // fill the raw category of the PionTracker for the channel "
320 
321  if (pTrbBoard)
322  {
323  HPionTrackerTrb3LookupChan * ch = pTrbBoard->getChannel (channel);
324  ch->getAddress (loc[0], loc[1]);
325 
326  if (loc[0] >= 0)
327  {
328  HPionTrackerRaw * pRaw = (HPionTrackerRaw *) pRawCat->getObject (loc);
329 
330  if (!pRaw)
331  {
332  pRaw = (HPionTrackerRaw *) pRawCat->getSlot (loc);
333 
334 // PRh(pRaw);
335 // if (pRaw) delete pRaw;
336 // PR(pRaw);
337  if (pRaw)
338  {
339 // printf("=== new pRaw\n");
340  pRaw = new (pRaw) HPionTrackerRaw;
341  pRaw->setAddress (loc[0], loc[1]);
342  }
343  else
344  {
345  Warning ("HPionTrackerTrb3Unpacker::execute()",
346  "Can't get slot mod=%i, chan=%i", loc[0], loc[1]);
347  return kFALSE;
348  }
349 
350  }
351 // printf("+ pRaw: %x at %x\n", pRaw, &pRaw);
352 
353  pRaw->setData (time, charge, pileup, overflow);
354  }
355  else
356  {
357  Warning ("HPionTrackerTrb3Unpacker::execute()",
358  "Not found in lookup table: TrbNetAddress=%i, channel=%i", uTrbNetAddress, channel);
359  }
360  }
361 
362  return kTRUE;
363 }
364 
Bool_t fillRaw(const ptdataset &ptds)
UInt_t getEventSeqNumber(void)
Definition: heventheader.h:132
ptdataset decodeData_140115(UInt_t d, const ptheaderset &hs)
UInt_t getId(void)
Definition: heventheader.h:134
const Cat_t catPionTrackerRaw
ClassImp(HPionTrackerTrb3Unpacker) HPionTrackerTrb3Unpacker
HRuntimeDb * getRuntimeDb(void)
Definition: hades.h:111
HEvent *& getCurrentEvent(void)
Definition: hades.cc:422
virtual HEventHeader * getHeader(void) const
Definition: hevent.h:36
Bool_t setData(const Float_t time, const Float_t charge, const Char_t pileup=0, const Char_t overflow=0)
void getAddress(Int_t &m, Int_t &c)
HSpectrometer * getSetup(void)
Definition: hades.h:112
HDetector * getDetector(const Char_t *name)
Hades * gHades
Definition: hades.cc:1213
ptdataset decodeData_Cosy13(UInt_t d, const ptheaderset &hs)
ptheaderset decodeSubevent(UInt_t h)
HParSet * getContainer(const Text_t *)
Definition: hruntimedb.cc:124
HCategory * buildCategory(Cat_t)
void setAddress(const Int_t m, const Int_t s)
Bool_t isCalibration()
Definition: hades.cc:276