FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FairMBSUnpack.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 "FairLogger.h"
14 #include "FairRootManager.h"
15 
16 // Land headers
17 #include "FairMBSRawItem.h"
18 #include "FairMBSUnpack.h"
19 
20 FairMBSUnpack::FairMBSUnpack(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 
28 {
29  LOG(info) << "FairMBSUnpack: Delete instance";
30  delete fRawData;
31 }
32 
34 {
35  Register();
36  return kTRUE;
37 }
38 
40 {
41  // LOG(debug) << "Registering";
42  LOG(info) << "FairMBSUnpack : Registering...";
44  if (!fMan) {
45  return;
46  }
47  fMan->Register("MBSRawItem", "MBS", fRawData, kTRUE);
48 }
49 
50 // DoUnpack: Public method
51 Bool_t FairMBSUnpack::DoUnpack(Int_t* data, Int_t size)
52 {
53  LOG(debug) << "FairMBSUnpack : Unpacking... size = " << size;
54 
55  Int_t l_i = 0;
56 
57  Int_t n17 = 0;
58 
59  while (l_i < size) {
60  n17 = 0;
61 
62  UInt_t* p1 = reinterpret_cast<UInt_t*>(data + l_i);
63  UInt_t l_sam_id = (p1[0] & 0xf0000000) >> 28; // identifies the sam
64  UInt_t l_gtb_id = (p1[0] & 0x0f000000) >> 24; // 0 or 1, identifies which of the 2 cables of the sam
65  UInt_t l_lec = (p1[0] & 0x00f00000) >> 20;
66  UInt_t l_da_siz = (p1[0] & 0x000001ff);
67 
68  LOG(debug) << "FairMBSUnpack : SAM:" << l_sam_id << ", GTB:" << l_gtb_id << ", lec:" << l_lec
69  << ", size:" << l_da_siz;
70 
71  l_i += 1;
72 
73  p1 = reinterpret_cast<UInt_t*>((data + l_i));
74 
75  for (UInt_t i1 = 0; i1 < l_da_siz; i1 += 2) {
76  UInt_t tac_addr;
77  UInt_t tac_ch;
78  UInt_t cal;
79  UInt_t clock;
80  UInt_t tac_data;
81  UInt_t qdc_data;
82  tac_addr = (p1[i1] & 0xf8000000) >> 27;
83  tac_ch = (p1[i1] & 0x07c00000) >> 22;
84  cal = (p1[i1] & 0x003C0000) >> 18;
85  clock = 63 - ((p1[i1] & 0x0003f000) >> 12);
86  tac_data = 4095 - ((p1[i1] & 0x00000fff));
87  qdc_data = (p1[i1 + 1] & 0x00000fff);
88  l_i += 2;
89 
90  if (16 == tac_ch) {
91  n17 += 1;
92  }
93  LOG(debug) << "FairMBSUnpack : TAC ADDR IS " << tac_addr << ", TAC CH IS " << tac_ch << ", TAC Data IS "
94  << tac_data << ", QDC Data IS " << qdc_data;
95  new ((*fRawData)[fNHits])
96  FairMBSRawItem(l_sam_id, l_gtb_id, tac_addr, tac_ch, cal, clock, tac_data, qdc_data);
97  fNHits++;
98  }
99 
100  LOG(debug) << "FairMBSUnpack : n17=" << n17;
101  }
102 
103  LOG(debug) << "FairMBSUnpack : Number of hits in LAND: " << fNHits;
104 
105  fNHitsTotal += fNHits;
106 
107  return kTRUE;
108 }
109 
110 // Reset: Public method
112 {
113  LOG(debug) << "FairMBSUnpack : Clearing Data Structure";
114  fRawData->Clear();
115  fNHits = 0;
116 }
117 
virtual Bool_t DoUnpack(Int_t *data, Int_t size)
FairMBSUnpack(Short_t type=94, Short_t subType=9400, Short_t procId=10, Short_t subCrate=1, Short_t control=3)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual Bool_t Init()
virtual void Register()
virtual void Reset()
virtual ~FairMBSUnpack()
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)