00001 #ifndef SCALA_UTIL
00002 #define SCALA_UTIL
00003
00004 #include <string>
00005 #include "hkl_datatypes.hh"
00006
00007 namespace scala
00008 {
00009
00010
00011
00012 std::string BaseFileName(const std::string& Name, const bool NoExt=true);
00013
00014 std::string FileNameNoExtension(const std::string& Name);
00015
00016 void AddFileExtension(std::string& name, const std::string& ext);
00017
00018
00019 std::string Directory(const std::string& Name);
00020
00021
00022 std::string FormatCell(const std::vector<double>& cell,
00023 const int w=7, const int p=4);
00024
00025
00026 std::string FormatCell(const Scell& cell, const int w=7, const int p=4);
00027
00028 RPair MnSd(const std::vector<double>& val);
00029
00030
00031 int IRandom(const int& MaxVal);
00032
00033
00034 float FRandom(const float& MaxVal);
00035
00036
00037 double FRandom(const double& MaxVal);
00038
00039
00040
00041 double SafeSqrt(const double& a);
00042
00043
00044
00045
00046
00047 Scell AverageDsetCell(const std::vector<Xdataset>& datasets);
00048
00049
00050
00051
00052
00053
00054
00055 std::vector<Scell> AverageBatchCell(const std::vector<Batch>& batches,
00056 const int& Ndatasets,
00057 std::vector<float>& averageMosaicity,
00058 std::vector<float>& averageWavelength);
00059
00060
00061
00062
00063
00064 float AverageDsetWavelength(const std::vector<Xdataset>& datasets);
00065
00066
00067
00068 float AverageWavelength(const std::vector<float>& allwavelengths,
00069 const int& idxexclude=-1);
00070
00071
00072 class MeanSD
00073
00074 {
00075 public:
00076 MeanSD() : sum_sc(0.0), sum_sc2(0.0), count(0) {}
00077 MeanSD(const std::vector<float>& list);
00078 MeanSD(const std::vector<double>& list);
00079
00080
00081 void initExclude(const std::vector<float>& list, const int& idxexclude=-1);
00082 void initExclude(const std::vector<double>& list, const int& idxexclude=-1);
00083
00084 void Add(const float& v);
00085 void Add(const double& v);
00086 void clear() {sum_sc=0.0; sum_sc2=0.0; count=0;}
00087
00088 double Mean() const;
00089 double SD() const;
00090 double Var() const;
00091 int Count() const {return count;}
00092
00093 std::string format() const;
00094
00095 MeanSD& operator+=(const MeanSD& other);
00096 friend MeanSD& operator+ (const MeanSD& a, const MeanSD& b);
00097 static bool MeanSDsmallerSD(const MeanSD& a, const MeanSD& b);
00098
00099 private:
00100 double sum_sc;
00101 double sum_sc2;
00102 int count;
00103 };
00104
00105 class MeanValue
00106
00107 {
00108 public:
00109 MeanValue() : sum_sc(0.0), count(0) {}
00110 MeanValue(const std::vector<float>& list);
00111 MeanValue(const std::vector<double>& list);
00112
00113 void Add(const float& v);
00114 void Add(const double& v);
00115 void clear() {sum_sc=0.0; count=0;}
00116
00117 double Mean() const;
00118 int Count() const {return count;}
00119
00120 std::string format() const;
00121
00122 MeanValue& operator+=(const MeanValue& other);
00123 friend MeanValue& operator+ (const MeanValue& a, const MeanValue& b);
00124
00125 private:
00126 double sum_sc;
00127 int count;
00128 };
00129 }
00130
00131 #endif
00132