refactor PSI-BIN lib. Fix a couple of bugs and start to adopt to more modern c++.

This commit is contained in:
suter_a 2022-05-28 14:08:04 +02:00
parent b72ec88783
commit 40007650f6
3 changed files with 1250 additions and 1493 deletions

View File

@ -5,7 +5,7 @@ set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\$\{prefix\}") set(exec_prefix "\$\{prefix\}")
set(libdir "\$\{exec_prefix\}/lib") set(libdir "\$\{exec_prefix\}/lib")
set(includedir "\$\{prefix\}/include") set(includedir "\$\{prefix\}/include")
set(PSIBIN_VERSION "0.1.0") set(PSIBIN_VERSION "0.2.0")
set(PSIBIN_LIBRARY_NAME "Class_MuSR_PSI") set(PSIBIN_LIBRARY_NAME "Class_MuSR_PSI")
configure_file("Class_MuSR_PSI.pc.in" "Class_MuSR_PSI.pc" @ONLY) configure_file("Class_MuSR_PSI.pc.in" "Class_MuSR_PSI.pc" @ONLY)

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@
begin : Alex Amato, October 2005 begin : Alex Amato, October 2005
modified : Andrea Raselli, October 2009 modified : Andrea Raselli, October 2009
: Andreas Suter, April 2019 : Andreas Suter, April 2019, May 2020
copyright : (C) 2005 by copyright : (C) 2005 by
email : alex.amato@psi.ch email : alex.amato@psi.ch
@ -56,57 +56,55 @@ class MuSR_td_PSI_bin {
~MuSR_td_PSI_bin(); ~MuSR_td_PSI_bin();
private: private:
// ------------------------------------start of the variables std::string fFilename;
std::string fReadStatus;
std::string fWriteStatus;
std::string fConsistencyStatus;
bool fReadingOk;
bool fWritingOk;
bool fConsistencyOk;
std::string filename; char fFormatId[3];
std::string readstatus;
std::string writestatus;
std::string consistencyStatus;
bool readingok;
bool writingok;
bool consistencyOk;
char format_id[3]; int fNumRun;
int num_run; char fSample[11];
char fTemp[11];
char fField[11];
char fOrient[11];
char fSetup[11];
char fComment[63];
char sample[11]; char fDateStart[10];
char temp[11]; char fDateStop[10];
char field[11]; char fTimeStart[9];
char orient[11]; char fTimeStop[9];
char setup[11];
char comment[63];
char date_start[10]; double fBinWidth;
char date_stop[10];
char time_start[9];
char time_stop[9];
double bin_width; int fNumberHisto;
int fLengthHisto;
char fLabelsHisto[MAXHISTO][MAXLABELSIZE];
int number_histo; int fTotalEvents;
int length_histo; int fEventsPerHisto[MAXHISTO];
char labels_histo[MAXHISTO][MAXLABELSIZE];
int total_events; int fDefaultBinning;
int events_per_histo[MAXHISTO];
int default_binning; float fRealT0[MAXHISTO];
int fIntegerT0[MAXHISTO];
int fFirstGood[MAXHISTO];
int fLastGood[MAXHISTO];
float real_t0[MAXHISTO]; int fNumberScaler;
int integer_t0[MAXHISTO]; int fScalers[MAXSCALER];
int first_good[MAXHISTO]; char fLabelsScalers[MAXSCALER][MAXLABELSIZE];
int last_good[MAXHISTO];
int number_scaler; int fNumberTemper;
int scalers[MAXSCALER]; float fTemper[MAXTEMPER];
char labels_scalers[MAXSCALER][MAXLABELSIZE]; float fTempDeviation[MAXTEMPER];
int number_temper; std::vector< std::vector<int> > fHisto;
float temper[MAXTEMPER];
float temp_deviation[MAXTEMPER];
int **histo;
public: public:
@ -118,22 +116,22 @@ class MuSR_td_PSI_bin {
NOTE: Histogram information returned by \<pointer_to_array\> = ..._array() methods NOTE: Histogram information returned by \<pointer_to_array\> = ..._array() methods
should be freed by delete [] \<pointer_to_array\>; should be freed by delete [] \<pointer_to_array\>;
*/ */
std::vector< std::vector<double> > histos_vector ; std::vector< std::vector<double> > fHistosVector ;
// ------------------------------------end of the variables // ------------------------------------end of the variables
public: public:
int read(const char* fileName); // generic read int Read(const char* fileName); // generic read
int write(const char *fileName); // generic write int Write(const char *fileName); // generic write
int readbin(const char* fileName); // read MuSR PSI bin format int ReadBin(const char* fileName); // read MuSR PSI bin format
int writebin(const char *fileName); // write MuSR PSI bin format int WriteBin(const char *fileName); // write MuSR PSI bin format
int readmdu(const char* fileName); // read MuSR mdu format int ReadMdu(const char* fileName); // read MuSR mdu format
int writemdu(const char* fileName); // write MuSR mdu format int WriteMdu(const char* fileName); // write MuSR mdu format
bool readingOK() const; bool ReadingOK() const;
bool writingOK() const; bool WritingOK() const;
bool CheckDataConsistency(int tag=0); // tag: 0=reasonable, 1=strict bool CheckDataConsistency(int tag=0); // tag: 0=reasonable, 1=strict
std::string ReadStatus() const; std::string ReadStatus() const;
std::string WriteStatus() const; std::string WriteStatus() const;
@ -143,57 +141,46 @@ class MuSR_td_PSI_bin {
int Show() const; int Show() const;
int Clear(); int Clear();
int get_histo_int(int histo_num, int j); int GetHistoInt(int histo_num, int j);
double get_histo(int histo_num, int j); double GetHisto(int histo_num, int j);
int *get_histo_array_int(int histo_num); std::vector<int> GetHistoArrayInt(int histo_num);
double *get_histo_array(int histo_num, int binning); std::vector<double> GetHistoArray(int histo_num, int binning);
int put_histo_array_int(std::vector< std::vector<int> > histo, int tag = 0); int PutHistoArrayInt(std::vector< std::vector<int> > &histo, int tag = 0);
std::vector<double> get_histo_vector(int histo_num, int binning); std::vector<double> GetHistoVector(int histo_num, int binning);
std::vector<double> get_histo_vector_no0(int histo_num, int binning); std::vector<double> GetHistoVectorNo0(int histo_num, int binning);
double *get_histo_fromt0_array(int histo_num, int binning, int offset = 0); double *GetHistoFromT0Array(int histo_num, int binning, int offset = 0);
std::vector<double> get_histo_fromt0_vector(int histo_num, int binning, int offset = 0); std::vector<double> GetHistoFromT0Vector(int histo_num, int binning, int offset = 0);
double *get_histo_goodBins_array(int histo_num, int binning); double *GetHistoGoodBinsArray(int histo_num, int binning);
std::vector<double> get_histo_goodBins_vector(int histo_num, int binning); std::vector<double> GetHistoGoodBinsVector(int histo_num, int binning);
double *get_histo_fromt0_minus_bckgrd_array(int histo_num, double *GetHistoFromT0MinusBkgArray(int histo_num,
int lower_bckgdr, int lower_bckgdr,
int higher_bckgdr, int higher_bckgdr,
int binning, int binning,
int offset = 0); int offset = 0);
std::vector<double> get_histo_fromt0_minus_bckgrd_vector(int histo_num, std::vector<double> GetHistoFromT0MinusBkgVector(int histo_num,
int lower_bckgdr, int lower_bckgdr,
int higher_bckgdr, int higher_bckgdr,
int binning, int binning,
int offset = 0); int offset = 0);
double *get_histo_goodBins_minus_bckgrd_array(int histo_num, double *GetHistoGoodBinsMinusBkgArray(int histo_num,
int lower_bckgrd, int lower_bckgrd,
int higher_bckgrd, int higher_bckgrd,
int binning); int binning);
std::vector<double> get_histo_goodBins_minus_bckgrd_vector(int histo_num, std::vector<double> GetHistoGoodBinsMinusBkgVector(int histo_num,
int lower_bckgrd, int lower_bckgrd,
int higher_bckgrd, int higher_bckgrd,
int binning); int binning);
double *get_asymmetry_array(int histo_num_plus, double *GetAsymmetryArray(int histo_num_plus,
int histo_num_minus,
double alpha_param,
int binning,
int lower_bckgrd_plus,
int higher_bckgrd_plus,
int lower_bckgrd_minus,
int higher_bckgrd_minus,
int offset = 0,
double y_offset = 0.);
std::vector<double> get_asymmetry_vector(int histo_num_plus,
int histo_num_minus, int histo_num_minus,
double alpha_param, double alpha_param,
int binning, int binning,
@ -204,7 +191,28 @@ class MuSR_td_PSI_bin {
int offset = 0, int offset = 0,
double y_offset = 0.); double y_offset = 0.);
double *get_error_asymmetry_array(int histo_num_plus, std::vector<double> GetAsymmetryVector(int histo_num_plus,
int histo_num_minus,
double alpha_param,
int binning,
int lower_bckgrd_plus,
int higher_bckgrd_plus,
int lower_bckgrd_minus,
int higher_bckgrd_minus,
int offset = 0,
double y_offset = 0.);
double *GetErrorAsymmetryArray(int histo_num_plus,
int histo_num_minus,
double alpha_param,
int binning,
int lower_bckgrd_plus,
int higher_bckgrd_plus,
int lower_bckgrd_minus,
int higher_bckgrd_minus,
int offset = 0);
std::vector<double> GetErrorAsymmetryVector(int histo_num_plus,
int histo_num_minus, int histo_num_minus,
double alpha_param, double alpha_param,
int binning, int binning,
@ -214,17 +222,7 @@ class MuSR_td_PSI_bin {
int higher_bckgrd_minus, int higher_bckgrd_minus,
int offset = 0); int offset = 0);
std::vector<double> get_error_asymmetry_vector(int histo_num_plus, double *GetAsymmetryGoodBinsArray(int histo_num_plus,
int histo_num_minus,
double alpha_param,
int binning,
int lower_bckgrd_plus,
int higher_bckgrd_plus,
int lower_bckgrd_minus,
int higher_bckgrd_minus,
int offset = 0);
double *get_asymmetry_goodBins_array(int histo_num_plus,
int histo_num_minus, int histo_num_minus,
double alpha_param, double alpha_param,
int binning, int binning,
@ -233,16 +231,16 @@ class MuSR_td_PSI_bin {
int lower_bckgrd_minus, int lower_bckgrd_minus,
int higher_bckgrd_minus); int higher_bckgrd_minus);
std::vector<double> get_asymmetry_goodBins_vector(int histo_num_plus, std::vector<double> GetAsymmetryGoodBinsVector(int histo_num_plus,
int histo_num_minus, int histo_num_minus,
double alpha_param, double alpha_param,
int binning, int binning,
int lower_bckgrd_plus, int lower_bckgrd_plus,
int higher_bckgrd_plus, int higher_bckgrd_plus,
int lower_bckgrd_minus, int lower_bckgrd_minus,
int higher_bckgrd_minus); int higher_bckgrd_minus);
double *get_error_asymmetry_goodBins_array(int histo_num_plus, double *GetErrorAsymmetryGoodBinsArray(int histo_num_plus,
int histo_num_minus, int histo_num_minus,
double alpha_param, double alpha_param,
int binning, int binning,
@ -251,103 +249,103 @@ class MuSR_td_PSI_bin {
int lower_bckgrd_minus, int lower_bckgrd_minus,
int higher_bckgrd_minus); int higher_bckgrd_minus);
std::vector<double> get_error_asymmetry_goodBins_vector(int histo_num_plus, std::vector<double> GetErrorAsymmetryGoodBinsVector(int histo_num_plus,
int histo_num_minus, int histo_num_minus,
double alpha_param, double alpha_param,
int binning, int binning,
int lower_bckgrd_plus, int lower_bckgrd_plus,
int higher_bckgrd_plus, int higher_bckgrd_plus,
int lower_bckgrd_minus, int lower_bckgrd_minus,
int higher_bckgrd_minus); int higher_bckgrd_minus);
double get_binWidth_ps(); double GetBinWidthPicoSec();
void put_binWidth_ps(double binWidth); void PutBinWidthPicoSec(double binWidth);
double get_binWidth_ns(); double GetBinWidthNanoSec();
void put_binWidth_ns(double binWidth); void PutBinWidthNanoSec(double binWidth);
double get_binWidth_us(); double GetBinWidthMicroSec();
void put_binWidth_us(double binWidth); void PutBinWidthMicroSec(double binWidth);
int get_histoLength_bin(); int GetHistoLengthBin() { return fLengthHisto; }
void put_histoLength_bin(int val) { length_histo = val; } void PutHistoLengthBin(int val) { fLengthHisto = val; }
int get_numberHisto_int(); int GetNumberHistoInt() { return fNumberHisto; }
void put_numberHisto_int(int val) { number_histo = val; } void PutNumberHistoInt(int val) { fNumberHisto = val; }
std::string get_nameHisto(int i); std::string GetNameHisto(int i);
int put_nameHisto(std::string histoName, int i); int PutNameHisto(std::string histoName, int i);
std::vector<std::string> get_histoNames_vector(); std::vector<std::string> GetHistoNamesVector();
int put_histoNames_vector(std::vector<std::string> &histoNames); int PutHistoNamesVector(std::vector<std::string> &histoNames);
long get_eventsHisto_long(int i); long GetEventsHistoLong(int i);
std::vector<long> get_eventsHisto_vector(); std::vector<long> GetEventsHistoVector();
long get_totalEvents_long(); long GetTotalEventsLong() { return long(fTotalEvents); }
int get_numberScaler_int(); int GetNumberScalerInt();
int put_numberScaler_int(int val); int PutNumberScalerInt(int val);
std::vector<long> get_scalers_vector(); std::vector<long> GetScalersVector();
int put_scalers_vector(std::vector<int> scalerData); int PutScalersVector(std::vector<int> scalerData);
std::vector<std::string> get_scalersNames_vector(); std::vector<std::string> GetScalersNamesVector();
int put_scalersNames_vector(std::vector<std::string> scalersName); int PutScalersNamesVector(std::vector<std::string> scalersName);
int get_default_binning(); int GetDefaultBinning();
int get_t0_int(int i); int GetT0Int(int i);
int put_t0_int(int histoNo, int t0); int PutT0Int(int histoNo, int t0);
std::vector<int> get_t0_vector(); std::vector<int> GetT0Vector();
int put_t0_vector(std::vector<int> &t0Data); int PutT0Vector(std::vector<int> &t0Data);
double get_t0_double(int i); double GetT0Double(int i);
int get_max_t0_int (); int GetMaxT0Int();
int get_max_2_t0_int (int k, int j); int GetMax2T0Int (int k, int j);
int get_min_t0_int (); int GetMinT0Int();
int get_min_2_t0_int (int k, int j); int GetMin2T0Int (int k, int j);
int get_firstGood_int(int i); int GetFirstGoodInt(int i);
std::vector<int> get_firstGood_vector(); std::vector<int> GetFirstGoodVector();
int put_firstGood_int(int i, int j); int PutFirstGoodInt(int i, int j);
int get_lastGood_int(int i); int GetLastGoodInt(int i);
std::vector<int> get_lastGood_vector(); std::vector<int> GetLastGoodVector();
int put_lastGood_int(int i, int j); int PutLastGoodInt(int i, int j);
int get_max_lastGood_int (); int GetMaxLastGoodInt();
int get_max_2_lastGood_int (int k, int j); int GetMax2LastGoodInt (int k, int j);
int get_min_lastGood_int (); int GetMinLastGoodInt();
int get_min_2_lastGood_int (int k, int j); int GetMin2LastGoodInt (int k, int j);
int get_runNumber_int(); int GetRunNumberInt() { return fNumRun; }
int put_runNumber_int(int i); int PutRunNumberInt(int i);
std::string get_sample(); std::string GetSample();
int put_sample(std::string sample); int PutSample(std::string sample);
std::string get_field(); std::string GetField();
int put_field(std::string field); int PutField(std::string field);
std::string get_orient(); std::string GetOrient();
int put_orient(std::string orientation); int PutOrient(std::string orientation);
std::string get_temp(); std::string GetTemp();
int put_temp(std::string temp); int PutTemp(std::string temp);
std::string get_setup(); std::string GetSetup();
int put_setup(std::string setup); int PutSetup(std::string setup);
std::string get_comment(); std::string GetComment();
int put_comment(std::string comment); int PutComment(std::string comment);
std::vector<std::string> get_timeStart_vector(); std::vector<std::string> GetTimeStartVector();
int put_timeStart_vector(std::vector<std::string> timeStart); int PutTimeStartVector(std::vector<std::string> timeStart);
std::vector<std::string> get_timeStop_vector(); std::vector<std::string> GetTimeStopVector();
int put_timeStop_vector(std::vector<std::string> timeStop); int PutTimeStopVector(std::vector<std::string> timeStop);
int get_numberTemperature_int(); int GetNumberTemperatureInt() { return fNumberTemper; }
int put_numberTemperature_int(int noOfTemps); int PutNumberTemperatureInt(int noOfTemps);
std::vector<double> get_temperatures_vector(); std::vector<double> GetTemperaturesVector();
int put_temperatures_vector(std::vector<double> &temps); int PutTemperaturesVector(std::vector<double> &temps);
std::vector<double> get_devTemperatures_vector(); std::vector<double> GetDevTemperaturesVector();
int put_devTemperatures_vector(std::vector<double> &devTemps); int PutDevTemperaturesVector(std::vector<double> &devTemps);
private: private:
int tmax(int x, int y); int Tmax(int x, int y);
int tmin(int x, int y); int Tmin(int x, int y);
} ; } ;
#endif #endif