ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TMUXPositionValidator.cc
Go to the documentation of this file.
1/**
2 * @file TMUXPositionValidator.cc
3 * @brief Implementation of the TMUXPositionValidator class for validating positions in MUX data.
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2024-01-30 10:02:46
6 * @note last modified: 2025-03-05 18:31:54
7 * @details
8 */
9
11#include "../TProcessorUtil.h"
12
13#include "TMUXData.h"
14
15/// ROOT macro for class implementation
17
18namespace art::crib {
19
20/**
21 * @details
22 * The constructor initializes member variables and registers input/output collections
23 * as well as the `ValidPositionRange` parameter.
24 * The default position range is set to `[0.0, 0.0]`, which effectively disables validation
25 * unless explicitly configured.
26 */
28 : fInData(nullptr), fOutData(nullptr) {
29 RegisterInputCollection("InputCollection", "Input collection of TMUXData objects",
30 fInputColName, TString("input"));
31 RegisterOutputCollection("OutputCollection", "Validated output collection",
32 fOutputColName, TString("validated"));
33
34 const DoubleVec_t range(2, 0.0);
35 RegisterProcessorParameter("ValidPositionRange",
36 "[min, max] -- Ignored if min == max",
37 fValidPositionRange, range);
38}
39
40/**
41 * @details
42 * The destructor releases any allocated resources, specifically deallocating the `fOutData`
43 * collection to prevent memory leaks.
44 */
49
50/**
51 * @details
52 * This method initializes the processor by:
53 * - Retrieving the input data collection from the event collection (`col`).
54 * - Validating the configuration of the position range parameter (`fValidPositionRange`).
55 * - Creating the output collection for validated data.
56 *
57 * If the position range parameter is invalid (e.g., incorrect size or `min > max`),
58 * the processor enters an error state and halts further processing.
59 */
60void TMUXPositionValidator::Init(TEventCollection *col) {
61 // Retrieve the input data collection
63 col, fInputColName, "TClonesArray", "art::crib::TMUXData");
64
65 if (std::holds_alternative<TString>(result)) {
66 SetStateError(std::get<TString>(result));
67 return;
68 }
69 fInData = std::get<TClonesArray **>(result);
70 Info("Init", "%s => %s", fInputColName.Data(), fOutputColName.Data());
71
72 // Validate the position range parameter
73 if (fValidPositionRange.size() != 2) {
74 SetStateError(Form("Position range size should be 2, but %zu",
75 fValidPositionRange.size()));
76 return;
77 }
78
80 SetStateError("Position range : min > max");
81 return;
82 }
83
84 // Set up the output data collection
85 fOutData = new TClonesArray("art::crib::TMUXData");
86 fOutData->SetName(fOutputColName);
87 col->Add(fOutputColName, fOutData, fOutputIsTransparent);
88}
89
90/**
91 * @details
92 * The `Process` method validates each entry in the input collection against the
93 * configured position range. Entries with positions (`P1`) within the range are copied
94 * to the output collection, while others are ignored.
95 *
96 * Processing steps:
97 * 1. Clear the output collection to prepare for new entries.
98 * 2. Iterate over all entries in the input collection.
99 * 3. Validate the position (`P1`) of each entry against the range.
100 * 4. Copy valid entries to the output collection.
101 *
102 * Any invalid or missing data is skipped without affecting the remaining entries.
103 */
105 fOutData->Clear("C");
106
107 // Process each entry in the input collection
108 const int nData = (*fInData)->GetEntriesFast();
109 for (int iData = 0; iData < nData; ++iData) {
110 const auto *data = dynamic_cast<const TMUXData *>((*fInData)->At(iData));
111 if (!data) {
112 // Warning("Process", "Invalid TMUXData object at index %d", iData);
113 continue;
114 }
115
116 // Validate position
117 const double pos1_raw = data->GetP1();
118 if (pos1_raw < fValidPositionRange[0] || pos1_raw > fValidPositionRange[1]) {
119 continue; // Skip entries outside the valid range
120 }
121
122 // Copy valid data to the output collection
123 auto *outData = fOutData->ConstructedAt(fOutData->GetEntriesFast());
124 data->Copy(*outData);
125 }
126}
127
128} // namespace art::crib
Header file for the TMUXData class.
ClassImp(art::crib::TMUXPositionValidator)
ROOT macro for class implementation.
Header file for the TMUXPositionValidator class.
Utility functions for handling input and parameter objects in TEventCollection.
Represents data from the MUX module (E1, E2, P1, P2, T).
Definition TMUXData.h:25
Double_t GetP1() const
Get the first position value.
Definition TMUXData.h:63
Validates positions from the MUX module based on specified ranges.
std::vector< Double_t > fValidPositionRange
Range of valid positions for validation.
TClonesArray * fOutData
! Pointer to the output data collection.
TString fOutputColName
Name of the output collection.
TString fInputColName
Name of the input collection.
TClonesArray ** fInData
! Pointer to the input data collection.
void Init(TEventCollection *col) override
Initializes the validator by setting up input and output collections.
void Process() override
Processes input data, validates positions, and stores the results.
std::enable_if_t< std::is_base_of_v< TObject, T >, std::variant< T **, TString > > GetInputObject(TEventCollection *col, const TString &name, const TString &expectedTypeName, const TString &elementTypeName="TObject")
Retrieve an object from TEventCollection with type validation.
return to the guide