-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSubevent.h
executable file
·111 lines (93 loc) · 2.65 KB
/
Subevent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* Subevent.h
*
* Created on: Mar 2, 2016
* Author: giovanna
*/
#ifndef L1SUBEVENT_H_
#define L1SUBEVENT_H_
#include <boost/noncopyable.hpp>
#include <atomic>
#include <cstdbool>
#include <cstdint>
#include <iostream>
#include <set>
#include "../eventBuilding/SourceIDManager.h"
#include "MEPFragment.h"
namespace na62 {
namespace l1 {
class Subevent: private boost::noncopyable {
public:
Subevent(const uint_fast16_t expectedPacketsNum, const uint_fast8_t sourceID);
virtual ~Subevent();
void destroy();
/**
* If the Subevent is not complete yet the given fragment will be stored and true is returned.
*
* Otherwise false is returned
*
*/
inline bool addFragment(MEPFragment* fragment) {
uint_fast16_t oldNumberOfFragments = fragmentCounter.fetch_add(1);
if (oldNumberOfFragments
>= SourceIDManager::getExpectedL1PacksBySourceID(fragment->getSourceID())) {
/*
* when more fragments are received than expected: decrement the counter back to the old value
* We have to check >= as it might be > in case of a high rate where another thread could already
* have incremented it without decrementing it yet
*/
fragmentCounter--;
return false;
}
eventFragments[oldNumberOfFragments] = fragment;
return true;
}
/**
* Returns all fragments of this Subevent
* @return A pointer to an array of all received MEPFragment pointers
*/
inline MEPFragment ** getEventFragments() const {
return eventFragments;
}
/**
* Returns the Nth event fragment that has been received
*
* @param eventPartNumber
* The number of the requested fragment (N). N must be smaller
* than getNumberOfParts()
* @return The Nth fragment received
*/
inline MEPFragment* getFragment(uint_fast16_t eventPartNumber) const {
return eventFragments[eventPartNumber];
}
/**
* Returns all missing source sub IDs. This only works correctly if the enabled sub IDs are consecutive numbers from 0 to ExpectedPacketsNum-1
*/
inline std::vector<uint> getMissingSourceSubIds() const {
// Not implemented
std::vector<uint> missingSubIDs;
return missingSubIDs;
}
/**
* Returns the number of received subevent fragments
*
* @return The number of subevent fragments received
*/
inline uint_fast16_t getNumberOfFragments() const {
return fragmentCounter;
}
uint_fast16_t getNumberOfExpectedFragments() const {
return expectedPacketsNum;
}
uint8_t getSourceID() {
return sourceID;
}
private:
const uint_fast16_t expectedPacketsNum;
const uint_fast8_t sourceID;
MEPFragment ** eventFragments;
std::atomic<uint_fast16_t> fragmentCounter;
};
} /* namespace l1 */
} /* namespace na62 */
#endif /* L1SUBEVENT_H_ */