REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
src/TRestRawSignalRemoveChannelsProcess.cxx
1/*************************************************************************
2 * This file is part of the REST software framework. *
3 * *
4 * Copyright (C) 2016 GIFNA/TREX (University of Zaragoza) *
5 * For more information see http://gifna.unizar.es/trex *
6 * *
7 * REST is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * REST is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have a copy of the GNU General Public License along with *
18 * REST in $REST_PATH/LICENSE. *
19 * If not, see http://www.gnu.org/licenses/. *
20 * For the list of contributors see $REST_PATH/CREDITS. *
21 *************************************************************************/
22
69#include "TRestRawSignalRemoveChannelsProcess.h"
70
71using namespace std;
72
74
79
93 Initialize();
94
95 if (LoadConfigFromFile(configFilename) == -1) {
97 }
98
100}
101
106
111 SetName("removeChannels-Default");
112 SetTitle("Default config");
113}
114
120 SetSectionName(this->ClassName());
121 SetLibraryVersion(LIBRARY_VERSION);
122
123 fInputEvent = nullptr;
125}
126
139void TRestRawSignalRemoveChannelsProcess::LoadConfig(const string& configFilename, const string& name) {
140 if (LoadConfigFromFile(configFilename, name) == -1) {
142 }
143}
144
149 fInputEvent = dynamic_cast<TRestRawSignalEvent*>(inputEvent);
150
151 const auto run = GetRunInfo();
152 if (run != nullptr) {
154 }
155
156 if (fReadoutMetadata == nullptr) {
157 fReadoutMetadata = fInputEvent->GetReadoutMetadata();
158 }
159
160 if (fReadoutMetadata == nullptr && !fChannelTypes.empty()) {
161 cerr << "TRestRawSignalRemoveChannelsProcess::ProcessEvent: readout metadata is null, cannot filter "
162 "the process by signal type"
163 << endl;
164 exit(1);
165 }
166
167 for (int n = 0; n < fInputEvent->GetNumberOfSignals(); n++) {
168 TRestRawSignal* signal = fInputEvent->GetSignal(n);
169
170 bool removeSignal = false;
171
172 // Check if the channel ID matches any specified for removal
173 for (int fChannelId : fChannelIds) {
174 if (signal->GetID() == fChannelId) {
175 removeSignal = true;
176 break;
177 }
178 }
179
180 // Check if the channel type matches any specified for removal
181 if (!removeSignal && !fChannelTypes.empty()) {
182 const auto signalId = signal->GetSignalID();
183 string channelType = fReadoutMetadata->GetTypeForChannelDaqId(signalId);
184 if (find(fChannelTypes.begin(), fChannelTypes.end(), channelType) != fChannelTypes.end()) {
185 removeSignal = true;
186 // Add the channel type and ID to the vector
187 if (fChannelTypesToRemove.find(signalId) != fChannelTypesToRemove.end() &&
188 fChannelTypesToRemove.at(signalId) != channelType) {
189 throw runtime_error(
190 "TRestRawSignalRemoveChannelsProcess: Signal was already recorded to have some type, "
191 "but it changed");
192 }
193 fChannelTypesToRemove[signalId] = channelType;
194 }
195 }
196
197 if (!removeSignal) {
198 fOutputEvent->AddSignal(*signal);
199 }
200
201 // Logging messages
203 cout << "Channel ID : " << signal->GetID() << endl;
204 }
205
207 cout << "Removing channel id : " << signal->GetID() << endl;
208 }
209 }
210
212 GetChar();
213 }
214
215 return fOutputEvent;
216}
217
223 size_t pos = 0;
224
225 string removeChannelDefinition;
226 while (!(removeChannelDefinition = GetKEYDefinition("removeChannel", pos)).empty()) {
227 Int_t id = StringToInteger(GetFieldValue("id", removeChannelDefinition));
228 if (id < 0) {
229 continue;
230 }
231 fChannelIds.push_back(id);
232 }
233
234 pos = 0;
235 while (!(removeChannelDefinition = GetKEYDefinition("removeChannels", pos)).empty()) {
236 TVector2 v = StringTo2DVector(GetFieldValue("range", removeChannelDefinition));
237 if (v.X() == -1 && v.Y() == -1) {
238 continue;
239 }
240 if (v.X() >= 0 && v.Y() >= 0 && v.Y() > v.X()) {
241 for (int n = (Int_t)v.X(); n <= (Int_t)v.Y(); n++) {
242 fChannelIds.push_back(n);
243 }
244 }
245 }
246
247 pos = 0;
248 while (!(removeChannelDefinition = GetKEYDefinition("removeChannels", pos)).empty()) {
249 string type = GetFieldValue("type", removeChannelDefinition);
250 if (type.empty() || type == "Not defined") {
251 continue;
252 }
253 fChannelTypes.push_back(type);
254 }
255}
256
259
260 for (int channelId : fChannelIds) {
261 RESTMetadata << "Channel id to remove: " << channelId << RESTendl;
262 }
263
264 if (!fChannelTypes.empty()) {
265 RESTMetadata << "Channel types to be removed: ";
266 for (const auto& type : fChannelTypes) {
267 RESTMetadata << type << " ";
268 }
269 RESTMetadata << RESTendl;
270 }
271
272 for (const auto& [signalId, type] : fChannelTypesToRemove) {
273 RESTMetadata << "Removing channel of type '" << type << "' and id " << signalId << RESTendl;
274 }
275
276 EndPrintProcess();
277}
TRestRun * GetRunInfo() const
Return the pointer of the hosting TRestRun object.
void BeginPrintProcess()
[name, cut range]
A base class for any REST event.
Definition: TRestEvent.h:38
virtual void InitializeReferences(TRestRun *run)
Initialize dynamical references when loading the event from a root file.
Definition: TRestEvent.cxx:175
endl_t RESTendl
Termination flag object for TRestStringOutput.
Int_t LoadConfigFromFile(const std::string &configFilename, const std::string &sectionName="")
Give the file name, find out the corresponding section. Then call the main starter.
void SetLibraryVersion(TString version)
Set the library version of this metadata class.
TRestStringOutput::REST_Verbose_Level GetVerboseLevel()
returns the verboselevel in type of REST_Verbose_Level enumerator
std::string GetFieldValue(std::string parName, TiXmlElement *e)
Returns the field value of an xml element which has the specified name.
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetKEYDefinition(std::string keyName)
Gets the first key definition for keyName found inside buffer starting at fromPosition.
An event container for time rawdata signals with fixed length.
A process allowing to remove selected channels from a TRestRawSignalEvent.
void InitFromConfigFile() override
Function reading input parameters from the RML TRestDetectorSignalToRawSignalProcess metadata section...
TRestRawSignalEvent * fOutputEvent
A pointer to the specific TRestRawSignalEvent input.
TRestRawReadoutMetadata * fReadoutMetadata
A pointer to the readout metadata.
TRestEvent * ProcessEvent(TRestEvent *inputEvent) override
The main processing event function.
void Initialize() override
Function to initialize input/output event members and define the section name.
TRestRawSignalEvent * fInputEvent
A pointer to the specific TRestDetectorSignalEvent input.
void PrintMetadata() override
It prints out the process parameters stored in the metadata structure.
void LoadDefaultConfig()
Function to load the default config in absence of RML input.
void LoadConfig(const std::string &configFilename, const std::string &name="")
Function to load the configuration from an external configuration file.
It defines a Short_t array with a physical parameter that evolves in time using a fixed time bin.
Int_t GetID() const
Returns the value of signal ID.
Int_t GetSignalID() const
Returns the value of signal ID.
@ REST_Debug
+show the defined debug messages
Int_t GetChar(std::string hint="Press a KEY to continue ...")
Helps to pause the program, printing a message before pausing.
Int_t StringToInteger(std::string in)
Gets an integer from a string.
TVector2 StringTo2DVector(std::string in)
Gets a 2D-vector from a string.