Neutral Particle Spectrometer analysis code
Loading...
Searching...
No Matches
VTPModule.cxx
Go to the documentation of this file.
1
2//
3// 0 block header
4// 1 block trailer
5// 2 event header
6// 3 trigger time
7// 12 cluster
8// 13 trigger decision
9// 14 data not valid (empty module)
10// 15 filler (non-data) word
11//
13
14#include "VTPModule.h"
15#include "THaSlotData.h"
16#include "TMath.h"
17
18#include <unistd.h>
19#include <iostream>
20#include <iomanip>
21#include <numeric>
22#include <cassert>
23#include <stdexcept>
24#include <map>
25#include <sstream>
26
27using namespace std;
28
29//#define DEBUG
30//#define WITH_DEBUG
31
32#ifdef DEBUG
33#include <fstream>
34#endif
35
36namespace Decoder {
37
38using vsiz_t = vector<int>::size_type;
39
40Module::TypeIter_t VTPModule::fgThisType =
41 DoRegister( ModuleType( "Decoder::VTPModule" , 514 ));
42
43//_____________________________________________________________________________
45 : PipeliningModule(crate, slot),
46 vtp_header_data{}, vtp_trigger_data{}, vtp_cluster_data{},
47 block_header_found(false), block_trailer_found(false),
48 event_header_found(false), slots_match(false)
49{
50 IsInit = false;
52}
53
54//_____________________________________________________________________________
55VTPModule::~VTPModule() = default;
56
57//_____________________________________________________________________________
59{
60 // Clear event-by-event data
62 vtp_header_data.clear();
63 vtp_trigger_data.clear();
64 vtp_cluster_data.clear();
65
66 // Initialize data_type_def to FILLER and data types to false
67 data_type_def = 15;
68 // Initialize data types to false
70}
71
72//_____________________________________________________________________________
74{
75 Module::Init();
76#if defined DEBUG && defined WITH_DEBUG
77 // This will make a HUGE output
78 delete fDebugFile; fDebugFile = 0;
79 fDebugFile = new ofstream;
80 fDebugFile->open(string("VTP_debug.txt"));
81#endif
82 //fDebugFile=0;
83 Clear();
84 IsInit = kTRUE;
85 fName = "VTP";
86}
87
88//_____________________________________________________________________________
90{
91 // Truncate to 32 bits
92 UInt_t shorttime = vtp_header_data.trig_time;
93#ifdef WITH_DEBUG
94 if( fDebugFile )
95 *fDebugFile << "VTPModule::GetTriggerTime = "
96 << vtp_header_data.trig_time << " " << shorttime << endl;
97#endif
98 return shorttime;
99}
100
101//_____________________________________________________________________________
102inline
103void VTPModule::DecodeBlockHeader( UInt_t pdat, uint32_t data_type_id )
104{
105 static const string here{ "VTPModule::DecodeBlockHeader" };
106
107 if( data_type_id ) {
108 block_header_found = true; // Set to true if found
109 vtp_header_data.slot_blk_hdr = (pdat >> 22) & 0x1F; // Slot number (set by VME64x backplane), mask 5 bits
110 // Debug output
111#ifdef WITH_DEBUG
112 if( fDebugFile )
113 *fDebugFile << "VTPModule::Decode:: Slot from VTP block header = " << vtp_header_data.slot_blk_hdr << endl;
114#endif
115 // Ensure that slots from cratemap and VTP match
116 slots_match = ((uint32_t) fSlot == vtp_header_data.slot_blk_hdr);
117 if( !slots_match )
118 return;
119 vtp_header_data.iblock_num = (pdat >> 8) & 0x3FF; // Event block number, mask 10 bits
120 vtp_header_data.nblock_events = (pdat >> 0) & 0xFF; // Number of events in block, mask 8 bits
121 // Debug output
122#ifdef WITH_DEBUG
123 if( fDebugFile )
124 *fDebugFile << "VTPModule::Decode:: VTP BLOCK HEADER"
125 << " >> data = " << hex << pdat << dec
126 << " >> slot = " << vtp_header_data.slot_blk_hdr
127 << " >> event block number = " << vtp_header_data.iblock_num
128 << " >> num events in block = " << vtp_header_data.nblock_events
129 << endl;
130#endif
131 }
132}
133
134//_____________________________________________________________________________
136{
137 block_trailer_found = true;
138 vtp_header_data.slot_blk_trl = (pdat >> 22) & 0x1F; // Slot number (set by VME64x backplane), mask 5 bits
139 vtp_header_data.nwords_inblock = (pdat >> 0) & 0x3FFFFF; // Total number of words in block of events, mask 22 bits
140 // Debug output
141#ifdef WITH_DEBUG
142 if( fDebugFile )
143 *fDebugFile << "VTPModule::Decode:: VTP BLOCK TRAILER"
144 << " >> data = " << hex << pdat << dec
145 << " >> slot = " << vtp_header_data.slot_blk_trl
146 << " >> nwords in block = " << vtp_header_data.nwords_inblock
147 << endl;
148#endif
149}
150
151//_____________________________________________________________________________
153{
154 event_header_found = true;
155 vtp_header_data.trig_num = (pdat >> 0) & 0x3FFFFF; // Trigger number, mask 22 bits
156#ifdef WITH_DEBUG
157 if( fDebugFile )
158 *fDebugFile << "VTPModule::Decode:: VTP EVENT HEADER"
159 << " >> data = " << hex << pdat << dec
160 << " >> trigger number = " << vtp_header_data.trig_num
161 << endl;
162#endif
163}
164
165//_____________________________________________________________________________
166void VTPModule::DecodeTriggerTime( UInt_t pdat, uint32_t data_type_id )
167{
168 if( data_type_id ) // Trigger time word 1
169 vtp_header_data.trig_time_w1 = (pdat >> 0) & 0xFFFFFF; // Time = T_D T_E T_F
170 else // Trigger time word 2
171 vtp_header_data.trig_time_w2 = (pdat >> 0) & 0xFFFFFF; // Time = T_A T_B T_C
172 // Time = T_A T_B T_C T_D T_E T_F
173 vtp_header_data.trig_time = (vtp_header_data.trig_time_w2 << 24) | vtp_header_data.trig_time_w1;
174 // Debug output
175#ifdef WITH_DEBUG
176 if( fDebugFile )
177 *fDebugFile << "VTPModule::Decode:: VTP TRIGGER TIME"
178 << " >> data = " << hex << pdat << dec
179 << " >> trigger time word 1 = " << vtp_header_data.trig_time_w1
180 << " >> trigger time word 2 = " << vtp_header_data.trig_time_w2
181 << " >> trigger time = " << vtp_header_data.trig_time
182 << endl;
183#endif
184}
185
186//_____________________________________________________________________________
187 void VTPModule::DecodeTriggerDecision( UInt_t pdat, uint32_t data_type_id )
188 {
189 uint32_t tpattern = 0;
190 uint32_t ttime = 0;
191 uint32_t ttype0 = 0;
192 uint32_t ttype1 = 0;
193 uint32_t ttype2 = 0;
194 uint32_t ttype3 = 0;
195 uint32_t ttype4 = 0;
196 uint32_t ttype5 = 0;
197
198 if( data_type_id ) { // trigger decision word 1
199
200 tpattern = (pdat >> 0) & 0xFFFF; // trigger pattern, mask 16 bits
201 ttime = (pdat >> 16) & 0x7F; // trigger time, mask 11 bits
202
203 if( (tpattern >> 0 ) & 0x1 ) ttype0 = 1;
204 if( (tpattern >> 1 ) & 0x1 ) ttype1 = 1;
205 if( (tpattern >> 2 ) & 0x1 ) ttype2 = 1;
206 if( (tpattern >> 3 ) & 0x1 ) ttype3 = 1;
207 if( (tpattern >> 4 ) & 0x1 ) ttype4 = 1;
208 if( (tpattern >> 5 ) & 0x1 ) ttype5 = 1;
209
210 // cout << " tpattern = " << tpattern << endl;
211 vtp_trigger_data.trigtype0.push_back( ttype0 );
212 vtp_trigger_data.trigtype1.push_back( ttype1 );
213 vtp_trigger_data.trigtype2.push_back( ttype2 );
214 vtp_trigger_data.trigtype3.push_back( ttype3 );
215 vtp_trigger_data.trigtype4.push_back( ttype4 );
216 vtp_trigger_data.trigtype5.push_back( ttype5 );
217 vtp_trigger_data.trigtime.push_back( ttime );
218 }
219
220#ifdef WITH_DEBUG
221 if( fDebugFile )
222 *fDebugFile << "VTPModule::Decode:: VTP Trigger"
223 << " >> data = " << hex << pdat << dec
224 << " >> trig0 = " << ttype0
225 << " >> trig1 = " << ttype1
226 << " >> trig2 = " << ttype2
227 << " >> trig time = " << ttime
228 << endl;
229#endif
230 }
231
232 //_____________________________________________________________________________
233 void VTPModule::DecodeCluster( UInt_t pdat, uint32_t data_type_id )
234 {
235 uint32_t ce = 0;
236 uint32_t ct = 0;
237 uint32_t cn = 0;
238 uint32_t cx = 0;
239 uint32_t cy = 0;
240
241 if( data_type_id ) { // cluster word 1
242 ce = (pdat >> 0) & 0x3FFF; // cluster energy, mask 14 bits
243 vtp_cluster_data.energy.push_back( ce );
244 }
245 else { // ckuster word 2
246 ct = (pdat >> 0) & 0x7FF; // cluster time, mask 11 bits
247 cn = (pdat >> 11) & 0xF; // cluster n blocks, mask 4 bits
248 cx = (pdat >> 15) & 0x1F; // cluster x coordinate, mask 5 bits
249 cy = (pdat >> 20) & 0x3F; // cluster y coordinate, mask 6 bits
250 vtp_cluster_data.time.push_back( ct );
251 vtp_cluster_data.nblocks.push_back( cn );
252 vtp_cluster_data.xcoord.push_back( cx );
253 vtp_cluster_data.ycoord.push_back( cy );
254 }
255
256#ifdef WITH_DEBUG
257 if( fDebugFile )
258 *fDebugFile << "VTPModule::Decode:: VTP Cluster"
259 << " >> data = " << hex << pdat << dec
260 << " >> energy = " << ce
261 << " >> n blocks = " << cn
262 << " >> time = " << ct
263 << " >> x coordinate = " << cx
264 << " >> y coordinate = " << cy
265 << endl;
266#endif
267}
268
269
270//_____________________________________________________________________________
271void VTPModule::UnsupportedType( UInt_t pdat, uint32_t data_type_id )
272{
273 // Handle unsupported, invalid, or irrelevant/non-decodable data types
274#ifdef WITH_DEBUG
275 // Data type descriptions
276 static const vector<string> what_text{ "UNDEFINED TYPE",
277 "DATA NOT VALID",
278 "FILLER WORD",
279 "INCORRECT DECODING" };
280 // Lookup table data_type -> message number
281 static const map<uint32_t, uint32_t> what_map = {
282 // undefined type
283 { 4, 0 },
284 { 5, 0 },
285 { 6, 0 },
286 { 7, 0 },
287 { 8, 0 },
288 { 9, 0 },
289 { 10, 0 },
290 { 11, 0 },
291 // data not valid
292 { 14, 1 },
293 // filler word
294 { 15, 2 }
295 };
296 auto idx = what_map.find(data_type_def);
297 // Message index. The last message means this function was called when
298 // it shouldn't have been called, i.e. coding error in DecodeOneWord
299 size_t i = (idx == what_map.end()) ? what_text.size() - 1 : idx->second;
300 const string& what = what_text[i];
301 ostringstream str;
302 str << "VTPModule::Decode:: " << what
303 << " >> data = " << hex << pdat << dec
304 << " >> data type id = " << data_type_id
305 << endl;
306 if( fDebugFile )
307 *fDebugFile << str.str();
308 if( idx == what_map.end() )
309 cerr << str.str();
310#endif
311}
312
313//_____________________________________________________________________________
315{
316 assert(pdat);
317 uint32_t data = *pdat;
318 uint32_t data_type_id = (data >> 31) & 0x1; // Data type identification, mask 1 bit
319 if( data_type_id == 1 )
320 data_type_def = (data >> 27) & 0xF; // Data type defining words, mask 4 bits
321
322 // Debug output
323#ifdef WITH_DEBUG
324 if( fDebugFile )
325 *fDebugFile << "VTPModule::Decode:: VTP DATA TYPES"
326 << " >> data = " << hex << data << dec
327 << " >> data word id = " << data_type_id
328 << " >> data type = " << data_type_def
329 << endl;
330
331#endif
332
333 // Ensure that slots match and do not decode if they differ.
334 // This should never happen if PipeliningModule::LoadBank selected the
335 // correct bank.
336 if( !slots_match && data_type_def != 0 ) {
337#ifdef WITH_DEBUG
338 if( fDebugFile )
339 *fDebugFile << "VTPModule::Decode:: "
340 << "fSlot & VTP slot do not match AND data type != 0"
341 << endl;
342#endif
343 return -1;
344 }
345
346 // Acquire data objects depending on the data type defining word
347 switch( data_type_def ) {
348 case 0: // Block header, indicates the beginning of a block of events
349 DecodeBlockHeader(data, data_type_id);
350 break;
351 case 1: // Block trailer, indicates the end of a block of events
353 break;
354 case 2: // Event header, indicates start of an event, includes the trigger number
356 break;
357 case 3: // Trigger time, time of trigger occurrence relative to the most recent global reset
358 DecodeTriggerTime(data, data_type_id);
359 break;
360 break;
361 case 12: // cluster
362 DecodeCluster(data, data_type_id);
363 break;
364 case 13: // trigger decision
365 DecodeTriggerDecision(data, data_type_id);
366 break;
367 case 4: // Undefined type
368 case 5: // Undefined type
369 case 6: // Undefined type
370 case 7: // Undefined type
371 case 8: // Undefined type
372 case 9: // Undefined type
373 case 10: // Undefined type
374 case 11: // Undefined type
375 case 14: // Data not valid
376 case 15: // Filler Word, should be ignored
377 UnsupportedType(data, data_type_id);
378 break;
379 default:
380 throw logic_error("VTPModule: incorrect masking of data_type_def");
381 } // data_type_def switch
382
383#ifdef WITH_DEBUG
384 if( fDebugFile )
385 *fDebugFile << "**********************************************************************"
386 << "\n" << endl;
387#endif
388 return block_trailer_found;
389}
390
391//_____________________________________________________________________________
393{
394 // Load THaSlotData
395
396 // trigger data
397 for( vsiz_t itrig = 0; itrig < vtp_trigger_data.trigtype0.size(); itrig++ )
398 sldat->loadData("scaler", 0, vtp_trigger_data.trigtype0[itrig], vtp_trigger_data.trigtype0[itrig]);
399 for( vsiz_t itrig = 0; itrig < vtp_trigger_data.trigtype1.size(); itrig++ )
400 sldat->loadData("scaler", 0, vtp_trigger_data.trigtype1[itrig], vtp_trigger_data.trigtype1[itrig]);
401 for( vsiz_t itrig = 0; itrig < vtp_trigger_data.trigtype2.size(); itrig++ )
402 sldat->loadData("scaler", 0, vtp_trigger_data.trigtype2[itrig], vtp_trigger_data.trigtype2[itrig]);
403 for( vsiz_t itrig = 0; itrig < vtp_trigger_data.trigtime.size(); itrig++ )
404 sldat->loadData("scaler", 0, vtp_trigger_data.trigtime[itrig], vtp_trigger_data.trigtime[itrig]);
405
406 // cluster data
407 for( vsiz_t iclus = 0; iclus < vtp_cluster_data.energy.size(); iclus++ )
408 sldat->loadData("scaler", 0, vtp_cluster_data.energy[iclus], vtp_cluster_data.energy[iclus]);
409 for( vsiz_t iclus = 0; iclus < vtp_cluster_data.time.size(); iclus++ )
410 sldat->loadData("scaler", 0, vtp_cluster_data.time[iclus], vtp_cluster_data.time[iclus]);
411 for( vsiz_t iclus = 0; iclus < vtp_cluster_data.nblocks.size(); iclus++ )
412 sldat->loadData("scaler", 0, vtp_cluster_data.nblocks[iclus], vtp_cluster_data.nblocks[iclus]);
413 for( vsiz_t iclus = 0; iclus < vtp_cluster_data.xcoord.size(); iclus++ )
414 sldat->loadData("scaler", 0, vtp_cluster_data.xcoord[iclus], vtp_cluster_data.xcoord[iclus]);
415 for( vsiz_t iclus = 0; iclus < vtp_cluster_data.ycoord.size(); iclus++ )
416 sldat->loadData("scaler", 0, vtp_cluster_data.ycoord[iclus], vtp_cluster_data.ycoord[iclus]);
417
418}
419
420//_____________________________________________________________________________
422 const UInt_t* pstop )
423{
424 // Load from evbuffer between [evbuffer,pstop]
425 return LoadSlot(sldat, evbuffer, 0, pstop + 1 - evbuffer);
426}
427
428//_____________________________________________________________________________
430 UInt_t pos, UInt_t len)
431{
432 // Load from bank data in evbuffer between [pos,pos+len)
433 const auto* p = evbuffer + pos;
434 const auto* q = p + len;
435 while( p != q ) {
436 if( Decode(p++) == 1 )
437 break; // block trailer found
438 }
439
440 LoadTHaSlotDataObj(sldat);
441
442 return fWordsSeen = p - (evbuffer + pos);
443}
444
445//_____________________________________________________________________________
446
447
448} // namespace Decoder
449
int Int_t
unsigned int UInt_t
const Bool_t kTRUE
const char Option_t
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
ClassImp(VDC::AnalyticTTDConv) using namespace std
float * q
string::size_type pos
std::ofstream * fDebugFile
virtual void Clear(Option_t *opt="")
Int_t loadData(const char *type, UInt_t chan, UInt_t dat, UInt_t raw)
void DecodeTriggerDecision(UInt_t pdat, uint32_t data_type_id)
Bool_t block_header_found
Definition VTPModule.h:78
void LoadTHaSlotDataObj(THaSlotData *sldat)
virtual void Clear(Option_t *opt="")
Definition VTPModule.cxx:58
virtual void Init()
Definition VTPModule.cxx:73
void DecodeCluster(UInt_t pdat, uint32_t data_type_id)
virtual ~VTPModule()
Bool_t block_trailer_found
Definition VTPModule.h:78
void UnsupportedType(UInt_t pdat, uint32_t data_type_id)
void DecodeEventHeader(UInt_t pdat)
virtual UInt_t LoadSlot(THaSlotData *sldat, const UInt_t *evbuffer, const UInt_t *pstop)
void DecodeBlockTrailer(UInt_t pdat)
void DecodeTriggerTime(UInt_t pdat, uint32_t data_type_id)
virtual UInt_t GetHeaderTriggerTime()
Definition VTPModule.cxx:89
Bool_t event_header_found
Definition VTPModule.h:78
static TypeIter_t fgThisType
Definition VTPModule.h:93
virtual Int_t Decode(const UInt_t *data)
void DecodeBlockHeader(UInt_t pdat, uint32_t data_type_id)
TString fName
vector< int >::size_type vsiz_t
Definition VTPModule.cxx:38
STL namespace.