SND@LHC Software
Loading...
Searching...
No Matches
ShipTdcSource Class Reference

#include <ShipTdcSource.h>

Inheritance diagram for ShipTdcSource:
Collaboration diagram for ShipTdcSource:

Public Member Functions

 ShipTdcSource ()
 
 ShipTdcSource (TString filename)
 
 ShipTdcSource (const ShipTdcSource &source)
 
virtual ~ShipTdcSource ()
 
virtual Bool_t Init ()
 
virtual Int_t ReadEvent (UInt_t=0)
 
virtual void Close ()
 
void FillEventHeader (FairEventHeader *feh)
 
void AddUnpacker (uint16_t partitionId, FairUnpack *unpacker)
 

Protected Member Functions

Bool_t Unpack (Int_t *data, Int_t size, uint16_t partitionId)
 
Int_t UnpackEventFrame (Int_t *data, Int_t total_size)
 

Protected Attributes

TFile * fIn
 
unsigned char buffer [UINT16_MAX]
 
Double_t fEventTime = 0
 
std::map< uint16_t, FairUnpack * > fUnpackerMap {}
 
TString fFilename
 

Detailed Description

Definition at line 13 of file ShipTdcSource.h.

Constructor & Destructor Documentation

◆ ShipTdcSource() [1/3]

ShipTdcSource::ShipTdcSource ( )

Definition at line 8 of file ShipTdcSource.cxx.

8: fFilename("tdcdata.bin") {}
TString fFilename

◆ ShipTdcSource() [2/3]

ShipTdcSource::ShipTdcSource ( TString  filename)
explicit

Definition at line 10 of file ShipTdcSource.cxx.

10: fFilename(std::move(filename)) {}

◆ ShipTdcSource() [3/3]

ShipTdcSource::ShipTdcSource ( const ShipTdcSource source)

Definition at line 12 of file ShipTdcSource.cxx.

12: FairOnlineSource(source) {}

◆ ~ShipTdcSource()

ShipTdcSource::~ShipTdcSource ( )
virtualdefault

Member Function Documentation

◆ AddUnpacker()

void ShipTdcSource::AddUnpacker ( uint16_t  partitionId,
FairUnpack *  unpacker 
)
inline

Definition at line 24 of file ShipTdcSource.h.

25 {
26 fUnpackerMap[partitionId] = unpacker;
27 fUnpackers->Add(unpacker);
28 }
std::map< uint16_t, FairUnpack * > fUnpackerMap

◆ Close()

void ShipTdcSource::Close ( )
virtual

Definition at line 22 of file ShipTdcSource.cxx.

23{
24 LOG(DEBUG) << "Closing file " << fFilename;
25 fIn->Close();
26}

◆ FillEventHeader()

void ShipTdcSource::FillEventHeader ( FairEventHeader *  feh)

Definition at line 106 of file ShipTdcSource.cxx.

107{
108 // TODO add frame times per partition?, -1 if not present?
109 feh->SetEventTime(fEventTime);
110 feh->SetRunId(fRunId);
111 return;
112}
Double_t fEventTime

◆ Init()

Bool_t ShipTdcSource::Init ( )
virtual

Definition at line 16 of file ShipTdcSource.cxx.

17{
18 fIn = TFile::Open(fFilename + "?filetype=raw", "read");
19 return kTRUE;
20}

◆ ReadEvent()

Int_t ShipTdcSource::ReadEvent ( UInt_t  = 0)
virtual

Definition at line 51 of file ShipTdcSource.cxx.

52{
53 auto df = new (buffer) DataFrame();
54 if (!fIn->ReadBuffer(reinterpret_cast<char *>(df), sizeof(DataFrame))) {
55 size_t size = df->header.size;
56 auto frameTime = df->header.frameTime;
57 uint16_t partitionId = df->header.partitionId;
58 if (!fIn->ReadBuffer(reinterpret_cast<char *>(df->hits), size - sizeof(DataFrame))) {
59 switch (frameTime) {
60 case SoS: LOG(INFO) << "ShipTdcSource: SoS frame."; return 2;
61 case EoS: LOG(INFO) << "ShipTdcSource: EoS frame."; break;
62 default: break;
63 }
64 fEventTime = double(frameTime) * 25;
65 if (partitionId == 0x8000) {
66 LOG(DEBUG) << "ShipTdcSource: Event builder meta frame.";
67 if (fEventTime > 5000000000 && frameTime != EoS && frameTime != SoS) {
68 LOG(WARNING) << "Late event:";
69 for (int i = 0; i < size; i++) {
70 if (i % 4 == 0) {
71 std::cout << ' ';
72 } else if (i % 16 == 0) {
73 std::cout << '\n';
74 }
75 std::cout << std::hex << +buffer[i] << std::dec;
76 }
77 std::cout << std::endl;
78 }
79 return UnpackEventFrame(reinterpret_cast<Int_t *>(&buffer), size);
80 }
81 LOG(DEBUG) << "ShipTdcSource: PartitionId " << std::hex << partitionId << std::dec;
82
83 if (Unpack(reinterpret_cast<Int_t *>(&buffer), size, partitionId)) {
84 return (frameTime == EoS) ? 1 : 0;
85 }
86 LOG(WARNING) << "ShipTdcSource: Failed to Unpack.";
87 LOG(WARNING) << "ShipTdcSource: Maybe missing unpacker for PartitionId " << std::hex << partitionId << std::dec;
88 return 3;
89 }
90 LOG(WARNING) << "ShipTdcSource: Failed to read hits.";
91 return 2;
92 }
93 return 1;
94}
unsigned char buffer[UINT16_MAX]
Bool_t Unpack(Int_t *data, Int_t size, uint16_t partitionId)
Int_t UnpackEventFrame(Int_t *data, Int_t total_size)
int i
Definition ShipAna.py:86
integer, parameter double
Definition mpdef.f90:38

◆ Unpack()

Bool_t ShipTdcSource::Unpack ( Int_t *  data,
Int_t  size,
uint16_t  partitionId 
)
protected

Definition at line 96 of file ShipTdcSource.cxx.

97{
98 try {
99 return fUnpackerMap.at(partitionId)->DoUnpack(data, size);
100 } catch (const std::out_of_range &oor) {
101 LOG(WARNING) << "ShipTdcSource: Failed to find suitable unpacker.";
102 return kFALSE;
103 }
104}

◆ UnpackEventFrame()

Int_t ShipTdcSource::UnpackEventFrame ( Int_t *  data,
Int_t  total_size 
)
protected

Definition at line 28 of file ShipTdcSource.cxx.

29{
30 auto mf = reinterpret_cast<DataFrame *>(data);
31 total_size -= sizeof(DataFrame);
32 data = reinterpret_cast<Int_t *>(&(mf->hits));
33 auto frameTime = mf->header.frameTime;
34 while (total_size > 0) {
35 auto df = reinterpret_cast<DataFrame *>(data);
36 Int_t size = df->header.size;
37 uint16_t partitionId = df->header.partitionId;
38 LOG(DEBUG) << "ShipTdcSource: PartitionId " << std::hex << partitionId << std::dec;
39 if (!Unpack(data, size, partitionId)) {
40 LOG(WARNING) << "ShipTdcSource: Failed to Unpack.";
41 LOG(WARNING) << "ShipTdcSource: Maybe missing unpacker for PartitionId " << std::hex << partitionId << std::dec;
42 return 3;
43 }
44 data += size / sizeof(Int_t);
45 total_size -= size;
46 }
47 assert(total_size == 0);
48 return (frameTime == EoS) ? 1 : 0;
49}

Member Data Documentation

◆ buffer

unsigned char ShipTdcSource::buffer[UINT16_MAX]
protected

Definition at line 34 of file ShipTdcSource.h.

◆ fEventTime

Double_t ShipTdcSource::fEventTime = 0
protected

Definition at line 35 of file ShipTdcSource.h.

◆ fFilename

TString ShipTdcSource::fFilename
protected

Definition at line 38 of file ShipTdcSource.h.

◆ fIn

TFile* ShipTdcSource::fIn
protected

Definition at line 33 of file ShipTdcSource.h.

◆ fUnpackerMap

std::map<uint16_t, FairUnpack *> ShipTdcSource::fUnpackerMap {}
protected

Definition at line 36 of file ShipTdcSource.h.

36{};

The documentation for this class was generated from the following files: