| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | # include "na64sw-config.h" | ||
| 2 | # include "na64util/na64/event-id.h" | ||
| 3 | |||
| 4 | # include <stdio.h> | ||
| 5 | # include <stdlib.h> | ||
| 6 | # include <string.h> | ||
| 7 | # include <printf.h> | ||
| 8 | |||
| 9 | #define define_event_field_limits( type, name, nBits, offset, bitmask, ... ) \ | ||
| 10 | const na64sw_ ## name ## _t na64sw_g_ ## name ## _max = (1 << nBits) - 1; | ||
| 11 | NA64SW_FOR_ALL_EVENT_ID_FIELDS( define_event_field_limits ) | ||
| 12 | #undef define_event_field_limits | ||
| 13 | |||
| 14 | #define impl_event_id_field_get_set( type, name, nBits, offset, bitmask, ... ) \ | ||
| 15 | na64sw_ ## name ## _t na64sw_get_ ## name ( na64sw_EventID_t eid ) { \ | ||
| 16 | return (eid & bitmask) >> offset; \ | ||
| 17 | } \ | ||
| 18 | void na64sw_set_ ## name ( na64sw_EventID_t * eidPtr, na64sw_ ## name ## _t v ) { \ | ||
| 19 | *eidPtr &= ~bitmask; \ | ||
| 20 | v &= (bitmask >> offset); \ | ||
| 21 | *eidPtr |= (((na64sw_EventID_t) v) << offset); \ | ||
| 22 | } | ||
| 23 | 326 | NA64SW_FOR_ALL_EVENT_ID_FIELDS( impl_event_id_field_get_set ) | |
| 24 | #undef impl_event_id_field_get_set | ||
| 25 | |||
| 26 | na64sw_EventID_t | ||
| 27 | 50 | na64sw_assemble_event_id( na64sw_runNo_t runNo | |
| 28 | , na64sw_spillNo_t spillNo | ||
| 29 | , na64sw_eventNo_t eventNo | ||
| 30 | ) { | ||
| 31 | 50 | na64sw_EventID_t res = 0x0; | |
| 32 | 50 | na64sw_set_runNo( &res, runNo ); | |
| 33 | 50 | na64sw_set_spillNo( &res, spillNo ); | |
| 34 | 50 | na64sw_set_eventNo( &res, eventNo ); | |
| 35 | 50 | return res; | |
| 36 | } | ||
| 37 | |||
| 38 | size_t | ||
| 39 | 3 | na64sw_eid2str( na64sw_EventID_t eid | |
| 40 | , char * buf, size_t buflen) { | ||
| 41 | 6 | return snprintf( buf, buflen | |
| 42 | , "%hu/%hu.%u" | ||
| 43 | , na64sw_get_runNo( eid ) | ||
| 44 | 3 | , na64sw_get_spillNo( eid ) | |
| 45 | , na64sw_get_eventNo( eid ) | ||
| 46 | ); | ||
| 47 | } | ||
| 48 | |||
| 49 | na64sw_EventID_t | ||
| 50 | 1 | na64sw_str2eid( const char * bf, char ** eventEnd ) { | |
| 51 | 1 | na64sw_EventID_t r = 0x0; | |
| 52 | char * runEnd | ||
| 53 | , * spillEnd | ||
| 54 | ; | ||
| 55 | /* parse run number */ | ||
| 56 | 1 | long int parsed = strtol( bf, &runEnd, 10 ); | |
| 57 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if( *runEnd != '/' |
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | || parsed > na64sw_g_runNo_max ) { |
| 59 | ✗ | goto parsingFailed; | |
| 60 | } | ||
| 61 | 1 | na64sw_set_runNo( &r, parsed ); | |
| 62 | |||
| 63 | /* parse spill number */ | ||
| 64 | 1 | parsed = strtol( runEnd + 1, &spillEnd, 10 ); | |
| 65 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if( *spillEnd != '.' |
| 66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | || parsed > na64sw_g_spillNo_max ) { |
| 67 | ✗ | goto parsingFailed; | |
| 68 | } | ||
| 69 | 1 | na64sw_set_spillNo( &r, parsed ); | |
| 70 | |||
| 71 | /* parse event number */ | ||
| 72 | 1 | parsed = strtol( spillEnd + 1, eventEnd, 10 ); | |
| 73 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if( parsed > na64sw_g_eventNo_max ) { |
| 74 | ✗ | goto parsingFailed; | |
| 75 | } | ||
| 76 | 1 | na64sw_set_eventNo( &r, parsed ); | |
| 77 | |||
| 78 | 1 | return r; | |
| 79 | |||
| 80 | ✗ | parsingFailed: | |
| 81 | ✗ | r = 0x0; | |
| 82 | ✗ | na64sw_set_reservedBit( &r, 1 ); | |
| 83 | ✗ | return r; | |
| 84 | } | ||
| 85 | |||
| 86 |