musrfit 1.10.0
PMsr2Data.h
Go to the documentation of this file.
1/***************************************************************************
2
3 PMsr2Data.h
4
5 Author: Bastian M. Wojek / Andreas Suter
6 e-mail: andreas.suter@psi.ch
7
8***************************************************************************/
9
10/***************************************************************************
11 * Copyright (C) 2009-2026 by Bastian M. Wojek / Andreas Suter *
12 * andreas.suter@psi.ch *
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 * This program is distributed in the hope that it will be useful, *
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22 * GNU General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU General Public License *
25 * along with this program; if not, write to the *
26 * Free Software Foundation, Inc., *
27 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28 ***************************************************************************/
29
30// note: msr2data is on purpose implemented in a way that shows string handling can be done solely
31// using std::string, boost and related standard C++ features
32// This implies, however, occasionally strange constructs when interoperating with PMusr-classes
33// which mostly rely on ROOT's TString.
34
35#ifndef _PMSR2DATA_H_
36#define _PMSR2DATA_H_
37
38#include <string>
39#include <sstream>
40
41#include "PRunDataHandler.h"
42#include "PStartupHandler.h"
43
44#include <TSAXParser.h>
45
46//-------------------------------------------------------------
81{
82 public:
83 //-----------------------------------------------------------------------
89 PMsr2Data(const std::string& fileExtension);
90
91 //-----------------------------------------------------------------------
95 ~PMsr2Data();
96
97 //-----------------------------------------------------------------------
104 int SetRunNumbers(unsigned int runNumber);
105
106 //-----------------------------------------------------------------------
114 int SetRunNumbers(unsigned int firstRun, unsigned int lastRun);
115
116 //-----------------------------------------------------------------------
125 int SetRunNumbers(const std::string& runListFileName);
126
127 //-----------------------------------------------------------------------
134 int SetRunNumbers(const std::vector<unsigned int>& runVector);
135
136 //-----------------------------------------------------------------------
142 unsigned int GetPresentRun() const;
143
144 //-----------------------------------------------------------------------
155 int DetermineRunNumberDigits(unsigned int maxRunNumber, bool templateFile) const;
156
157 //-----------------------------------------------------------------------
163 int CheckRunNumbersInRange() const;
164
165 //-----------------------------------------------------------------------
175
176 //-----------------------------------------------------------------------
183 int ReadMsrFile(const std::string& msrFileName) const;
184
185 //-----------------------------------------------------------------------
191 int ReadRunDataFile();
192
193 //-----------------------------------------------------------------------
204 bool PrepareNewInputFile(unsigned int templateNumber, bool sorted) const;
205
206 //-----------------------------------------------------------------------
217 bool PrepareGlobalInputFile(unsigned int templateNumber, const std::string& globalOutputFile, unsigned int runListSize) const;
218
219 //-----------------------------------------------------------------------
233 int WriteOutput(const std::string& outputFileName, const std::vector<unsigned int>& parameters, bool dbFormat, unsigned int precision, bool global = false, unsigned int counter = 0) const;
234
235 private:
236 //-----------------------------------------------------------------------
245 bool PrepareNewSortedInputFile(unsigned int templateNumber) const;
246
247 //-----------------------------------------------------------------------
254
255 //-----------------------------------------------------------------------
263 void WriteValue(std::fstream &outFile, const double &value, const unsigned int &width) const;
264
265 //-----------------------------------------------------------------------
277 void WriteValue(std::fstream &outFile, const double &value, const double &errValue, const unsigned int &width, const bool &db) const;
278
279 //-----------------------------------------------------------------------
288 int GetFirstSignificantDigit(const double &value) const;
289
290 //-----------------------------------------------------------------------
298 bool InParameterList(const unsigned int &paramValue, const std::vector<unsigned int>& paramList) const;
299
300 std::string fFileExtension;
301 std::vector<unsigned int> fRunVector;
302 mutable std::vector<unsigned int>::const_iterator fRunVectorIter;
304 std::vector<std::string> fIndVar;
305 std::unique_ptr<std::ifstream> fRunListFileStream;
306 std::unique_ptr<TSAXParser> fSaxParser;
307 std::unique_ptr<PStartupHandler> fStartupHandler;
308 mutable std::unique_ptr<PRunDataHandler> fDataHandler;
309 mutable std::unique_ptr<PMsrHandler> fMsrHandler;
310 mutable unsigned int fNumGlobalParam;
311 mutable unsigned int fNumSpecParam;
312 mutable unsigned int fNumTempRunBlocks;
313 mutable unsigned int fRunNumberDigits;
314 mutable bool fHeaderWritten;
315};
316
317
318#endif // _PMSR2DATA_H_
PMsr2Data(const std::string &fileExtension)
Constructor that initializes the msr2data handler.
Definition PMsr2Data.cpp:73
unsigned int fNumSpecParam
Number of spectrum-specific parameters.
Definition PMsr2Data.h:311
int ReadMsrFile(const std::string &msrFileName) const
Reads and parses an msr-file.
std::unique_ptr< std::ifstream > fRunListFileStream
Stream for reading run list file.
Definition PMsr2Data.h:305
bool PrepareGlobalInputFile(unsigned int templateNumber, const std::string &globalOutputFile, unsigned int runListSize) const
Generates an msr-file for global (multi-run) fitting.
PMsrHandler * GetSingleRunMsrFile() const
Retrieves msr-file handler for a single run.
int WriteOutput(const std::string &outputFileName, const std::vector< unsigned int > &parameters, bool dbFormat, unsigned int precision, bool global=false, unsigned int counter=0) const
Writes extracted parameters to output file.
bool PrepareNewInputFile(unsigned int templateNumber, bool sorted) const
Generates a new msr-file from a template.
int CheckRunNumbersInRange() const
Validates that all run numbers are within acceptable ranges.
unsigned int fNumTempRunBlocks
Number of temporary run blocks.
Definition PMsr2Data.h:312
std::vector< unsignedint >::const_iterator fRunVectorIter
Iterator for current position in run vector.
Definition PMsr2Data.h:302
int ReadRunDataFile()
Reads the run data file for the current run.
std::unique_ptr< PMsrHandler > fMsrHandler
Handler for msr-file parsing and generation.
Definition PMsr2Data.h:309
std::unique_ptr< TSAXParser > fSaxParser
XML SAX parser for startup file.
Definition PMsr2Data.h:306
std::string fFileExtension
File extension for data files (e.g., "bin", "root")
Definition PMsr2Data.h:300
int GetFirstSignificantDigit(const double &value) const
Determines the first significant digit position of a value.
unsigned int fNumGlobalParam
Number of global parameters in fit.
Definition PMsr2Data.h:310
std::unique_ptr< PStartupHandler > fStartupHandler
Handler for XML startup file configuration.
Definition PMsr2Data.h:307
int SetRunNumbers(unsigned int runNumber)
Sets a single run number for processing.
void WriteValue(std::fstream &outFile, const double &value, const unsigned int &width) const
Writes a single numeric value to output stream.
bool fHeaderWritten
Flag tracking if output header has been written.
Definition PMsr2Data.h:314
int ParseXmlStartupFile()
Parses the XML startup file for configuration.
unsigned int fRunNumberDigits
Number of digits for run number formatting.
Definition PMsr2Data.h:313
~PMsr2Data()
Destructor that cleans up resources.
Definition PMsr2Data.cpp:93
bool PrepareNewSortedInputFile(unsigned int templateNumber) const
Generates a sorted msr-file from a template.
std::vector< std::string > fIndVar
Independent variables for output.
Definition PMsr2Data.h:304
std::vector< unsigned int > fRunVector
Vector of run numbers to process.
Definition PMsr2Data.h:301
unsigned int GetPresentRun() const
Gets the current run number being processed.
int DetermineRunNumberDigits(unsigned int maxRunNumber, bool templateFile) const
Determines the number of digits needed for run number formatting.
bool fRunListFile
Flag indicating if run list is from a file.
Definition PMsr2Data.h:303
bool InParameterList(const unsigned int &paramValue, const std::vector< unsigned int > &paramList) const
Checks if a parameter is in the output parameter list.
std::unique_ptr< PRunDataHandler > fDataHandler
Handler for run data files.
Definition PMsr2Data.h:308
MSR file parser and manager for the musrfit framework.