REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
TRestRawToSignalProcess.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
59#include "TRestRawToSignalProcess.h"
60
61#include <sys/stat.h>
62
63using namespace std;
64
65#include "TTimeStamp.h"
66
68
69TRestRawToSignalProcess::TRestRawToSignalProcess() { Initialize(); }
70
71TRestRawToSignalProcess::TRestRawToSignalProcess(const char* configFilename) {
72 Initialize();
73
74 if (LoadConfigFromFile(configFilename)) LoadDefaultConfig();
75}
76
77TRestRawToSignalProcess::~TRestRawToSignalProcess() {
78 // TRestRawToSignalProcess destructor
79 delete fSignalEvent;
80}
81
82void TRestRawToSignalProcess::LoadConfig(const string& configFilename, const string& name) {
83 if (LoadConfigFromFile(configFilename, name) == -1) {
84 cout << "Loading default" << endl;
85 LoadDefaultConfig();
86 }
87}
88
90 SetSectionName(this->ClassName());
91 SetLibraryVersion(LIBRARY_VERSION);
92
93 delete fSignalEvent;
94 fSignalEvent = new TRestRawSignalEvent();
95
96 fInputBinFile = nullptr;
97
98 fMinPoints = 512;
99
100 fSingleThreadOnly = true;
101 fIsExternal = true;
102 fgKeepFileOpen = true;
103
104 totalBytes = 0;
105 totalbytesRead = 0;
106}
107
109 fElectronicsType = GetParameter("electronics");
110 fShowSamples = StringToInteger(GetParameter("showSamples", "10"));
111 fMinPoints = StringToInteger(GetParameter("minPoints", "512"));
112
114
115 if (fElectronicsType == "SingleFeminos" || fElectronicsType == "TCMFeminos" || fElectronicsType == "TDS")
116 return;
117
118 if (fElectronicsType == "FEUDream") {
119 fgKeepFileOpen = false;
120 return;
121 }
122
123 if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Warning) {
124 cout << "REST WARNING: TRestRawToSignalProcess::InitFromConfigFile" << endl;
125 cout << "Electronic type " << fElectronicsType << " not found " << endl;
126 // cout << "Loading default config" << endl;
127 }
128
129 LoadDefaultConfig();
130}
131
132void TRestRawToSignalProcess::LoadDefaultConfig() {
133 fElectronicsType = "SingleFeminos";
134 fMinPoints = 512;
135}
136
137Bool_t TRestRawToSignalProcess::OpenInputFiles(const vector<string>& files) {
138 nFiles = 0;
139 fInputFiles.clear();
140 fInputFileNames.clear();
141 totalBytes = 0;
142 totalbytesRead = 0;
143
144 for (const auto& file : files) {
145 AddInputFile(file);
146 }
147
148 if (nFiles > 0) {
149 fInputBinFile = fInputFiles[0];
150 } else {
151 RESTError << "No input file is opened, in process: " << this->ClassName() << "!" << RESTendl;
152 exit(1);
153 }
154
155 RESTDebug << this->GetName() << " : opened " << nFiles << " files" << RESTendl;
156 return nFiles;
157}
158
159Bool_t TRestRawToSignalProcess::AddInputFile(const string& file) {
160 for (auto& inputFileName : fInputFileNames) {
161 if (inputFileName == file) {
162 RESTError << "file: \"" << file << "\" already added!" << RESTendl;
163 return false;
164 }
165 }
166
167 FILE* f = fopen(file.c_str(), "rb");
168
169 if (f == nullptr) {
170 RESTWarning << "REST WARNING. Input file for " << this->ClassName() << " does not exist!" << RESTendl;
171 RESTWarning << "File : " << file << RESTendl;
172 return false;
173 }
174
175 fInputFiles.push_back(f);
176 fInputFileNames.push_back(file);
177
178 struct stat statbuf;
179 stat(file.c_str(), &statbuf);
180 totalBytes += statbuf.st_size;
181
182 nFiles++;
183
184 return true;
185}
186
187Bool_t TRestRawToSignalProcess::ResetEntry() {
188 for (auto f : fInputFiles) {
189 if (f != nullptr) {
190 if (fseek(f, 0, 0) != 0) return false;
191 }
192 }
193 InitProcess();
194
195 return true;
196}
197
200
201 RESTMetadata << " " << RESTendl;
202 RESTMetadata << " ==================================== " << RESTendl;
203 RESTMetadata << "DAQ : " << GetTitle() << RESTendl;
204 RESTMetadata << "Electronics type : " << fElectronicsType << RESTendl;
205 RESTMetadata << "Minimum number of points : " << fMinPoints << RESTendl;
206 RESTMetadata << "All raw files open at beginning : " << fgKeepFileOpen << RESTendl;
207 RESTMetadata << " ==================================== " << RESTendl;
208
209 RESTMetadata << " " << RESTendl;
210
211 EndPrintProcess();
212}
213
214Bool_t TRestRawToSignalProcess::GoToNextFile() {
215 iCurFile++;
216 if (iCurFile < nFiles) {
217 if (fgKeepFileOpen) {
218 fInputBinFile = fInputFiles[iCurFile];
219 } else {
220 fclose(fInputBinFile);
221 fInputBinFile = fopen(fInputFileNames[iCurFile].c_str(), "rb");
222 }
223 RESTInfo << "GoToNextFile(): Going to the next raw input file number " << iCurFile << " over "
224 << nFiles << RESTendl;
225 RESTInfo << " Reading file name: " << fInputFileNames[iCurFile] << RESTendl;
226 return true;
227 } else {
228 RESTInfo << "GoToNextFile(): No more file to read" << RESTendl;
229 }
230 return false;
231}
bool fIsExternal
It defines if the process reads event data from an external source.
void BeginPrintProcess()
[name, cut range]
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
void SetSectionName(std::string sName)
set the section name, clear the section content
std::string GetParameter(std::string parName, TiXmlElement *e, TString defaultValue=PARAMETER_NOT_FOUND_STR)
Returns the value for the parameter named parName in the given section.
An event container for time rawdata signals with fixed length.
A base class for any process reading a binary external file as input to REST.
virtual void InitProcess() override
To be executed at the beginning of the run (outside event loop)
void InitFromConfigFile() override
To make settings from rml file. This method must be implemented in the derived class.
Int_t fShowSamples
true if need to open all raw files at the beginning
void Initialize() override
Making default settings.
virtual void PrintMetadata() override
Implemented it in the derived metadata class to print out specific metadata information.
Int_t StringToInteger(std::string in)
Gets an integer from a string.