|
16 | 16 | #include <vector> |
17 | 17 |
|
18 | 18 |
|
19 | | -class GDataCollection { |
| 19 | +class GDataCollection |
| 20 | +{ |
20 | 21 | public: |
21 | | - /** |
22 | | - * \brief Constructs a GDataCollection. |
23 | | - * \param logger Pointer to a GLogger instance. |
24 | | - */ |
25 | | - explicit GDataCollection(){} |
| 22 | + /** |
| 23 | + * \brief Constructs a GDataCollection. |
| 24 | + */ |
| 25 | + explicit GDataCollection() = default; |
26 | 26 |
|
27 | | - /** |
28 | | - * \brief Destructor for GDataCollection. |
29 | | - * |
30 | | - * Smart pointers clean up automatically. |
31 | | - */ |
32 | 27 |
|
33 | | - /** |
34 | | - * \brief Adds true hit information data. |
35 | | - * \param data Unique pointer to GTrueInfoData. |
36 | | - */ |
37 | | - void addTrueInfoData(std::unique_ptr<GTrueInfoData> data) { |
38 | | - trueInfosData.push_back(std::move(data)); // taking ownership of the unique_ptr |
39 | | - } |
| 28 | + /** |
| 29 | + * \brief Destructor for GDataCollection. |
| 30 | + * |
| 31 | + * Smart pointers clean up automatically. |
| 32 | + */ |
40 | 33 |
|
41 | | - /** |
42 | | - * \brief Adds digitized hit data. |
43 | | - * \param data Unique pointer to GDigitizedData. |
44 | | - */ |
45 | | - void addDigitizedData(std::unique_ptr<GDigitizedData> data) { |
46 | | - digitizedData.push_back(std::move(data)); // taking ownership of the unique_ptr |
47 | | - } |
| 34 | + /** |
| 35 | + * \brief Adds true hit information data. |
| 36 | + * \param data Unique pointer to GTrueInfoData. |
| 37 | + */ |
| 38 | + void addTrueInfoData(std::unique_ptr<GTrueInfoData> data) { |
| 39 | + trueInfosData.push_back(std::move(data)); // taking ownership of the unique_ptr |
| 40 | + } |
48 | 41 |
|
49 | | - /** |
50 | | - * \brief Provides read-only access to the stored true hit data. |
51 | | - * |
52 | | - * Returns a constant reference to the internal vector of unique pointers |
53 | | - * to GTrueInfoData objects. Ownership of the data remains with this class. |
54 | | - * Callers may inspect the data via the pointers but must not modify or |
55 | | - * take ownership of them. |
56 | | - * |
57 | | - * \return Const reference to the vector of unique_ptr<GTrueInfoData>. |
58 | | - */ |
59 | | - [[nodiscard]] inline const std::vector<std::unique_ptr<GTrueInfoData>>& getTrueInfoData() const { return trueInfosData; } |
| 42 | + // sum existing data |
| 43 | + void collectTrueInfosData(std::unique_ptr<GTrueInfoData> data) { |
| 44 | + // first event |
| 45 | + if (trueInfosData.empty()) { |
| 46 | + trueInfosData.push_back(std::move(data)); |
| 47 | + } |
| 48 | + else { |
| 49 | + for (const auto& [varName, value] : data->getDoubleVariablesMap()) { |
| 50 | + trueInfosData.front()->accumulateVariable(varName, value); |
| 51 | + } |
| 52 | + for (const auto& [varName, value] : data->getStringVariablesMap()) { |
| 53 | + trueInfosData.front()->accumulateVariable(varName, value); |
| 54 | + } |
| 55 | + } |
| 56 | + } |
60 | 57 |
|
61 | | - /** |
62 | | - * \brief Provides read-only access to the stored digitized hit data. |
63 | | - * |
64 | | - * Returns a constant reference to the internal vector of unique pointers |
65 | | - * to GDigitizedData objects. Ownership of the data remains with this class. |
66 | | - * Callers may read the data but must not modify or transfer ownership. |
67 | | - * |
68 | | - * \return Const reference to the vector of unique_ptr<GDigitizedData>. |
69 | | - */ |
70 | | - [[nodiscard]] inline const std::vector<std::unique_ptr<GDigitizedData>>& getDigitizedData() const { return digitizedData; } |
| 58 | + void collectDigitizedData(std::unique_ptr<GDigitizedData> data) { |
| 59 | + // first event |
| 60 | + if (digitizedData.empty()) { |
| 61 | + digitizedData.push_back(std::move(data)); |
| 62 | + } |
| 63 | + else { |
| 64 | + // argument passed: 0: do not get SRO var |
| 65 | + for (const auto& [varName, value] : data->getIntObservablesMap(0)) { |
| 66 | + digitizedData.front()->accumulateVariable(varName, value); |
| 67 | + } |
| 68 | + for (const auto& [varName, value] : data->getDblObservablesMap(0)) { |
| 69 | + digitizedData.front()->accumulateVariable(varName, value); |
| 70 | + } |
| 71 | + } |
| 72 | + } |
71 | 73 |
|
72 | | -private: |
73 | | - std::vector<std::unique_ptr<GTrueInfoData>> trueInfosData; ///< Vector of true hit data. |
74 | | - std::vector<std::unique_ptr<GDigitizedData>> digitizedData; ///< Vector of digitized hit data. |
75 | 74 |
|
| 75 | + /** |
| 76 | + * \brief Adds digitized hit data. |
| 77 | + * \param data Unique pointer to GDigitizedData. |
| 78 | + */ |
| 79 | + void addDigitizedData(std::unique_ptr<GDigitizedData> data) { |
| 80 | + digitizedData.push_back(std::move(data)); // taking ownership of the unique_ptr |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * \brief Provides read-only access to the stored true hit data. |
| 85 | + * |
| 86 | + * Returns a constant reference to the internal vector of unique pointers |
| 87 | + * to GTrueInfoData objects. Ownership of the data remains with this class. |
| 88 | + * Callers may inspect the data via the pointers but must not modify or |
| 89 | + * take ownership of them. |
| 90 | + * |
| 91 | + * \return Const reference to the vector of unique_ptr<GTrueInfoData>. |
| 92 | + */ |
| 93 | + [[nodiscard]] inline const std::vector<std::unique_ptr<GTrueInfoData>>& getTrueInfoData() const { |
| 94 | + return trueInfosData; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * \brief Provides read-only access to the stored digitized hit data. |
| 99 | + * |
| 100 | + * Returns a constant reference to the internal vector of unique pointers |
| 101 | + * to GDigitizedData objects. Ownership of the data remains with this class. |
| 102 | + * Callers may read the data but must not modify or transfer ownership. |
| 103 | + * |
| 104 | + * \return Const reference to the vector of unique_ptr<GDigitizedData>. |
| 105 | + */ |
| 106 | + [[nodiscard]] inline const std::vector<std::unique_ptr<GDigitizedData>>& getDigitizedData() const { |
| 107 | + return digitizedData; |
| 108 | + } |
| 109 | + |
| 110 | +private: |
| 111 | + // for event data, the array index is the hit index |
| 112 | + std::vector<std::unique_ptr<GTrueInfoData>> trueInfosData; ///< Vector of true data. |
| 113 | + std::vector<std::unique_ptr<GDigitizedData>> digitizedData; ///< Vector of digitized data. |
76 | 114 | }; |
0 commit comments