REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
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 
71 using namespace std;
72 
74 
79 
93  Initialize();
94 
95  if (LoadConfigFromFile(configFilename) == -1) LoadDefaultConfig();
96 
97  PrintMetadata();
98 }
99 
104 
109  SetName("removeChannels-Default");
110  SetTitle("Default config");
111 }
112 
118  SetSectionName(this->ClassName());
119  SetLibraryVersion(LIBRARY_VERSION);
120 
121  fInputSignalEvent = nullptr;
122  fOutputSignalEvent = new TRestRawSignalEvent();
123 }
124 
137 void TRestRawSignalRemoveChannelsProcess::LoadConfig(const string& configFilename, const string& name) {
138  if (LoadConfigFromFile(configFilename, name) == -1) LoadDefaultConfig();
139 }
140 
145  fInputSignalEvent = (TRestRawSignalEvent*)inputEvent;
146 
147  for (int n = 0; n < fInputSignalEvent->GetNumberOfSignals(); n++) {
148  TRestRawSignal* sgnl = fInputSignalEvent->GetSignal(n);
149 
150  Bool_t removeChannel = false;
151  for (unsigned int x = 0; x < fChannelIds.size() && !removeChannel; x++)
152  if (sgnl->GetID() == fChannelIds[x]) removeChannel = true;
153 
154  if (!removeChannel) fOutputSignalEvent->AddSignal(*sgnl);
155 
157  cout << "Channel ID : " << sgnl->GetID() << endl;
158 
159  if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug && removeChannel)
160  cout << "Removing channel id : " << sgnl->GetID() << endl;
161  }
162 
164 
165  return fOutputSignalEvent;
166 }
167 
173  size_t pos = 0;
174 
175  string removeChannelDefinition;
176  while ((removeChannelDefinition = GetKEYDefinition("removeChannel", pos)) != "") {
177  Int_t id = StringToInteger(GetFieldValue("id", removeChannelDefinition));
178  fChannelIds.push_back(id);
179  }
180 
181  pos = 0;
182  while ((removeChannelDefinition = GetKEYDefinition("removeChannels", pos)) != "") {
183  TVector2 v = StringTo2DVector(GetFieldValue("range", removeChannelDefinition));
184  if (v.X() >= 0 && v.Y() >= 0 && v.Y() > v.X())
185  for (int n = (Int_t)v.X(); n <= (Int_t)v.Y(); n++) fChannelIds.push_back(n);
186  }
187 }
A base class for any REST event.
Definition: TRestEvent.h:38
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...
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.
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.
@ 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.