ARTEMIS-CRIB
 
Loading...
Searching...
No Matches
TMapSelector.cc
Go to the documentation of this file.
1/**
2 * @file TMapSelector.cc
3 * @brief extract one catid data
4 * @author Kodai Okawa<okawa@cns.s.u-tokyo.ac.jp>
5 * @date 2024-12-23 11:56:21
6 * @note last modified: 2025-03-05 18:39:21
7 * @details
8 */
9
10#include "TMapSelector.h"
11
12#include <TCategorizedData.h>
13#include <TRawDataObject.h>
14#include <TSimpleData.h>
15
17
18namespace art::crib {
19TMapSelector::TMapSelector() : fCategorizedData(nullptr), fOutData(nullptr) {
20 RegisterInputCollection("CategorizedDataName", "name of the segmented data",
21 fCategorizedDataName, TString("catdata"));
22 RegisterOutputCollection("OutputCollection", "name of the output branch",
23 fOutputColName, TString("channel"));
24
25 IntVec_t init_i_vec;
26 RegisterProcessorParameter("CatID", "Categorized ID, [cid, detid, type]",
27 fCatID, init_i_vec);
28}
29
31 delete fOutData;
32 fOutData = nullptr;
33}
34
35void TMapSelector::Init(TEventCollection *col) {
36 // Categorized data initialization
37 void **cat_ref = col->GetObjectRef(fCategorizedDataName);
38 if (!cat_ref) {
39 SetStateError(Form("No input collection '%s'", fCategorizedDataName.Data()));
40 return;
41 }
42
43 auto *cat_obj = static_cast<TObject *>(*cat_ref);
44 if (!cat_obj->InheritsFrom("art::TCategorizedData")) {
45 SetStateError(Form("Invalid input collection '%s': not TCategorizedData",
46 fCategorizedDataName.Data()));
47 return;
48 }
49 fCategorizedData = reinterpret_cast<TCategorizedData **>(cat_ref);
50
51 // CatID validation
52 if (fCatID.size() != 3) {
53 SetStateError("CatID must contain exactly 3 elements: [cid, detid, type]");
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, CatID = %d",
62 fCategorizedDataName.Data(), fOutputColName.Data(), fCatID[0]);
63}
64
66 fOutData->Clear("C");
67 if (!fCategorizedData) {
68 Warning("Process", "No CategorizedData object");
69 return;
70 }
71
72 auto *cat_array = (*fCategorizedData)->FindCategory(fCatID[0]);
73 if (!cat_array) {
74 // Warning("Process", "No data having catid = %d", fCatID[0]);
75 return;
76 }
77
78 const int nDet = cat_array->GetEntriesFast();
79 int counter = 0;
80 for (int iDet = 0; iDet < nDet; ++iDet) {
81 auto *det_array = static_cast<TObjArray *>(cat_array->At(iDet));
82 if (!det_array)
83 continue;
84 auto *data_array = static_cast<TObjArray *>(det_array->At(fCatID[2]));
85 if (!data_array)
86 continue;
87 const int nData = data_array->GetEntriesFast();
88 for (int iData = 0; iData < nData; ++iData) {
89 auto *data = dynamic_cast<TRawDataObject *>(data_array->At(iData));
90 if (data && data->GetDetID() == fCatID[1]) {
91 auto *outData = static_cast<art::TSimpleData *>(fOutData->ConstructedAt(counter));
92 counter++;
93 outData->SetValue(data->GetValue());
94 }
95 }
96 }
97}
98
99} // namespace art::crib
ClassImp(art::crib::TMapSelector)
extract one catid data
TClonesArray * fOutData
void Process() override
void Init(TEventCollection *col) override
TCategorizedData ** fCategorizedData
return to the guide