00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "pdscalibdata/CsPad2x2PixelGainV1.h"
00017
00018
00019
00020
00021 #include <algorithm>
00022 #include <stdexcept>
00023 #include <fstream>
00024
00025
00026
00027
00028 #include "MsgLogger/MsgLogger.h"
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace pdscalibdata {
00039
00040
00041
00042
00043 CsPad2x2PixelGainV1::CsPad2x2PixelGainV1 ()
00044 {
00045
00046 std::fill_n(m_pixelGains, int(Size), pixelGain_t(0));
00047 }
00048
00049 CsPad2x2PixelGainV1::CsPad2x2PixelGainV1 (const std::string& fname)
00050 {
00051
00052 std::ifstream in(fname.c_str());
00053 if (not in.good()) {
00054 const std::string msg = "Failed to open pixel gain file: "+fname;
00055 MsgLogRoot(error, msg);
00056 throw std::runtime_error(msg);
00057 }
00058
00059
00060 pixelGain_t* it = m_pixelGains;
00061 size_t count = 0;
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 pixelGain_t val;
00073 std::string str;
00074 while(getline(in,str)) {
00075
00076 if(str[0] == '#') continue;
00077
00078
00079 else if (str.find_first_not_of(" ")==std::string::npos) continue;
00080
00081
00082 else {
00083 std::stringstream ss(str);
00084 while (ss >> val and count != Size) {
00085 *it++ = val;
00086 ++ count;
00087 }
00088 }
00089 }
00090
00091
00092
00093
00094 if (count != Size) {
00095 const std::string msg = "Pixel gain file does not have enough data: "+fname;
00096 MsgLogRoot(error, msg);
00097 throw std::runtime_error(msg);
00098 }
00099
00100
00101 float tmp ;
00102 if ( in >> tmp ) {
00103 ++ count;
00104 const std::string msg = "Pixel gain file has extra data: "+fname;
00105 MsgLogRoot(error, msg);
00106 MsgLogRoot(error, "read " << count << " numbers, expecting " << Size );
00107 throw std::runtime_error(msg);
00108 }
00109 }
00110
00111
00112
00113
00114 CsPad2x2PixelGainV1::~CsPad2x2PixelGainV1 ()
00115 {
00116 }
00117
00118 }