GCC Code Coverage Report


Directory: ./
File: include/na64util/na64/event-id.hh
Date: 2025-09-01 06:19:01
Exec Total Coverage
Lines: 7 7 100.0%
Functions: 5 5 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /* This file is a part of NA64SW software.
2 * Copyright (C) 2015-2022 NA64 Collaboration, CERN
3 *
4 * NA64SW is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 #pragma once
18
19 # include "na64util/na64/event-id.h"
20
21 # include <iostream>
22 # include <set>
23 # include <utility>
24
25 namespace na64dp {
26
27 /**\brief Event ID C++ wrapper around numerical type
28 *
29 * \todo Uncommon event ID ctr for identifier type bearing information of
30 * physical event data layout
31 * */
32 class EventID {
33 private:
34 na64sw_EventID_t _eid;
35 public:
36 /// Default ctr, creates event ID of `{0, 0, 0}`
37 71 EventID() : _eid(0) {}
38 /// Common event ID ctr, makes "chunkless" event identifier
39 50 EventID( na64sw_runNo_t runNo
40 , na64sw_spillNo_t spillNo
41 , na64sw_eventNo_t evNo )
42 50 : _eid(na64sw_assemble_event_id(runNo, spillNo, evNo)) {}
43 /// Copy ctr, initialized underlying struct
44 20 explicit EventID( const na64sw_EventID_t & eid ) : _eid(eid) {}
45 /// Implicit `to-number` cast operator
46 247 operator na64sw_EventID_t () const { return _eid; }
47 #if 0
48 /// Copies full ID by copying numerical value
49 EventID & operator=( na64sw_EventID_t nid ) {
50 _eid = nid;
51 return *this;
52 }
53 #endif
54 /// Returns run number of an event being identified
55 na64sw_runNo_t run_no() const { return na64sw_get_runNo(_eid); }
56 /// Sets the run number of an event being identified
57 void run_no( na64sw_runNo_t rn ) { na64sw_set_runNo( &_eid, rn ); }
58 /// Returns spill number of an event being identified
59 na64sw_spillNo_t spill_no() const { return na64sw_get_spillNo(_eid); }
60 /// Sets the spill number of an event being identified
61 void spill_no( na64sw_spillNo_t sn ) { na64sw_set_spillNo(&_eid, sn); }
62 /// Returns the event's in-spill number of an event being identified
63 na64sw_eventNo_t event_no() const { return na64sw_get_eventNo(_eid); }
64 /// Sets the event's in-spill number of an event being identified
65 void event_no( na64sw_eventNo_t en ) { na64sw_set_eventNo(&_eid, en); }
66 /// Returns `std::string` copying from internal buffer
67 std::string to_str() const;
68 /// Reads the event ID from string assuming its default str format
69 static EventID from_str( const std::string & );
70 };
71
72 inline bool
73 88 operator<(const EventID & a, const EventID & b) {
74 88 return ((na64sw_EventID_t) a) < ((na64sw_EventID_t) b);
75 }
76
77 std::ostream & operator<<( std::ostream & stream, const EventID & );
78
79 namespace util {
80 void reset(EventID &);
81 }
82
83 namespace event {
84 template<typename T, typename> struct Traits; // fwd
85 template<typename T> struct Stream; // fwd
86
87 template<>
88 struct Traits<EventID, void> {
89 template<typename StreamImplT>
90 static void stream_op( Stream<StreamImplT> & ds, EventID & v ) {
91 if( StreamImplT::isInput ) {
92 na64sw_runNo_t eid;
93 ds.impl().template scalar<na64sw_runNo_t>(eid);
94 v = EventID(eid);
95 } else {
96 ds.impl().template scalar<EventID>(v);
97 }
98 }
99 };
100 }
101
102 } // namespace na64dp
103
104