Changeset 15214
- Timestamp:
- 03/31/13 12:07:46 (12 years ago)
- Location:
- trunk/Mars/mcore
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/PixelMap.cc
r15212 r15214 1 #include "PixelMap.h" 2 3 #ifdef __EXCEPTIONS 4 #include <stdexcept> 5 #endif 6 7 #ifdef __MARS__ 8 #include "MLog.h" 9 #include "MLogManip.h" 10 #endif 1 #include "externals/PixelMap.h" 11 2 12 3 using namespace std; 13 4 14 const PixelMapEntry PixelMap::empty = { -1, 0, 0, 0, 0 };15 const BiasMapEntry BiasMap::empty = { -1, 0, 0, 0 };16 17 bool BiasMap::Read(const std::string &fname)18 {19 std::ifstream fin(fname);20 21 int l = 0;22 23 std::string buf;24 while (getline(fin, buf, '\n'))25 {26 if (l>416)27 break;28 29 buf = Tools::Trim(buf);30 if (buf[0]=='#')31 continue;32 33 std::stringstream str(buf);34 35 BiasMapEntry entry;36 37 str >> entry.hv_board;38 str >> entry.hv_channel;39 str >> entry.Vnom;40 str >> entry.Voff;41 42 #ifdef __EXCEPTIONS43 if (entry.hv_channel+32*entry.hv_board>=416)44 throw runtime_error("Invalid board/channel read from "+fname+".");45 #endif46 #ifdef __MARS__47 if (entry.hv_channel+32*entry.hv_board>=416)48 {49 gLog << err << "Invalid board/channel read from " << fname << "." << endl;50 return false;51 }52 #endif53 54 (*this)[entry.hv()] = entry;55 56 l++;57 }58 59 #ifdef __EXCEPTIONS60 if (l!=416)61 throw runtime_error("Number of lines read from "+fname+" does not match 416.");62 63 if (size()!=416)64 throw runtime_error("Number of entries read from "+fname+" does not match 416.");65 #endif66 67 #ifdef __MARS__68 if (l!=416)69 {70 gLog << err << "Number of lines read from " << fname << " does not match 416." << endl;71 return false;72 }73 74 if (size()!=416)75 {76 gLog << "Number of entries read from " << fname << " does not match 416." << endl;77 return false;78 }79 #endif80 81 return true;82 }83 84 #ifndef __MARS__85 5 #include <boost/regex.hpp> 86 6 #include <mysql++/mysql++.h> … … 148 68 throw runtime_error("Number of entries retrived from database does not match 416."); 149 69 } 150 #endif -
trunk/Mars/mcore/PixelMap.h
r15212 r15214 7 7 #include <sstream> 8 8 9 #include "tools.h"10 11 9 #ifdef DEBUG 12 10 #include <iostream> // cerr -- to be removed? 11 #endif 12 13 #ifdef __EXCEPTIONS 14 #include <stdexcept> 15 #endif 16 17 #ifdef __MARS__ 18 #include "MLog.h" 19 #include "MLogManip.h" 13 20 #endif 14 21 … … 22 29 // float Vgapd; /// gAPD Bias voltage 23 30 int hv_board; /// Bias suppply board 24 int hv_channel; /// Bias supply channel 31 int hv_channel; 32 33 PixelMapEntry() : index(-1) { } /// Bias supply channel 25 34 26 35 int crate() const { return cbpx/1000; } … … 33 42 34 43 operator bool() const { return index>=0; } 44 45 static const PixelMapEntry &empty() { const static PixelMapEntry e; return e; } 35 46 }; 36 47 … … 38 49 { 39 50 public: 40 static const PixelMapEntry empty;41 42 51 PixelMap() : std::vector<PixelMapEntry>(1440) 43 52 { … … 56 65 break; 57 66 58 buf = Tools::Trim(buf); 59 if (buf[0]=='#') 67 buf.erase(buf.find_last_not_of(' ')+1); //surfixing spaces 68 buf.erase(0, buf.find_first_not_of(' ')); //prefixing spaces 69 70 if (buf.empty() || buf[0]=='#') 60 71 continue; 61 72 … … 101 112 std::cerr << "PixelMap: index " << idx << " not found" << std::endl; 102 113 #endif 103 return empty;114 return PixelMapEntry::empty(); 104 115 } 105 116 … … 112 123 std::cerr << "PixelMap: cbpx " << c << " not found" << std::endl; 113 124 #endif 114 return empty;125 return PixelMapEntry::empty(); 115 126 } 116 127 … … 133 144 std::cerr << "PixelMap: hv " << board << "/" << channel << " not found" << std::endl; 134 145 #endif 135 return empty;146 return PixelMapEntry::empty(); 136 147 } 137 148 … … 192 203 float Voff; /// Channel bias voltage offset 193 204 205 BiasMapEntry() : hv_board(-1) { } 206 194 207 int hv() const { return hv_channel+hv_board*32; } 208 209 operator bool() const { return hv_board>=0; } 210 211 static const BiasMapEntry &empty() { const static BiasMapEntry e; return e; } 195 212 }; 196 213 … … 198 215 { 199 216 public: 200 static const BiasMapEntry empty;201 202 217 BiasMap() : std::vector<BiasMapEntry>(416) 203 218 { … … 207 222 void Retrieve(const std::string &database); 208 223 #endif 209 bool Read(const std::string &fname); 224 bool Read(const std::string &fname) 225 { 226 std::ifstream fin(fname); 227 228 int l = 0; 229 230 std::string buf; 231 while (getline(fin, buf, '\n')) 232 { 233 if (l>416) 234 break; 235 236 buf.erase(buf.find_last_not_of(' ')+1); //surfixing spaces 237 buf.erase(0, buf.find_first_not_of(' ')); //prefixing spaces 238 239 if (buf.empty() || buf[0]=='#') 240 continue; 241 242 std::stringstream str(buf); 243 244 BiasMapEntry entry; 245 246 str >> entry.hv_board; 247 str >> entry.hv_channel; 248 str >> entry.Vnom; 249 str >> entry.Voff; 250 251 #ifdef __EXCEPTIONS 252 if (entry.hv_channel+32*entry.hv_board>=416) 253 throw std::runtime_error("Invalid board/channel read from "+fname+"."); 254 #endif 255 #ifdef __MARS__ 256 if (entry.hv_channel+32*entry.hv_board>=416) 257 { 258 gLog << err << "Invalid board/channel read from " << fname << "." << endl; 259 return false; 260 } 261 #endif 262 263 (*this)[entry.hv()] = entry; 264 265 l++; 266 } 267 268 #ifdef __EXCEPTIONS 269 if (l!=416) 270 throw std::runtime_error("Number of lines read from "+fname+" does not match 416."); 271 272 if (size()!=416) 273 throw std::runtime_error("Number of entries read from "+fname+" does not match 416."); 274 #endif 275 276 #ifdef __MARS__ 277 if (l!=416) 278 { 279 gLog << err << "Number of lines read from " << fname << " does not match 416." << endl; 280 return false; 281 } 282 283 if (size()!=416) 284 { 285 gLog << "Number of entries read from " << fname << " does not match 416." << endl; 286 return false; 287 } 288 #endif 289 290 return true; 291 } 210 292 211 293 const BiasMapEntry &hv(int board, int channel) const … … 217 299 std::cerr << "PixelMap: hv " << board << "/" << channel << " not found" << std::endl; 218 300 #endif 219 return empty;301 return BiasMapEntry::empty(); 220 302 } 221 303
Note:
See TracChangeset
for help on using the changeset viewer.