FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMBSUnpacker.cxx
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 // ROOT headers
10 #include <TClonesArray.h>
11 
12 // Fair headers
13 #include <FairMQLogger.h>
14 
15 // Land headers
16 #include "FairMBSRawItem.h"
17 #include "FairMBSUnpacker.h"
18 
19 // FairMBSUnpacker: Constructor
20 FairMBSUnpacker::FairMBSUnpacker(Short_t type, Short_t subType, Short_t procId, Short_t subCrate, Short_t control)
21  : FairUnpack(type, subType, procId, subCrate, control)
22  , fRawData(new TClonesArray("FairMBSRawItem"))
23  , fNHits(0)
24  , fNHitsTotal(0)
25 {}
26 
27 // Virtual FairMBSUnpacker: Public method
29 {
30  LOG(info) << "FairMBSUnpacker: Delete instance";
31  delete fRawData;
32 }
33 
34 // Init: Public method
35 Bool_t FairMBSUnpacker::Init() { return kTRUE; }
36 
37 // DoUnpack: Public method
38 Bool_t FairMBSUnpacker::DoUnpack(Int_t* data, Int_t size)
39 {
40  LOG(debug) << "FairMBSUnpacker: Unpacking... size = " << size;
41 
42  Int_t l_i = 0;
43 
44  Int_t n17 = 0;
45 
46  while (l_i < size) {
47  n17 = 0;
48 
49  UInt_t* p1 = reinterpret_cast<UInt_t*>(data + l_i);
50  UInt_t l_sam_id = (p1[0] & 0xf0000000) >> 28; // identifies the sam
51  UInt_t l_gtb_id = (p1[0] & 0x0f000000) >> 24; // 0 or 1, identifies which of the 2 cables of the sam
52  UInt_t l_lec = (p1[0] & 0x00f00000) >> 20;
53  UInt_t l_da_siz = (p1[0] & 0x000001ff);
54 
55  LOG(debug) << "FairMBSUnpacker: SAM: " << l_sam_id << ", GTB: " << l_gtb_id << ", lec: " << l_lec
56  << ", size: " << l_da_siz;
57 
58  l_i += 1;
59 
60  p1 = reinterpret_cast<UInt_t*>(data + l_i);
61 
62  for (UInt_t i1 = 0; i1 < l_da_siz; i1 += 2) {
63  UInt_t tac_addr;
64  UInt_t tac_ch;
65  UInt_t cal;
66  UInt_t clock;
67  UInt_t tac_data;
68  UInt_t qdc_data;
69  tac_addr = (p1[i1] & 0xf8000000) >> 27;
70  tac_ch = (p1[i1] & 0x07c00000) >> 22;
71  cal = (p1[i1] & 0x003C0000) >> 18;
72  clock = 63 - ((p1[i1] & 0x0003f000) >> 12);
73  tac_data = 4095 - ((p1[i1] & 0x00000fff));
74  qdc_data = (p1[i1 + 1] & 0x00000fff);
75  l_i += 2;
76 
77  if (16 == tac_ch) {
78  n17 += 1;
79  }
80  LOG(debug) << "FairMBSUnpacker: TAC ADDR: " << tac_addr << ", TAC CH: " << tac_ch
81  << ", TAC Data: " << tac_data << ", QDC Data: " << qdc_data;
82  new ((*fRawData)[fNHits])
83  FairMBSRawItem(l_sam_id, l_gtb_id, tac_addr, tac_ch, cal, clock, tac_data, qdc_data);
84  fNHits++;
85  }
86 
87  LOG(debug) << "FairMBSUnpacker: n17=" << n17;
88  }
89 
90  LOG(debug) << "FairMBSUnpacker: Number of hits in LAND: " << fNHits;
91 
92  fNHitsTotal += fNHits;
93 
94  return kTRUE;
95 }
96 
97 // Reset: Public method
99 {
100  LOG(debug) << "FairMBSUnpacker: Clearing Data Structure";
101  fRawData->Clear();
102  fNHits = 0;
103 }
104 
virtual Bool_t DoUnpack(Int_t *data, Int_t size)
FairMBSUnpacker(Short_t type=94, Short_t subType=9400, Short_t procId=10, Short_t subCrate=1, Short_t control=3)
ClassImp(FairEventBuilder)
virtual Bool_t Init()
virtual ~FairMBSUnpacker()
virtual void Reset()