MiniballSort
Loading...
Searching...
No Matches
MbsFormat.cc
Go to the documentation of this file.
1#include <algorithm>
2#include "MbsFormat.hh"
3
5
6 fp = nullptr;
7 ptr = nullptr;
8 len = 0;
9 current = -1;
10 bufsize = 0x8000; // default buffer size
11
12 // Set up the trigger types
14 for( unsigned int i = 0; i < MBS_N_TRIGGERS; i++ ) {
15 std::string trigname = "Trig %d" + std::to_string(i);
16 if( i == 14 ) trigname += " (Start)";
17 if( i == 15 ) trigname += " (Stop)";
18 triggers[i].SetType( MBS_L_NAME, trigname, sizeof(s_vehe), sizeof(unsigned short) );
19 }
20
21 // Buffer types
22 buffer_types.push_back( MBSBufferElem( MBS_BTYPE_FHEADER, "File header", sizeof(s_filhe), sizeof(unsigned short) ) );
23 buffer_types.push_back( MBSBufferElem( MBS_BTYPE_VME, "VME buffer", sizeof(s_bufhe), sizeof(unsigned short) ) );
24 buffer_types.push_back( MBSBufferElem( MBS_BTYPE_ERROR, "Illegal buffer type", 0, 0 ) );
25 buffer_types.push_back( MBSBufferElem( 0, "", 0, 0 ) );
26
27 // Event types
28 event_types.push_back( MBSBufferElem( MBS_ETYPE_VME, "Standard MBS event", sizeof(s_vehe), sizeof(unsigned short) ) );
29 event_types.push_back( MBSBufferElem( 0, "", 0, 0 ) );
30
31 // Subevent types
32 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_1, "Chn + Data", sizeof(s_veshe), sizeof(unsigned int)*10 ) );
33 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_WO_ID_1, "Data w/o Chn", sizeof(s_veshe), sizeof(unsigned short) ) );
34 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_2, "Chn + Data", sizeof(s_veshe), sizeof(unsigned int)*10 ) );
35 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_WO_ID_2, "Data w/o Chn", sizeof(s_veshe), sizeof(unsigned short) ) );
36 sevent_types.push_back( MBSBufferElem( MBS_STYPE_TIME_STAMP, "Time stamp", sizeof(s_veshe), sizeof(unsigned int) ) );
37 sevent_types.push_back( MBSBufferElem( MBS_STYPE_DEAD_TIME, "Dead time", sizeof(s_veshe), sizeof(unsigned int) ) );
38 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_DGF_1, "XIA DGF-4C (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
39 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_DGF_2, "XIA DGF-4C (2)", sizeof(s_veshe), sizeof(unsigned short) ) );
40 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_DGF_3, "XIA DGF-4C (3)", sizeof(s_veshe), sizeof(unsigned short) ) );
41 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_SILENA_1, "Silena 4418 (1, zero suppr)", sizeof(s_veshe), sizeof(unsigned short) ) );
42 sevent_types.push_back( MBSBufferElem( MBS_STYPE_CAMAC_SILENA_2, "Silena 4418 (2, zero suppr)", sizeof(s_veshe), sizeof(unsigned short) ) );
43 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_V556_1, "Caen VME ADCs V556 (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
44 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_V556_2, "Caen VME ADCs V556 (2)", sizeof(s_veshe), sizeof(unsigned short) ) );
45 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_V556_3, "Caen VME ADCs V556 (3)", sizeof(s_veshe), sizeof(unsigned short) ) );
46 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_1, "Caen VME ADCs/TDCs (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
47 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_2, "Caen VME ADCs/TDCs (2)", sizeof(s_veshe), sizeof(unsigned short) ) );
48 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_3, "Caen VME ADCs/TDCs (3)", sizeof(s_veshe), sizeof(unsigned short) ) );
49 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_V1X90_1, "Caen VME TDCs V1X90 (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
50 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_V1X90_2, "Caen VME TDCs V1X90 (2)", sizeof(s_veshe), sizeof(unsigned short) ) );
51 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_CAEN_V1X90_3, "Caen VME TDCs V1X90 (3)", sizeof(s_veshe), sizeof(unsigned short) ) );
52 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_1, "SIS VME modules (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
53 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_2, "SIS VME modules (2)", sizeof(s_veshe), sizeof(unsigned short) ) );
54 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_3, "SIS VME modules (3)", sizeof(s_veshe), sizeof(unsigned short) ) );
55 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_3300, "SIS 3300 VME modules", sizeof(s_veshe), sizeof(unsigned short) ) );
56 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_3302_1, "SIS 3302 VME modules (1)", sizeof(s_veshe), sizeof(unsigned long) ) );
57 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_3302_2, "SIS 3302 VME modules (2)", sizeof(s_veshe), sizeof(unsigned long) ) );
58 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_SIS_3302_3, "SIS 3302 VME modules (3)", sizeof(s_veshe), sizeof(unsigned long) ) );
59 sevent_types.push_back( MBSBufferElem( MBS_STYPE_HITBUF_1, "Hitbuffer (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
60 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_MADC_1, "Mesytec MADC modules (1)", sizeof(s_veshe), sizeof(unsigned short) ) );
61 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_MADC_2, "Mesytec MADC modules (2)", sizeof(s_veshe), sizeof(unsigned short) ) );
62 sevent_types.push_back( MBSBufferElem( MBS_STYPE_VME_MADC_3, "Mesytec MADC modules (3)", sizeof(s_veshe), sizeof(unsigned short) ) );
63 sevent_types.push_back( MBSBufferElem( MBS_STYPE_DATA_SHORT, "Plain data (16 bit)", sizeof(s_veshe), sizeof(unsigned short) ) );
64 sevent_types.push_back( MBSBufferElem( MBS_STYPE_DATA_INT, "Plain data (32 bit)", sizeof(s_veshe), sizeof(unsigned short) ) );
65 sevent_types.push_back( MBSBufferElem( MBS_STYPE_DUMMY, "MBS dummy", sizeof(s_veshe), sizeof(unsigned int)*10 ) );
66 sevent_types.push_back( MBSBufferElem( MBS_STYPE_RAW, "Raw data", sizeof(s_veshe), sizeof(unsigned short) ) );
67 sevent_types.push_back( MBSBufferElem( 0, "", 0, 0 ) );
68
69}
70
71// Open an LMD file
72void MBS::OpenLmdFile( std::string _filename ){
73
74 // Close file if already open
75 if(fp) CloseFile();
76
77 // Open file
78 fp = fopen( _filename.data(), "rb" );
79 if( !fp ) {
80 std::cerr << "Unable to open " << _filename << std::endl;
81 return;
82 }
83
84 // Get length of file
85 fseek( fp, 0, SEEK_END );
86 len = ftell(fp);
87
88 // Map into virtual memory
89 ptr = (const UChar_t *)mmap(nullptr, len, PROT_READ, MAP_SHARED, fileno(fp), 0);
90 if( ptr == MAP_FAILED ) {
91
92 std::cerr << __FUNCTION__ << ": Error mapping MBS file " << _filename << std::endl;
93 fclose(fp);
94 fp = nullptr;
95 ptr = nullptr;
96 return;
97
98 }
99
100 // File header
101 fh = (s_filhe *)ptr;
102 fh->Show();
103
104 // Set to first buffer with real data (i.e. skipping file header)
105 GetBuffer(1);
106
107 // Store filename
108 filename = _filename;
109
110}
111
112// Open a MED file
113void MBS::OpenMedFile( std::string _filename ){
114
115 // Close file if already open
116 if(fp) CloseFile();
117
118 // Event type initialisation
119 if( sevent_type_raw == NULL ) {
120
121 for( unsigned int i = 0; i < sevent_types.size(); i++ ) {
122
123 if( sevent_types[i].GetType() == MBS_STYPE_RAW ) {
125 break;
126 }
127
128 }
129
130 }
131
132 // Open file
133 fp = fopen( _filename.data(), "rb" );
134 if( !fp ) {
135 std::cerr << "Unable to open " << _filename << std::endl;
136 return;
137 }
138
139 // Get length of file
140 fseek( fp, 0, SEEK_END );
141 len = ftell(fp);
142
143 // Map into virtual memory
144 ptr = (const UChar_t *)mmap(nullptr, len, PROT_READ, MAP_SHARED, fileno(fp), 0);
145 if( ptr == MAP_FAILED ) {
146
147 std::cerr << __FUNCTION__ << ": Error mapping MED file " << _filename << std::endl;
148 fclose(fp);
149 fp = nullptr;
150 ptr = nullptr;
151 return;
152
153 }
154
155 // MED file byte order is fixed
157 bufsize = 0x4000; // fix byte order for now
158
159 // Store filename
160 filename = _filename;
161
162 // Initialse number of hits
164
165 // Set position to the start of the file
166 pos = 0;
167
168
169}
170
171// Close the file
173
174 if(!fp) return;
175 fclose(fp);
176 fp = nullptr;
177
178}
179
180// Open a stream
181int MBS::OpenEventServer( std::string _server, unsigned short _port ){
182
183 // Get the server and port number
184 server = _server;
185 port = _port;
186
187 // Create to the socket
188 struct sockaddr_in serv_addr;
189 if( !(socket_id = socket( AF_INET, SOCK_STREAM, 0 )) ){
190
191 std::cerr << "Socket creation failed" << std::endl;
192 return -1;
193
194 }
195
196 // Make the address of the server
197 serv_addr.sin_family = AF_INET;
198 serv_addr.sin_port = htons( port );
199 if( inet_pton( AF_INET, server.data(), &serv_addr.sin_addr ) <= 0 ) {
200
201 std::cerr << "Invalid server address " << server << std::endl;
202 return -1;
203
204 }
205
206 // Connect to the server
207 if( (server_id = connect( socket_id, (struct sockaddr*)&serv_addr,
208 sizeof(serv_addr) )) < 0 ) {
209
210 std::cerr << "Failed to connect to " << server << std::endl;
211 return -1;
212
213 }
214
215 return 0;
216
217}
218
220
221 close(server_id);
222
223}
224
226
227 // TODO: This is not correct, probably!!
228 read( socket_id, &ptr, bufsize );
229
230 return ptr;
231
232}
233
234// Get the next event from an LMD file
236
237 // Return nullptr if we've reached the end of the file
238 if( pos + bufsize >= len ) return(nullptr);
239
240 // Check if we need another buffer
241 if( pos >= current_buffer * bufsize + used )
242 if( !GetNextBuffer() ) return(nullptr);
243
244 // Clear old data
245 evt.Clear();
246
247 // Event header (16 bytes, assuming VME)
248 UInt_t *val32 = (UInt_t *)(ptr + pos);
249 UInt_t elen = val32[0]; // l_dlen of event header
250 evtsiz = elen * sizeof(UShort_t) + sizeof(s_evhe);
251 evt.SetEventID( val32[3] ); // l_count of event header
252 vh = (s_vehe *)(ptr + pos);
253 //UInt_t elen = eh->l_dlen;
254 pos += sizeof(s_evhe); // Advance to trigger/counter
255
256 // Subevent header (8 bytes)
257 UInt_t slen = val32[4]; // l_dlen of subevent header
258 //UInt_t slen = vh->l_dlen;
259
260 // Handle the special case, where the subevent header is in the
261 // next buffer
262 if( elen <= 4 ) {
263
264 for( UInt_t i = 2; i < 4; i++ )
265 evt.Store(val32[i]);
266
267 // Next buffer
268 if( !GetNextBuffer() ) return(nullptr);
269 val32 = (UInt_t *)(ptr + pos);
270 elen = val32[0];
271 slen = val32[2];
272 pos += 8;
273
274 }
275
276
277 // Copy payload of event (without event header)
278 for( UInt_t i = 2; i < elen / 2 + 2; i++ )
279 evt.Store(val32[i]);
280 pos += elen * 2; // Advance past this data
281
282 // Check if there's more data in the next buffer
283 while( evt.GetNData() < slen / 2 + 2 ) { // Yes, there's more data
284
285 // Next buffer
286 if( !GetNextBuffer() ) return(nullptr);
287 val32 = (UInt_t *)(ptr + pos);
288 elen = val32[0];
289 for( UInt_t i = 2; i < elen / 2 + 2; i++ )
290 evt.Store(val32[i]);
291 pos += elen * 2 + 8; // Advance past this data
292
293 }
294
295 return(&evt);
296
297};
298
299// Get the next event from a MED file
301
302 // Clear old data
303 evt.Clear();
304
305 // Update buffer count and used bytes (bodge)
306 current_buffer = (float)GetNBuffers() * (float)pos / (float)len;
307 used = pos;
308
309 // Check length
310 if( pos >= len - sizeof(s_evhe) ){
311 std::cerr << "End of file reached whilst trying to get next event" << std::endl;
312 running = false;
313 eof = true;
314 pos = len;
315 return nullptr;
316 }
317
318 // Event header (8 bytes)
319 eh = (s_evhe *)(ptr + pos);
321 evtsiz = elen * sizeof(UShort_t) + sizeof(s_evhe);
322 if( pos + evtsiz > len ) {
323 std::cerr << "End of file before end of event" << std::endl;
324 running = false;
325 eof = true;
326 pos = len;
327 return nullptr;
328 }
329
330 // Check the event type
331 for( unsigned int i = 0; i < event_types.size(); i++ ){
332 if( event_types[i].GetType() == etype ){
335 break;
336 }
337 }
338
339 // Error checking for events
341 std::cerr << "Bad event type = " << etype << std::endl;
342 pos += evtsiz;
343 return(nullptr);
344 }
345
346 // Checking for a start or stop event
347 if( etype == MBS_ETYPE_VME ) {
348
349 // Get VME sub-event header and trigger type
350 vh = (s_vehe *)(ptr + pos);
352
353 // Check we have a valid trigger
355
358 if( trigger_id == 14 ){
359 std::cout << "Start trigger #14" << std::endl;
360 running = true;
361 pos += evtsiz;
362 return(nullptr);
363 }
364 else if( trigger_id == 15 ) {
365 std::cout << "Stop trigger #15" << std::endl;
366 running = false;
367 eof = true;
368 pos += evtsiz;
369 return(nullptr);
370 }
371 }
372
373 // Bad trigger
374 else {
375 std::cerr << "Bad trigger: " << trigger_id << std::endl;
376 pos += evtsiz;
377 return(nullptr);
378 }
379
380 // Advance to sub event
381 pos += sizeof(s_vehe);
382
383 } // VME event
384
385 // Has to be VME event if not an error, but just in case
386 else {
387 pos += evtsiz;
388 return(nullptr);
389 }
390
391 // Loop over all sub-events
392 current_subevt = 0;
393 while( (int)pos < (int)used + evtsiz ){
394
395 // Check sub-event type
396 sh = (s_evhe *)(ptr + pos);
398 if( stype == MBS_STYPE_EOE ){
399 pos += slen*sizeof(unsigned short) + sizeof(s_evhe);
400 break;
401 }
402
403 // VME sub-event header
404 vsh = (s_veshe *)(ptr + pos);
406 UInt_t wc = slen - (sizeof(s_veshe) - sizeof(s_evhe)) / sizeof(unsigned short);
407 pos += sizeof(s_veshe);
408
409 // Now we start the sub events
410 MBSSubEvent mbs_subevt;
411 mbs_subevt.SetSubEventElement( *current_stype );
412 mbs_subevt.SetSubEventID( current_subevt );
413 mbs_subevt.SetDataLength( slen );
414 mbs_subevt.SetProcessorType( control );
415 mbs_subevt.SetCrateID( crateid );
416 mbs_subevt.SetModuleID( procid );
417
418 // Short data types
419 if( current_stype->GetDataSize() == sizeof(unsigned short) ){
420
421 // Sub-event data
422 char *vartmp = (char *)(ptr + pos);
423 auto tmp_val = GetByteSwapShort( vartmp, wc, byteorder );
424 for( int i = 0; i < (int)tmp_val.size(); i++ ){
425 mbs_subevt.AddData( tmp_val[i] );
426 }
427
428 }
429
430 // Integer data types
431 else if( current_stype->GetDataSize() == sizeof(unsigned int) ){
432
433 // Sub-event data
434 char *vartmp = (char *)(ptr + pos);
435 auto tmp_val = GetByteSwapInt( vartmp, wc, byteorder );
436 for( int i = 0; i < (int)tmp_val.size(); i++ ){
437 mbs_subevt.AddData32( tmp_val[i] );
438 }
439
440 }
441
442 // Integer data types, but read as short
443 else if( current_stype->GetDataSize() == sizeof(unsigned int)*10 ){
444
445 // Sub-event data
446 wc *= 2;
447 char *vartmp = (char *)(ptr + pos);
448 auto tmp_val = GetByteSwapShort( vartmp, wc, byteorder );
449 for( int i = 0; i < (int)tmp_val.size(); i++ ){
450 mbs_subevt.AddData( tmp_val[i] );
451 }
452
453 }
454
455 // Long data types
456 else if( current_stype->GetDataSize() == sizeof(unsigned long) ){
457
458 // Sub-event data
459 wc /= 2;
460 char *vartmp = (char *)(ptr + pos);
461 auto tmp_val = GetByteSwapInt( vartmp, wc, byteorder );
462 for( int i = 0; i < (int)tmp_val.size(); i++ ){
463 mbs_subevt.AddData32( tmp_val[i] );
464 }
465
466
467 }
468
469 // Store this sub event
470 if( wc > 0 )
471 evt.StoreSubEvent( mbs_subevt );
472
473
474 // Move the pointer on
475 int nextevt = slen * sizeof(unsigned short);
476 nextevt += sizeof(s_evhe) - sizeof(s_veshe);
477 pos += nextevt;
478
479 // Check if we finished the file
480 if( pos >= len ) {
481 std::cerr << "Reached the end of the file already" << std::endl;
482 return(nullptr);
483 }
484
485 // Increment the subevent counter
487
488 } // finish sub events
489
490 return(&evt);
491
492};
493
494// Get the next event
496
497 // Clear old data
498 evt.Clear();
499
500 // Need to do stuff here
501
502 return(&evt);
503
504
505}
506
507// Get the nth buffer
508const UChar_t* MBS::GetBuffer( UInt_t i ) {
509
510 current_buffer = i;
512 if( pos + bufsize > len ) return(nullptr);
513
514 bh = (s_bufhe *)(ptr + pos);
515 used = bh->i_used * 2 + sizeof(s_bufhe);
516 pos += sizeof(s_bufhe);
517
518 // Check buffer type for med files
519 for( unsigned int i = 0; i < buffer_types.size(); i++ ){
520 if( buffer_types[i].GetType() == (unsigned int)((bh->i_subtype << 16) | bh->i_type) ){
523 break;
524 }
525 }
526
527 // Is it a VME buffer?
529 std::cerr << "Current buffer type incorrect. Expecting ";
530 std::cerr << MBS_BTYPE_VME << " but got " << current_btype->GetType();
531 std::cerr << std::endl;
532 }
533
534 // Store the current buffer timestamp
535 buf_ts = ((long long) bh->l_time[0]) << 32 | ((long long) bh->l_time[1]);
536 if( start_ts == 0 ) start_ts = buf_ts;
537
538 return( ptr + pos - sizeof(s_bufhe) );
539
540};
541
542// Convert event header
544
545 elen = GetByteSwapInt( (char *)&eh->l_dlen, byteorder );
546 std::vector<short> type_tmp = GetByteSwapShort( (char *)&eh->i_type, 2, byteorder );
547
548 etype = (type_tmp[0] << 16) | type_tmp[1];
549
550}
551
552// Check sub event header
554
555 std::vector<short> type_tmp = GetByteSwapShort( (char *)&sh->i_type, 2, byteorder );
556
557 stype = (type_tmp[0] << 16) | type_tmp[1];
558
559 for( unsigned int i = 0; i < sevent_types.size(); i++ ){
560 if( sevent_types[i].GetType() == stype ){
563 break;
564 }
565 }
566
567}
568// Convert sub event header
570
571 slen = GetByteSwapInt( (char *)&vsh->l_dlen, byteorder );
572 std::vector<short> proc_tmp = GetByteSwapShort( (char *)&vsh->i_procid, 2, byteorder );
573
574 procid = proc_tmp[1];
575 crateid = (char)( (proc_tmp[0] >> 8 ) & 0x00ff);
576 control = (char)(proc_tmp[0] & 0x00ff);
577
578}
579
580// Convert VME header
582
583 vlen = GetByteSwapInt( (char *)&vh->l_dlen, byteorder );
584 std::vector<short> type_tmp = GetByteSwapShort( (char *)&vh->i_type, 2, byteorder );
585 std::vector<short> trig_tmp = GetByteSwapShort( (char *)&vh->i_dummy, 2, byteorder);
586 int lcnt_tmp = GetByteSwapInt( (char *)&vh->l_count, byteorder );
587
588 trigger_id = trig_tmp[0]; // just one part of trigger/dummy pair
589 evt.SetEventID( lcnt_tmp ); // l_count of event header
590
591
592}
593
594// Byte order swaps
595std::vector<short> MBS::GetByteSwapShort( char *in, int count, int bo ){
596
597 // Returning a short depending on the byte ordering (bo)
598 std::vector<short> s;
599 char b[2];
600
601 switch( bo ) {
602
603 case BYTE_ORDER_LSW:
605 for( int i = 0; i < count; i++ ) {
606 b[0] = in[i*2+0];
607 b[1] = in[i*2+1];
608 s.push_back( (((short)b[1] << 8) & 0xff00) |
609 ((short)b[0] & 0x00ff) );
610 }
611 break;
612
613 case BYTE_ORDER_REV:
614 case BYTE_ORDER_BSW:
615 for( int i = 0; i < count; i++ ) {
616 b[1] = in[i*2+0];
617 b[0] = in[i*2+1];
618 s.push_back( (((short)b[1] << 8) & 0xff00) |
619 ((short)b[0] & 0x00ff) );
620 }
621 break;
622
623 }
624
625 return s;
626
627};
628
629std::vector<int> MBS::GetByteSwapInt( char *in, int count, int bo ){
630
631 // Returning an int depending on the byte ordering (bo)
632 std::vector<int> s;
633 char b[4];
634
635 switch( bo ) {
636
638 for( int i = 0; i < count; i++ ) {
639 b[0] = in[i*4+0];
640 b[1] = in[i*4+1];
641 b[2] = in[i*4+2];
642 b[3] = in[i*4+3];
643 s.push_back( (((int)b[3] << 24) & 0xff000000) |
644 (((int)b[2] << 16) & 0x00ff0000) |
645 (((int)b[1] << 8) & 0x0000ff00) |
646 ((int)b[0] & 0x000000ff) );
647 }
648 break;
649
650 case BYTE_ORDER_BSW:
651 for( int i = 0; i < count; i++ ) {
652 b[1] = in[i*4+0];
653 b[0] = in[i*4+1];
654 b[3] = in[i*4+2];
655 b[2] = in[i*4+3];
656 s.push_back( (((int)b[3] << 24) & 0xff000000) |
657 (((int)b[2] << 16) & 0x00ff0000) |
658 (((int)b[1] << 8) & 0x0000ff00) |
659 ((int)b[0] & 0x000000ff) );
660 }
661 break;
662
663 case BYTE_ORDER_LSW:
664 for( int i = 0; i < count; i++ ) {
665 b[2] = in[i*4+0];
666 b[3] = in[i*4+1];
667 b[0] = in[i*4+2];
668 b[1] = in[i*4+3];
669 s.push_back( (((int)b[3] << 24) & 0xff000000) |
670 (((int)b[2] << 16) & 0x00ff0000) |
671 (((int)b[1] << 8) & 0x0000ff00) |
672 ((int)b[0] & 0x000000ff) );
673 }
674 break;
675
676
677 case BYTE_ORDER_REV:
678 for( int i = 0; i < count; i++ ) {
679 b[3] = in[i*4+0];
680 b[2] = in[i*4+1];
681 b[1] = in[i*4+2];
682 b[0] = in[i*4+3];
683 s.push_back( (((int)b[3] << 24) & 0xff000000) |
684 (((int)b[2] << 16) & 0x00ff0000) |
685 (((int)b[1] << 8) & 0x0000ff00) |
686 ((int)b[0] & 0x000000ff) );
687 }
688 break;
689
690 }
691
692 return s;
693
694};
695
696std::string MBS::GetByteSwapString( char *in, int count, int bo ){
697
698 // Returning a short depending on the byte ordering (bo)
699 std::string sin;
700 std::string sout;
701
702 if( count <= 0 ) sin = std::string( in, std::strlen(in) );
703 else sin = std::string( in, count );
704
705 switch( bo ) {
706
707 case BYTE_ORDER_REV:
709 sout = sin;
710 break;
711
712 case BYTE_ORDER_LSW:
713 case BYTE_ORDER_BSW:
714 sout = sin;
715 std::reverse( sout.begin(), sout.end() );
716 break;
717
718 }
719
720 return sout;
721
722};
#define MBS_STYPE_VME_CAEN_V556_1
Definition MbsDefines.hh:55
#define MBS_STYPE_VME_SIS_3
Definition MbsDefines.hh:66
#define BYTE_ORDER_LSW
long word swap
#define MBS_STYPE_DEAD_TIME
Definition MbsDefines.hh:83
#define MBS_STYPE_DATA_SHORT
Definition MbsDefines.hh:72
#define MBS_STYPE_VME_CAEN_V1X90_3
Definition MbsDefines.hh:63
#define MBS_STYPE_RAW
Definition MbsDefines.hh:88
#define MBS_STYPE_VME_CAEN_V1X90_1
Definition MbsDefines.hh:61
#define MBS_STYPE_VME_SIS_3302_1
Definition MbsDefines.hh:68
#define MBS_STYPE_VME_SIS_3300
Definition MbsDefines.hh:67
#define MBS_STYPE_VME_CAEN_2
Definition MbsDefines.hh:59
#define MBS_N_TRIGGERS
Definition MbsDefines.hh:94
#define MBS_STYPE_VME_CAEN_V1X90_2
Definition MbsDefines.hh:62
#define MBS_STYPE_CAMAC_DGF_3
Definition MbsDefines.hh:52
#define MBS_STYPE_VME_SIS_3302_2
Definition MbsDefines.hh:69
#define MBS_STYPE_VME_SIS_2
Definition MbsDefines.hh:65
#define BYTE_ORDER_BSW
byte swap
#define MBS_ETYPE_ERROR
Definition MbsDefines.hh:34
#define MBS_STYPE_CAMAC_SILENA_2
Definition MbsDefines.hh:54
#define MBS_ETYPE_VME
Definition MbsDefines.hh:32
#define MBS_STYPE_TIME_STAMP
Definition MbsDefines.hh:82
#define MBS_STYPE_CAMAC_DGF_1
Definition MbsDefines.hh:50
#define MBS_L_NAME
Definition MbsDefines.hh:98
#define MBS_STYPE_VME_SIS_1
Definition MbsDefines.hh:64
#define MBS_BTYPE_FHEADER
Definition MbsDefines.hh:23
#define MBS_STYPE_CAMAC_DGF_2
Definition MbsDefines.hh:51
#define MBS_STYPE_CAMAC_2
Definition MbsDefines.hh:47
#define MBS_BTYPE_VME
Definition MbsDefines.hh:24
#define MBS_STYPE_VME_MADC_2
Definition MbsDefines.hh:77
#define MBS_BTYPE_ERROR
Definition MbsDefines.hh:26
#define MBS_STYPE_HITBUF_1
Definition MbsDefines.hh:75
#define BYTE_ORDER_REV
reverse order
#define MBS_STYPE_CAMAC_1
Definition MbsDefines.hh:44
#define MBS_STYPE_VME_CAEN_V556_3
Definition MbsDefines.hh:57
#define MBS_STYPE_VME_CAEN_V556_2
Definition MbsDefines.hh:56
#define MBS_STYPE_DATA_INT
Definition MbsDefines.hh:73
#define MBS_STYPE_CAMAC_SILENA_1
Definition MbsDefines.hh:53
#define MBS_STYPE_CAMAC_WO_ID_2
Definition MbsDefines.hh:48
#define MBS_STYPE_CAMAC_WO_ID_1
Definition MbsDefines.hh:45
#define BYTE_ORDER_1_TO_1
1:1, nothing to do
#define MBS_STYPE_VME_CAEN_3
Definition MbsDefines.hh:60
#define MBS_STYPE_VME_CAEN_1
Definition MbsDefines.hh:58
#define MBS_STYPE_EOE
Definition MbsDefines.hh:85
#define MBS_STYPE_VME_MADC_3
Definition MbsDefines.hh:78
#define MBS_ETYPE_ABORT
Definition MbsDefines.hh:35
#define MBS_STYPE_DUMMY
Definition MbsDefines.hh:84
#define MBS_STYPE_VME_SIS_3302_3
Definition MbsDefines.hh:70
#define MBS_STYPE_VME_MADC_1
Definition MbsDefines.hh:76
struct s_evhe s_evhe
struct s_vehe s_vehe
struct s_veshe s_veshe
struct s_bufhe s_bufhe
unsigned int GetType() const
Definition MbsFormat.hh:184
void IncrementHit()
Definition MbsFormat.hh:189
int GetDataSize() const
Definition MbsFormat.hh:186
void SetEventID(unsigned long long id)
Definition MbsFormat.hh:303
void StoreSubEvent(MBSSubEvent _sevt)
Definition MbsFormat.hh:312
void Store(UInt_t datum)
Definition MbsFormat.hh:307
size_t GetNData() const
Definition MbsFormat.hh:289
void Clear()
Definition MbsFormat.hh:324
void SetSubEventID(unsigned long id)
Definition MbsFormat.hh:245
void SetSubEventElement(MBSBufferElem _stype)
Definition MbsFormat.hh:244
void SetProcessorType(unsigned char ptype)
Definition MbsFormat.hh:247
void SetDataLength(unsigned int len)
Definition MbsFormat.hh:246
void SetCrateID(unsigned char id)
Definition MbsFormat.hh:248
void AddData(short datum)
Definition MbsFormat.hh:211
void SetModuleID(unsigned short id)
Definition MbsFormat.hh:249
void AddData32(int datum)
Definition MbsFormat.hh:221
UShort_t procid
Definition MbsFormat.hh:397
Int_t vlen
Definition MbsFormat.hh:389
UInt_t socket_id
Definition MbsFormat.hh:352
std::vector< short > GetByteSwapShort(char *in, int count, int bo)
Definition MbsFormat.cc:595
UChar_t byteorder
Definition MbsFormat.hh:394
void CloseFile()
Definition MbsFormat.cc:172
s_evhe * sh
Definition MbsFormat.hh:362
std::string server
Definition MbsFormat.hh:349
Int_t server_id
Definition MbsFormat.hh:353
MBSBufferElem * current_btype
Definition MbsFormat.hh:373
const MBSEvent * GetNextLmdEvent()
Definition MbsFormat.cc:235
s_filhe * fh
Definition MbsFormat.hh:358
void OpenLmdFile(std::string _filename)
Definition MbsFormat.cc:72
long long buf_ts
Definition MbsFormat.hh:367
UInt_t stype
Definition MbsFormat.hh:391
const MBSEvent * GetNextMedEvent()
Definition MbsFormat.cc:300
void OpenMedFile(std::string _filename)
Definition MbsFormat.cc:113
MBSBufferElem * current_stype
Definition MbsFormat.hh:375
UInt_t current_subevt
Definition MbsFormat.hh:355
std::string GetByteSwapString(char *in, int count, int bo)
Definition MbsFormat.cc:696
UInt_t GetNBuffers() const
Definition MbsFormat.hh:417
MBS()
Definition MbsFormat.cc:4
void ConvertVmeHeader()
Definition MbsFormat.cc:581
UChar_t control
Definition MbsFormat.hh:395
int OpenEventServer(std::string _server, unsigned short _port)
Definition MbsFormat.cc:181
const UChar_t * GetNextBuffer()
Definition MbsFormat.hh:428
const UChar_t * ptr
Definition MbsFormat.hh:385
Int_t slen
Definition MbsFormat.hh:388
std::string filename
Definition MbsFormat.hh:348
bool running
Definition MbsFormat.hh:368
s_veshe * vsh
Definition MbsFormat.hh:363
Int_t elen
Definition MbsFormat.hh:387
const UChar_t * GetBufferFromStream()
Definition MbsFormat.cc:225
const MBSEvent * GetNextEventFromStream()
Definition MbsFormat.cc:495
void ConvertEventHeader()
Definition MbsFormat.cc:543
Int_t current
Definition MbsFormat.hh:392
UInt_t pos
Definition MbsFormat.hh:356
bool eof
Definition MbsFormat.hh:369
MBSBufferElem * current_etype
Definition MbsFormat.hh:374
std::vector< MBSBufferElem > event_types
Definition MbsFormat.hh:381
unsigned int trigger_id
Definition MbsFormat.hh:370
UInt_t bufsize
Definition MbsFormat.hh:393
int evtsiz
Definition MbsFormat.hh:365
long long start_ts
Definition MbsFormat.hh:366
size_t len
Definition MbsFormat.hh:386
s_vehe * vh
Definition MbsFormat.hh:361
UInt_t etype
Definition MbsFormat.hh:390
UInt_t used
Definition MbsFormat.hh:364
MBSEvent evt
Definition MbsFormat.hh:357
unsigned short port
Definition MbsFormat.hh:350
s_bufhe * bh
Definition MbsFormat.hh:359
std::vector< MBSBufferElem > sevent_types
Definition MbsFormat.hh:382
void ConvertSubEventHeader()
Definition MbsFormat.cc:569
s_evhe * eh
Definition MbsFormat.hh:360
void ResetHitCount()
Definition MbsFormat.hh:473
MBSBufferElem * current_trigger
Definition MbsFormat.hh:376
FILE * fp
Definition MbsFormat.hh:351
std::vector< MBSBufferElem > buffer_types
Definition MbsFormat.hh:380
void CheckSubEventType()
Definition MbsFormat.cc:553
UInt_t current_buffer
Definition MbsFormat.hh:354
std::vector< MBSBufferElem > triggers
Definition MbsFormat.hh:383
MBSBufferElem * sevent_type_raw
Definition MbsFormat.hh:377
UChar_t crateid
Definition MbsFormat.hh:396
std::vector< int > GetByteSwapInt(char *in, int count, int bo)
Definition MbsFormat.cc:629
const UChar_t * GetBuffer(UInt_t i)
Definition MbsFormat.cc:508
void CloseEventServer()
Definition MbsFormat.cc:219
UShort_t i_type
Type.
Definition MbsFormat.hh:82
UInt_t l_time[2]
64-bit timestamp since 1970
Definition MbsFormat.hh:90
UShort_t i_subtype
Subtype.
Definition MbsFormat.hh:83
UShort_t i_used
Used length of data field in 16-bit words.
Definition MbsFormat.hh:84
UShort_t i_type
Type.
Definition MbsFormat.hh:118
UInt_t l_dlen
Length of data in 16-bit words.
Definition MbsFormat.hh:117
void Show() const
Definition MbsFormat.hh:60
UInt_t l_dlen
Length of data in 16-bit words.
Definition MbsFormat.hh:103
UInt_t l_count
Event number.
Definition MbsFormat.hh:108
UShort_t i_type
Type.
Definition MbsFormat.hh:104
UShort_t i_dummy
Not used.
Definition MbsFormat.hh:106
UInt_t l_dlen
data length + 2 in words
Definition MbsFormat.hh:124
UShort_t i_procid
processor ID
Definition MbsFormat.hh:127