ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TChannelSelector.cc
Go to the documentation of this file.
1/**
2 * @file TChannelSelector.cc
3 * @brief extract one channel data
4 * @author Kodai Okawa <okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2024-12-18 15:41:32
6 * @note last modified: 2025-03-05 18:38:43
7 * @details
8 */
9
10#include "TChannelSelector.h"
11
12#include <TRawDataObject.h>
13#include <TSegmentedData.h>
14#include <TSimpleData.h>
15
17
18namespace art::crib {
19TChannelSelector::TChannelSelector() : fSegmentedData(nullptr), fOutData(nullptr) {
20 RegisterInputCollection("SegmentedDataName", "name of the segmented data",
21 fSegmentedDataName, TString("segdata"));
22 RegisterOutputCollection("OutputCollection", "name of the output branch",
23 fOutputColName, TString("channel"));
24
25 IntVec_t init_i_vec;
26 RegisterProcessorParameter("SegID", "segment ID, [dev, fp, mod, geo, ch]",
27 fSegID, init_i_vec);
28}
29
31 delete fOutData;
32 fOutData = nullptr;
33}
34
35void TChannelSelector::Init(TEventCollection *col) {
36 // Segmented data initialization
37 void **seg_ref = col->GetObjectRef(fSegmentedDataName);
38 if (!seg_ref) {
39 SetStateError(Form("No input collection '%s'", fSegmentedDataName.Data()));
40 return;
41 }
42
43 auto *seg_obj = static_cast<TObject *>(*seg_ref);
44 if (!seg_obj->InheritsFrom("art::TSegmentedData")) {
45 SetStateError(Form("Invalid input collection '%s': not TSegmentedData",
46 fSegmentedDataName.Data()));
47 return;
48 }
49 fSegmentedData = reinterpret_cast<TSegmentedData **>(seg_ref);
50
51 // SegID validation
52 if (fSegID.size() != 5) {
53 SetStateError("SegID must contain exactly 5 elements: [dev, fp, mod, geo, ch]");
54 return;
55 }
56
57 delete fOutData; // Release memory allocated for fOutData if it exists
58 fOutData = new TClonesArray("art::TSimpleData");
59 fOutData->SetName(fOutputColName);
60 col->Add(fOutputColName, fOutData, fOutputIsTransparent);
61 Info("Init", "%s -> %s, [dev=%d, fp=%d, mod=%d, geo=%d, ch=%d]",
63 fSegID[0], fSegID[1], fSegID[2], fSegID[3], fSegID[4]);
64}
65
67 fOutData->Clear("C");
68 if (!fSegmentedData) {
69 Warning("Process", "No SegmentedData object");
70 return;
71 }
72
73 auto *seg_array = (*fSegmentedData)->FindSegment(fSegID[0], fSegID[1], fSegID[2]);
74 if (!seg_array) {
75 Warning("Process", "No segment having segid = [dev=%d, fp=%d, mod=%d]",
76 fSegID[0], fSegID[1], fSegID[2]);
77 return;
78 }
79
80 const int nData = seg_array->GetEntriesFast();
81 int counter = 0;
82 for (int iData = 0; iData < nData; ++iData) {
83 auto *data = dynamic_cast<TRawDataObject *>(seg_array->At(iData));
84 if (data && data->GetGeo() == fSegID[3] && data->GetCh() == fSegID[4]) {
85 auto *outData = static_cast<art::TSimpleData *>(fOutData->ConstructedAt(counter));
86 counter++;
87 outData->SetValue(data->GetValue());
88 }
89 }
90}
91
92} // namespace art::crib
ClassImp(art::crib::TChannelSelector)
extract one channel data
void Init(TEventCollection *col) override
TSegmentedData ** fSegmentedData
return to the guide