SND@LHC Software
Loading...
Searching...
No Matches
ShipOnlineDataFormat.h
Go to the documentation of this file.
1#ifndef ONLINE_SHIPONLINEDATAFORMAT_H
2#define ONLINE_SHIPONLINEDATAFORMAT_H
3
4#include <cstdint>
5#include <cassert>
6#include <iostream>
7
8struct RawDataHit {
9 uint16_t channelId; // Channel Identifier
10 uint16_t hitTime; // Hit time, coarse 25ns based time in MSByte, fine time in LSByte
11 uint16_t extraData[0]; // Optional subdetector specific data items
12};
13
15 uint16_t size; // Length of the data frame in bytes (including header).
16 uint16_t partitionId; // Identifier of the subdetector and partition.
17 uint32_t cycleIdentifier; // SHiP cycle identifier as received from TFC.
18 uint32_t frameTime; // Frame time in 25ns clock periods
19 uint16_t timeExtent; // sequential trigger number
20 uint16_t flags; // Version, truncated, etc.
21};
22
23struct DataFrame {
26 // DataFrameHeader
27 // Address of first raw data hit.
28 // for a partition with a fixed hit structure size, the actual number of hits is given by
29 // the frame size and the hit size:
30 int getHitCount() { return (header.size - sizeof(header)) / sizeof(RawDataHit); }
31};
32
33namespace DriftTubes {
34struct ChannelId {
35 uint16_t channel : 8;
36 uint16_t TDC : 4;
37 uint16_t edge : 1;
38 uint16_t padding : 3;
39 int GetDetectorId() const
40 {
41 bool trigger = false;
42 bool beamcounter = false;
43 bool RC_signal = false;
44 bool scintillatorA = false;
45 bool scintillatorB = false;
46 bool master_trigger = false;
47 bool blacklisted = false;
48 int module = 0;
49 int station = 0;
50 int channel_offset = 0;
51 switch (TDC) {
52 case 0:
53 trigger = channel == 126;
54 scintillatorA = channel == 127;
55 station = (channel < 96) ? 1 : 2;
56 module = (channel / 48) % 2;
57 blacklisted = channel >= 120;
58 break;
59 case 1:
60 trigger = channel == 0;
61 scintillatorA = channel == 1;
62 station = (channel < 80) ? 2 : 4;
63 channel_offset = (channel < 80) ? 112 : 1;
64 channel_offset += (channel >= 32 && channel < 48) ? +16 : (channel >= 48 && channel < 64) ? -16 : 0;
65 blacklisted = channel < 8;
66 blacklisted |= channel >= 128;
67 break;
68 case 2:
69 trigger = channel == 126;
70 scintillatorB = channel == 127;
71 station = 4;
72 channel_offset = -119;
73 module = (channel / 48) % 3 + 1;
74 blacklisted = channel >= 120;
75 break;
76 case 3:
77 trigger = channel == 0;
78 scintillatorB = channel == 1;
79 station = (channel < 32) ? 4 : 3;
80 channel_offset = (channel < 32) ? 1 : 33;
81 module = ((channel + 16) / 48 + 3) % 4;
82 blacklisted = channel < 8;
83 blacklisted |= channel >= 128;
84 break;
85 case 4:
86 trigger = channel == 96;
87 RC_signal = channel == 97 || channel == 98;
88 master_trigger = channel == 99;
89 beamcounter = channel > 111;
90 module = (channel / 48) % 2 + 2;
91 channel_offset = (channel < 48) * 33;
92 station = 3;
93 blacklisted = channel >= 96;
94 break;
95 }
96 if (trigger) {
97 return 0;
98 } else if (master_trigger) {
99 return 1;
100 } else if (beamcounter || RC_signal) {
101 return -1;
102 } else if (scintillatorA) {
103 return 6;
104 } else if (scintillatorB) {
105 return 7;
106 } else if(blacklisted) {
107 return -2;
108 }
109 bool reverse_x = !(station == 2 || (TDC == 4 && channel >= 48));
110 int _channel = channel + channel_offset;
111 _channel += (_channel < 0) * 0x80;
112 _channel = reverse_x ? (0x80 - _channel % 0x80) % 0x80 : _channel;
113 if (TDC == 0 && channel < 96) {
114 _channel += _channel ? 63 : 191;
115 } else if (TDC == 3 && channel < 96) {
116 _channel += (channel < 32) ? 24 : 32;
117 }
118 if (TDC == 1) {
119 module = (_channel / 48) % 2;
120 }
121
122 int view = (station == 1 || station == 2) * module % 2;
123 int plane = (TDC == 2) ? ((_channel % 48) / 24 + 1) % 2
124 : (station == 3 && TDC == 4) ? 1 - (channel % 48) / 24 : (_channel % 48) / 24;
125 if (station == 4 && TDC == 3) {
126 plane -= 1;
127 }
128 int layer = (TDC == 4) ? 1 - (channel % 24) / 12 : (_channel % 24) / 12;
129 int straw = _channel % 12 + ((station == 3 || station == 4) ? 1 + (3 - module) * 12 : 1);
130 return station * 10000000 + view * 1000000 + plane * 100000 + layer * 10000 + 2000 + straw;
131 };
133 {
134 bool trigger = false;
135 bool beamcounter = false;
136 bool RC_signal = false;
137 bool master_trigger = false;
138 int module = 0;
139 int station = 0;
140 int module_channel = 0;
141 switch (TDC) {
142 case 0:
143 trigger = channel == 126 || channel == 120;
144 RC_signal = channel == 121 || channel == 122;
145 master_trigger = channel == 123;
146 station = 3;
147 module = (channel < 96) ? 2 + (channel / 48) % 2 : 0;
148 module_channel = channel % 48;
149 //reverse front end board
150 if(module == 3) module_channel = 12*(module_channel/12)+(11-module_channel%12);
151 break;
152 case 1:
153 trigger = channel == 0;
154 beamcounter = channel >=2 && channel <= 5;
155 station = (channel < 80) ? 3 : 4;
156 module = (channel >= 32 && channel < 80) ? 1 : 0;
157 module_channel = (channel + 16) % 48;
158 //cable swap
159 if(module==1) module_channel += ( module_channel < 16 ) ? 16 : ( module_channel < 32 ) ? -16 : 0;
160 break;
161 case 2:
162 trigger = channel == 126;
163 station = 4;
164 module = (channel / 48) + 1 ;
165 module_channel = channel % 48;
166 break;
167 case 3:
168 trigger = channel == 0;
169 station = (channel < 32 || channel >= 80) ? 4 : 3;
170 module = (channel < 32 ) ? 3 : 4;
171 module_channel = (channel + 16) % 48;
172 break;
173 }
174 if (trigger) {
175 return 0;
176 } else if (master_trigger) {
177 return 1;
178 } else if (beamcounter || RC_signal) {
179 return -1;
180 }
181
182 int plane = 1 - (module_channel / 24);
183 int layer = 1 - (module_channel % 24) / 12;
184 int straw = (module >= 4 ? module : 3 - module) * 12 + (11 - (module_channel % 12)) + 1;
185
186 return station * 10000000 + plane * 100000 + layer * 10000 + 2000 + straw;
187 };
188};
189enum Flag : uint16_t {
191 TDC0_PROBLEM = 1 << 1,
192 TDC1_PROBLEM = 1 << 2,
193 TDC2_PROBLEM = 1 << 3,
194 TDC3_PROBLEM = 1 << 4,
195 TDC4_PROBLEM = 1 << 5,
196 NoTrigger = 1<<12,
197 NoWidth = 1<<13,
198 NoDelay = 1<<14,
199 InValid = 1<<15,
200};
201} // namespace DriftTubes
202
203enum MagicFrameTime { SoS = 0xFF005C03, EoS = 0xFF005C04 };
204
205#endif
RawDataHit hits[0]
DataFrameHeader header
uint16_t extraData[0]