SND@LHC Software
Loading...
Searching...
No Matches
PixelUnpack.cxx
Go to the documentation of this file.
1#include <cassert>
2
3// ROOT headers
4#include "TClonesArray.h"
5
6// Fair headers
7#include "FairRootManager.h"
8#include "FairRunOnline.h"
9#include "FairLogger.h"
10
11// SHiP headers
12#include "PixelUnpack.h"
13#include "ShipPixelHit.h"
15
16struct HitData {
17 uint16_t relative_BCID : 4;
18 uint16_t flags : 4;
19 uint16_t moduleID : 4;
20 uint16_t tot : 4;
21};
22struct ChannelId {
23 uint16_t column : 7;
24 uint16_t row : 9;
25};
26
27// PixelUnpack: Constructor
28PixelUnpack::PixelUnpack(uint16_t PartitionId)
29 : fRawData(new TClonesArray("ShipPixelHit")), fNHits(0), fNHitsTotal(0), fPartitionId(PartitionId)
30{
31}
32
33// Virtual PixelUnpack: Public method
35{
36 LOG(INFO) << "PixelUnpack: Delete instance";
37 delete fRawData;
38}
39
40// Init: Public method
42{
43 Register();
44 return kTRUE;
45}
46
47// Register: Protected method
49{
50 LOG(INFO) << "PixelUnpack : Registering...";
51 auto *fMan = FairRootManager::Instance();
52 if (!fMan) {
53 return;
54 }
55 fMan->Register("Digi_PixelHits", "Pixels", fRawData, kTRUE);
56}
57
58// DoUnpack: Public method
59Bool_t PixelUnpack::DoUnpack(Int_t *data, Int_t size)
60{
61 LOG(INFO) << "PixelUnpack : Unpacking frame... size/bytes = " << size;
62
63 auto df = reinterpret_cast<DataFrame *>(data);
64 switch (df->header.frameTime) {
65 case SoS: LOG(INFO) << "PixelUnpacker: SoS frame."; return kTRUE;
66 case EoS: LOG(INFO) << "PixelUnpacker: EoS frame."; return kTRUE;
67 default: break;
68 }
69 assert(df->header.size == size);
70 auto nhits = df->getHitCount();
71 std::vector<RawDataHit> hits(df->hits, df->hits + nhits);
72 for (auto &&hit : hits) {
73 auto hitData = reinterpret_cast<HitData *>(&(hit.hitTime));
74 auto channelId = reinterpret_cast<ChannelId *>(&(hit.channelId));
75 auto detectorID = (df->header.partitionId%0x0800) * 10000000 + 1000000 * hitData->moduleID + 1000 * channelId->row + channelId->column;
76 auto tot = hitData->tot;
77 new ((*fRawData)[fNHits]) ShipPixelHit(detectorID, tot); //tot is measured in steps of 25 ns
78 fNHits++;
79 }
80
82 return kTRUE;
83}
84
85// Reset: Public method
87{
88 LOG(DEBUG) << "PixelUnpack : Clearing Data Structure" ;
89 fRawData->Clear();
90 fNHits = 0;
91}
92
Int_t fNHitsTotal
Definition PixelUnpack.h:44
virtual void Register() override
virtual Bool_t DoUnpack(Int_t *data, Int_t size) override
virtual void Reset() override
virtual ~PixelUnpack()
virtual Bool_t Init() override
TClonesArray * fRawData
Definition PixelUnpack.h:42
PixelUnpack(uint16_t PartitionId)
ClassImp(ecalContFact) ecalContFact
uint16_t column
uint16_t row
uint16_t flags
uint16_t relative_BCID
uint16_t moduleID
uint16_t tot