Neutral Particle Spectrometer analysis code
Loading...
Searching...
No Matches
VLDModule.cxx
Go to the documentation of this file.
1
2//
3// 0 block header
4// 1 block trailer
5// 2 slot header
6//
8
9#include "VLDModule.h"
10#include "THaSlotData.h"
11#include "TMath.h"
12#include "CodaDecoder.h" // for coda_format_error
13#include "CodaDecoder.h" // for coda_format_error
14
15#include <unistd.h>
16#include <iostream>
17#include <iomanip>
18#include <numeric>
19#include <cassert>
20#include <stdexcept>
21#include <map>
22#include <sstream>
23
24using namespace std;
25
26//#define DEBUG
27//#define WITH_DEBUG
28
29#ifdef DEBUG
30#include <fstream>
31#endif
32
33namespace Decoder {
34
35using vsiz_t = vector<int>::size_type;
36
37Module::TypeIter_t VLDModule::fgThisType =
38 DoRegister( ModuleType( "Decoder::VLDModule" , 493 ));
39
40//_____________________________________________________________________________
42 : PipeliningModule(crate, slot),
43 vld_header_data{}, vld_data{},
44 block_header_found(false), block_trailer_found(false), slot_header_found(false)
45{
46 IsInit = false;
48}
49
50//_____________________________________________________________________________
51VLDModule::~VLDModule() = default;
52
53//_____________________________________________________________________________
55{
56 // Clear event-by-event data
58 vld_header_data.clear();
59 vld_data.clear();
60
61 // Initialize data_type_def to FILLER and data types to false
62 data_type_def = 15;
63 // Initialize data types to false
65}
66
67//_____________________________________________________________________________
69{
70 Module::Init();
71#if defined DEBUG && defined WITH_DEBUG
72 // This will make a HUGE output
73 delete fDebugFile; fDebugFile = 0;
74 fDebugFile = new ofstream;
75 fDebugFile->open(string("VLD_debug.txt"));
76#endif
77 //fDebugFile=0;
78 Clear();
79 IsInit = kTRUE;
80 fName = "VLD";
81
82}
83
84//_____________________________________________________________________________
85inline
86void VLDModule::DecodeBlockHeader( UInt_t pdat, uint32_t data_type_id )
87{
88 if( data_type_id ) {
89 block_header_found = true; // Set to true if found
90 vld_header_data.num_vld = (pdat >> 16) & 0x1F; // Number of VLD that are readout in this block, mask 5 bits
91 vld_header_data.read_count = (pdat >> 8) & 0xFF; // Number of times data has been read from VLD shared memory, mask 8 bits
92 vld_header_data.write_count = (pdat >> 0) & 0xFF; // Number of times data has been written to VLD shared memory, mask 8 bits
93 // Debug output
94#ifdef WITH_DEBUG
95 if( fDebugFile )
96 *fDebugFile << "VLDModule::Decode:: VLD BLOCK HEADER"
97 << " >> data = " << hex << pdat << dec
98 << " >> num_vld = " << vld_header_data.num_vld
99 << " >> read count = " << vld_header_data.read_count
100 << " >> write count = " << vld_header_data.write_count
101 << endl;
102#endif
103 }
104}
105
106//_____________________________________________________________________________
108{
109 block_trailer_found = true;
110 vld_header_data.nwords_inblock = (pdat >> 0) & 0xFFFF; // Total number of words in block, mask 16 bits
111 // Debug output
112#ifdef WITH_DEBUG
113 if( fDebugFile )
114 *fDebugFile << "VLDModule::Decode:: VLD BLOCK TRAILER"
115 << " >> data = " << hex << pdat << dec
116 << " >> nwords in block = " << vld_header_data.nwords_inblock
117 << endl;
118#endif
119}
120
121//_____________________________________________________________________________
122void VLDModule::DecodeSlotHeader( UInt_t pdat , uint32_t data_type_id )
123{
124 if( data_type_id ) { // word 1
125 slot_header_found = true;
126 vld_header_data.slotid = (pdat >> 16) & 0x1F; // Slot number (set by VME64x backplane), mask 5 bits
127 vld_header_data.nconnect = (pdat >> 8) & 0xFF; // Number of connector data words to follow (4 x 2 = current), mask 8 bits
128#ifdef WITH_DEBUG
129 if( fDebugFile )
130 *fDebugFile << "VLDModule::Decode:: VLD SLOT HEADER"
131 << " >> data = " << hex << pdat << dec
132 << " >> slot ID = " << vld_header_data.slotid
133 << " >> num connector words = " << vld_header_data.nconnect
134 << endl;
135#endif
136 }
137 else { // continuation words
138 uint32_t connectid = (pdat >> 28) & 0x7; // ID of VLD connector [0, 3], mask 3 bits
139 uint32_t lohi = (pdat >> 24) & 0x1; // The Low (0) or High (1) 18 channels of the connector
140 uint32_t chnmask = (pdat >> 0) & 0x3FFFF; // Mask of channels with VLD pulse enabled
141
142 vld_data.connectid.push_back( connectid );
143 vld_data.lohi.push_back( lohi );
144 vld_data.chnmask.push_back( chnmask );
145#ifdef WITH_DEBUG
146 if( fDebugFile )
147 *fDebugFile << "VLDModule::Decode:: VLD SLOT DATA"
148 << " >> data = " << hex << pdat << dec
149 << " >> slot ID = " << vld_header_data.slotid
150 << " >> num connector words = " << vld_header_data.nconnect
151 << " >> num connector id = " << connectid
152 << " >> num lo/hi bit = " << lohi
153 << " >> channel mask = " << chnmask
154 << endl;
155#endif
156 }
157}
158
159//_____________________________________________________________________________
160void VLDModule::UnsupportedType( UInt_t pdat, uint32_t data_type_id )
161{
162
163 // Handle unsupported, invalid, or irrelevant/non-decodable data types
164#ifdef WITH_DEBUG
165 // Data type descriptions
166 ostringstream str;
167 str << "VLDModule::Decode:: UNDEFINED TYPE"
168 << " >> data = " << hex << pdat << dec
169 << " >> data type id = " << data_type_id
170 << endl;
171 if( fDebugFile )
172 *fDebugFile << str.str();
173
174 cerr << str.str() << endl;
175#endif
176}
177
178//_____________________________________________________________________________
180{
181 assert(pdat);
182 uint32_t data = *pdat;
183
184 uint32_t data_type_id = (data >> 31) & 0x1; // Data type identification, mask 1 bit
185 if( data_type_id == 1 )
186 data_type_def = (data >> 27) & 0xF; // Data type defining words, mask 4 bits
187
188 // Debug output
189#ifdef WITH_DEBUG
190 if( fDebugFile )
191 *fDebugFile << "VLDModule::Decode:: VLD DATA TYPES"
192 << " >> data = " << hex << data << dec
193 << " >> data word id = " << data_type_id
194 << " >> data type = " << data_type_def
195 << endl;
196
197#endif
198
199
200 // Acquire data objects depending on the data type defining word
201 switch( data_type_def ) {
202 case 0: // Block header, indicates the beginning of a block of events
203 DecodeBlockHeader(data, data_type_id);
204 break;
205 case 1: // Block trailer, indicates the end of a block of events
207 break;
208 case 2: // Slot header
209 DecodeSlotHeader(data, data_type_id);
210 break;
211 default:
212#ifdef WITH_DEBUG
213 UnsupportedType(data, data_type_id);
214#endif
215 break;
216 } // data_type_def switch
217
218#ifdef WITH_DEBUG
219 if( fDebugFile )
220 *fDebugFile << "**********************************************************************"
221 << "\n" << endl;
222#endif
223
224 return block_trailer_found;
225}
226
227//_____________________________________________________________________________
229{
230
231 // Load THaSlotData
232
233 for( vsiz_t iclus = 0; iclus < vld_data.connectid.size(); iclus++ )
234 sldat->loadData("scaler", 0, vld_data.connectid[iclus], vld_data.connectid[iclus]);
235 for( vsiz_t iclus = 0; iclus < vld_data.lohi.size(); iclus++ )
236 sldat->loadData("scaler", 0, vld_data.lohi[iclus], vld_data.lohi[iclus]);
237 for( vsiz_t iclus = 0; iclus < vld_data.chnmask.size(); iclus++ )
238 sldat->loadData("scaler", 0, vld_data.chnmask[iclus], vld_data.chnmask[iclus]);
239
240}
241
242//_____________________________________________________________________________
244 const UInt_t* pstop )
245{
246 // Load from evbuffer between [evbuffer,pstop]
247 return LoadSlot(sldat, evbuffer, 0, pstop + 1 - evbuffer);
248
249}
250
251//_____________________________________________________________________________
253 UInt_t pos, UInt_t len)
254{
255
256 // Load from bank data in evbuffer between [pos,pos+len)
257 const auto* p = evbuffer + pos;
258 const auto* q = p + len;
259 while( p != q ) {
260 if( Decode(p++) == 1 )
261 break; // block trailer found
262 }
263
264
265 LoadTHaSlotDataObj(sldat);
266
267 return fWordsSeen = p - (evbuffer + pos);
268}
269
270//_____________________________________________________________________________
271// Helper function for debugging
272static void PrintBlock( const uint32_t* codabuffer, uint32_t pos, uint32_t len )
273{
274 size_t idx = pos;
275 while( idx < pos+len ) {
276 while( idx < pos+len && !TESTBIT(codabuffer[idx], 31) )
277 ++idx;
278 if( idx == pos+len )
279 break;
280 uint32_t data = codabuffer[idx];
281 uint32_t type = (data >> 27) & 0xF;
282 switch( type ) {
283 case 0:
284 cout << "Block header"
285 << " idx = " << idx
286 << " num_vld = " << ((data >> 16) & 0x1F)
287 << " read = " << ((data >> 8) & 0xFF)
288 << " write = " << (data & 0xFF);
289 break;
290 case 1:
291 cout << "Block trailer"
292 << " idx = " << idx
293 << " nwords = " << (data & 0x3FFFFF);
294 break;
295 case 2:
296 cout << " Slot header"
297 << " idx = " << idx
298 << " slot = " << ((data >> 16) & 0x1F)
299 << " nwords = " << (data & 0xFF);
300 break;
301 default:
302 cout << " Type = " << type
303 << " idx = " << idx;
304 break;
305 }
306 cout << endl;
307 ++idx;
308 }
309}
310
311//_____________________________________________________________________________
313 UInt_t pos, UInt_t len )
314{
315 // Load event block. The VLD module does not provide multi-block data.
316
317 if( fDebug > 1 ) // Set fDebug via module config string in db_cratemap.dat
318 PrintBlock(evbuffer, pos, len);
319
320 // Find block header. The VLDModule block header does not contain the slot;
321 // instead, all slot data are sent in a single block, preceded by slot headers.
322 auto ibeg = FindIDWord(evbuffer, pos, len, kBlockHeader);
323 if( ibeg == -1 )
324 // No block header - something is quite wrong ...
326 "VLDModule::LoadBank: Missing block header. Call expert.");
327
328 fBlockHeader = evbuffer[ibeg]; // save for convenience
329
330 // Find end of block and let the module decode the event
331 Long64_t iend = ibeg+1;
332 while( true ) {
333 iend = FindIDWord(evbuffer, iend, len + pos - iend, kBlockTrailer);
334 if( (iend = VerifyBlockTrailer(evbuffer, pos, len, ibeg, iend)) > 0 )
335 break;
336 if( iend == 0 )
337 return 0;
338 iend = -iend;
339 }
340 assert( ibeg >= pos && iend > ibeg && iend < pos+len ); // trivially
341
342 return LoadSlot(sldat, evbuffer, ibeg, iend+1-ibeg);
343}
344
345//_____________________________________________________________________________
347{
348 // This method should never be called for this module type
349 throw logic_error("VLDModule::LoadNextEvBuffer called. This module "
350 "does not support multi-block mode. Call expert.");
351}
352
353//_____________________________________________________________________________
354
355
356} // namespace Decoder
357
int Int_t
unsigned int UInt_t
const Bool_t kTRUE
const char Option_t
#define TESTBIT(n, i)
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
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 type
ClassImp(VDC::AnalyticTTDConv) using namespace std
float * q
string::size_type pos
std::vector< uint32_t > lohi
Definition VLDModule.h:0
std::vector< uint32_t > chnmask
Definition VLDModule.h:0
std::vector< uint32_t > connectid
Definition VLDModule.h:0
std::ofstream * fDebugFile
static Long64_t FindIDWord(const uint32_t *buf, size_t start, size_t len, uint32_t type)
virtual void Clear(Option_t *opt="")
Long64_t VerifyBlockTrailer(const UInt_t *evbuffer, UInt_t pos, UInt_t len, Long64_t ibeg, Long64_t iend) const
Int_t loadData(const char *type, UInt_t chan, UInt_t dat, UInt_t raw)
virtual ~VLDModule()
virtual void Clear(Option_t *opt="")
Definition VLDModule.cxx:54
void DecodeSlotHeader(UInt_t pdat, uint32_t data_type_id)
Bool_t block_header_found
Definition VLDModule.h:60
void DecodeBlockTrailer(UInt_t pdat)
virtual UInt_t LoadSlot(THaSlotData *sldat, const UInt_t *evbuffer, const UInt_t *pstop)
static TypeIter_t fgThisType
Definition VLDModule.h:69
virtual Int_t Decode(const UInt_t *data)
void UnsupportedType(UInt_t pdat, uint32_t data_type_id)
void DecodeBlockHeader(UInt_t pdat, uint32_t data_type_id)
Definition VLDModule.cxx:86
virtual UInt_t LoadNextEvBuffer(THaSlotData *sldat)
virtual UInt_t LoadBank(THaSlotData *sldat, const UInt_t *evbuffer, UInt_t pos, UInt_t len)
virtual void Init()
Definition VLDModule.cxx:68
Bool_t block_trailer_found
Definition VLDModule.h:60
void LoadTHaSlotDataObj(THaSlotData *sldat)
Bool_t slot_header_found
Definition VLDModule.h:60
TString fName
long long Long64_t
vector< int >::size_type vsiz_t
Definition VTPModule.cxx:38
static void PrintBlock(const uint32_t *codabuffer, uint32_t pos, uint32_t len)
STL namespace.