00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "PSCalib/GenericCalibPars.h"
00017
00018
00019
00020
00021 #include <iostream>
00022 #include <iomanip>
00023 #include <sstream>
00024
00025
00026
00027
00028 #include "MsgLogger/MsgLogger.h"
00029 #include "PSCalib/CalibFileFinder.h"
00030
00031 #include "pdscalibdata/CsPadBaseV2.h"
00032 #include "pdscalibdata/CsPad2x2BaseV2.h"
00033 #include "pdscalibdata/PnccdBaseV1.h"
00034 #include "pdscalibdata/PrincetonBaseV1.h"
00035 #include "pdscalibdata/AndorBaseV1.h"
00036 #include "pdscalibdata/Andor3dBaseV1.h"
00037 #include "pdscalibdata/Epix100aBaseV1.h"
00038 #include "pdscalibdata/VarShapeCameraBaseV1.h"
00039
00040
00041
00042
00043
00044
00045 using namespace std;
00046
00047
00048
00049
00050
00051 namespace PSCalib {
00052
00053 const char logger[] = "PSCalib";
00054
00055
00056
00057
00058
00059 template <typename TBASE>
00060 GenericCalibPars<TBASE>::GenericCalibPars ( const std::string& calibDir,
00061 const std::string& groupName,
00062 const std::string& source,
00063 const unsigned long& runNumber,
00064 unsigned print_bits)
00065 : PSCalib::CalibPars()
00066 , TBASE()
00067 , m_calibDir(calibDir)
00068 , m_groupName(groupName)
00069 , m_source(source)
00070 , m_runNumber(runNumber)
00071 , m_print_bits(print_bits)
00072 {
00073 init();
00074 }
00075
00076
00077
00078 template <typename TBASE>
00079 GenericCalibPars<TBASE>::GenericCalibPars ( const std::string& calibDir,
00080 const std::string& groupName,
00081 const Pds::Src& src,
00082 const unsigned long& runNumber,
00083 unsigned print_bits)
00084 : PSCalib::CalibPars()
00085 , TBASE()
00086 , m_calibDir(calibDir)
00087 , m_groupName(groupName)
00088 , m_source(std::string())
00089 , m_src(src)
00090 , m_runNumber(runNumber)
00091 , m_print_bits(print_bits)
00092 {
00093 init();
00094 }
00095
00096
00097
00098 template <typename TBASE>
00099 void GenericCalibPars<TBASE>::init()
00100 {
00101 m_pedestals = 0;
00102 m_pixel_gain = 0;
00103 m_pixel_mask = 0;
00104 m_pixel_bkgd = 0;
00105 m_pixel_rms = 0;
00106 m_common_mode = 0;
00107 m_pixel_status = 0;
00108 m_name = std::string("GenericCalibPars");
00109 m_size = TBASE::size_base();
00110 m_size_cm = TBASE::SizeCM;
00111
00112 if( m_print_bits & 1 ) printInputPars();
00113 if( m_print_bits & 16) printCalibTypes();
00114 m_prbits_cff = ( m_print_bits & 2 ) ? 0377 : 0;
00115 m_prbits_type = ( m_print_bits & 32 ) ? 0377 : 0;
00116 }
00117
00118
00119
00120 template <typename TBASE>
00121 std::string GenericCalibPars<TBASE>::getCalibFileName (const CALIB_TYPE& calibtype)
00122 {
00123 std::string fname = std::string();
00124 if (m_calibDir != std::string()) {
00125
00126
00127 PSCalib::CalibFileFinder calibfinder(m_calibDir, m_groupName, m_prbits_cff);
00128
00129 if (m_source.empty())
00130 fname = calibfinder.findCalibFile(m_src, map_type2str[calibtype], m_runNumber);
00131 else
00132 fname = calibfinder.findCalibFile(m_source, map_type2str[calibtype], m_runNumber);
00133 }
00134
00135 if( m_print_bits & 4 ) MsgLog(m_name, info, "Use calibration parameters from file: " << fname);
00136 if( m_print_bits & 8 && fname.empty() )
00137 MsgLog(m_name, warning, "File for calibration type " << map_type2str[calibtype]
00138 << " IS MISSING! Use default calibration parameters on your own risk...");
00139
00140 return fname;
00141 }
00142
00143
00144
00145 template <typename TBASE>
00146 const CalibPars::pedestals_t*
00147 GenericCalibPars<TBASE>::pedestals()
00148 {
00149 if(m_print_bits & 64) MsgLog(m_name, info, "GenericCalibPars<TBASE>::pedestals()");
00150
00151 if (m_pedestals == 0) {
00152 std::string fname = getCalibFileName(PEDESTALS);
00153
00154 if (m_size) m_pedestals = new NDAIPEDS(fname, shape(), pedestals_t(0), m_prbits_type);
00155 else m_pedestals = new NDAIPEDS(fname, m_prbits_type);
00156 m_size = size();
00157 }
00158 return m_pedestals->get_ndarray().data();
00159 }
00160
00161
00162
00163 template <typename TBASE>
00164 const CalibPars::pixel_status_t*
00165 GenericCalibPars<TBASE>::pixel_status()
00166 {
00167 if (m_pixel_status == 0) {
00168 std::string fname = getCalibFileName(PIXEL_STATUS);
00169
00170
00171
00172 if (m_size) m_pixel_status = new NDAISTATUS(fname, shape(), pixel_status_t(1), m_prbits_type);
00173 else m_pixel_status = new NDAISTATUS(fname, m_prbits_type);
00174 m_size = size();
00175 }
00176 return m_pixel_status->get_ndarray().data();
00177 }
00178
00179
00180
00181 template <typename TBASE>
00182 const CalibPars::pixel_gain_t*
00183 GenericCalibPars<TBASE>::pixel_gain()
00184 {
00185 if (m_pixel_gain == 0) {
00186 std::string fname = getCalibFileName(PIXEL_GAIN);
00187 if (m_size) m_pixel_gain = new NDAIGAIN(fname, shape(), pixel_gain_t(1), m_prbits_type);
00188 else m_pixel_gain = new NDAIGAIN(fname, m_prbits_type);
00189 m_size = size();
00190 }
00191 return m_pixel_gain->get_ndarray().data();
00192 }
00193
00194
00195
00196 template <typename TBASE>
00197 const CalibPars::pixel_mask_t*
00198 GenericCalibPars<TBASE>::pixel_mask()
00199 {
00200 if (m_pixel_mask == 0) {
00201 std::string fname = getCalibFileName(PIXEL_MASK);
00202 if (m_size) m_pixel_mask = new NDAIMASK(fname, shape(), pixel_mask_t(1), m_prbits_type);
00203 else m_pixel_mask = new NDAIMASK(fname, m_prbits_type);
00204 m_size = size();
00205 }
00206 return m_pixel_mask->get_ndarray().data();
00207 }
00208
00209
00210
00211 template <typename TBASE>
00212 const CalibPars::pixel_bkgd_t*
00213 GenericCalibPars<TBASE>::pixel_bkgd()
00214 {
00215 if (m_pixel_bkgd == 0) {
00216 std::string fname = getCalibFileName(PIXEL_BKGD);
00217 if (m_size) m_pixel_bkgd = new NDAIBKGD(fname, shape(), pixel_bkgd_t(0), m_prbits_type);
00218 else m_pixel_bkgd = new NDAIBKGD(fname, m_prbits_type);
00219 m_size = size();
00220 }
00221 return m_pixel_bkgd->get_ndarray().data();
00222 }
00223
00224
00225
00226 template <typename TBASE>
00227 const CalibPars::pixel_rms_t*
00228 GenericCalibPars<TBASE>::pixel_rms()
00229 {
00230 if (m_pixel_rms == 0) {
00231 std::string fname = getCalibFileName(PIXEL_RMS);
00232 if (m_size) m_pixel_rms = new NDAIRMS(fname, shape(), pixel_rms_t(1), m_prbits_type);
00233 else m_pixel_rms = new NDAIRMS(fname, m_prbits_type);
00234 m_size = size();
00235 }
00236 return m_pixel_rms->get_ndarray().data();
00237 }
00238
00239
00240
00241 template <typename TBASE>
00242 const CalibPars::common_mode_t*
00243 GenericCalibPars<TBASE>::common_mode()
00244 {
00245 if (m_common_mode == 0) {
00246 std::string fname = getCalibFileName(COMMON_MODE);
00247 ndarray<const CalibPars::common_mode_t,1> nda = make_ndarray(TBASE::cmod_base(), TBASE::SizeCM);
00248 m_common_mode = new NDAICMOD(fname, nda, m_prbits_type);
00249 m_size_cm = TBASE::SizeCM;
00250 }
00251 return m_common_mode->get_ndarray().data();
00252 }
00253
00254
00255
00256 template <typename TBASE>
00257 const size_t
00258 GenericCalibPars<TBASE>::ndim(const CALIB_TYPE& calibtype)
00259 {
00260 return (calibtype!=COMMON_MODE) ? TBASE::Ndim : 1;
00261 }
00262
00263
00264
00265 template <typename TBASE>
00266 const size_t
00267 GenericCalibPars<TBASE>::size(const CALIB_TYPE& calibtype)
00268 {
00269 if(m_print_bits & 64) MsgLog(m_name, info, "GenericCalibPars<TBASE>::size()");
00270
00271 if (calibtype == COMMON_MODE) return TBASE::SizeCM;
00272 size_t s = TBASE::size_base();
00273 return (s) ? s : size_of_ndarray();
00274 }
00275
00276
00277
00278 template <typename TBASE>
00279 const CalibPars::shape_t*
00280
00281 GenericCalibPars<TBASE>::shape(const CALIB_TYPE& calibtype)
00282 {
00283 if(m_print_bits & 64) MsgLog(m_name, info, "GenericCalibPars<TBASE>::shape()");
00284
00285 if(calibtype == COMMON_MODE) {
00286
00287 *m_shape_cm = TBASE::SizeCM;
00288 return m_shape_cm;
00289 }
00290
00291
00292 if (TBASE::size_base()) return TBASE::shape_base();
00293
00294
00295
00296
00297
00298 return shape_of_ndarray();
00299 }
00300
00301
00302 template <typename TBASE>
00303 const int
00304 GenericCalibPars<TBASE>::status(const CALIB_TYPE& calibtype)
00305 {
00306 if(m_print_bits & 64) MsgLog(m_name, info, "GenericCalibPars<TBASE>::status()");
00307
00308
00309
00310
00311 if( calibtype == PEDESTALS && m_pedestals ) return (int)m_pedestals -> status();
00312 if( calibtype == PIXEL_STATUS && m_pixel_status) return (int)m_pixel_status-> status();
00313 if( calibtype == PIXEL_GAIN && m_pixel_gain ) return (int)m_pixel_gain -> status();
00314 if( calibtype == PIXEL_MASK && m_pixel_mask ) return (int)m_pixel_mask -> status();
00315 if( calibtype == PIXEL_BKGD && m_pixel_bkgd ) return (int)m_pixel_bkgd -> status();
00316 if( calibtype == PIXEL_RMS && m_pixel_rms ) return (int)m_pixel_rms -> status();
00317 if( calibtype == COMMON_MODE && m_common_mode ) return (int)m_common_mode -> status();
00318
00319 return 0;
00320 }
00321
00322
00323
00324 template <typename TBASE>
00325 const size_t
00326 GenericCalibPars<TBASE>::size_of_ndarray()
00327 {
00328 if (m_pedestals ) return m_pedestals ->get_ndarray().size();
00329 else if (m_pixel_status) return m_pixel_status->get_ndarray().size();
00330 else if (m_pixel_gain ) return m_pixel_gain ->get_ndarray().size();
00331 else if (m_pixel_mask ) return m_pixel_mask ->get_ndarray().size();
00332 else if (m_pixel_bkgd ) return m_pixel_bkgd ->get_ndarray().size();
00333 else if (m_pixel_rms ) return m_pixel_rms ->get_ndarray().size();
00334 else p_peds = pedestals();
00335
00336 if (m_pedestals ) return m_pedestals ->get_ndarray().size();
00337
00338 if(m_print_bits) MsgLog(m_name, warning, "CAN'T RETURN SIZE of ndarray. "
00339 << "For variable shape camera at least one of calib files should be available.");
00340 return TBASE::size_base();
00341 }
00342
00343
00344
00345 template <typename TBASE>
00346 const CalibPars::shape_t*
00347
00348 GenericCalibPars<TBASE>::shape_of_ndarray()
00349 {
00350 if (m_pedestals ) return m_pedestals ->get_ndarray().shape();
00351 else if (m_pixel_status) return m_pixel_status->get_ndarray().shape();
00352 else if (m_pixel_gain ) return m_pixel_gain ->get_ndarray().shape();
00353 else if (m_pixel_mask ) return m_pixel_mask ->get_ndarray().shape();
00354 else if (m_pixel_bkgd ) return m_pixel_bkgd ->get_ndarray().shape();
00355 else if (m_pixel_rms ) return m_pixel_rms ->get_ndarray().shape();
00356 else p_peds = pedestals();
00357
00358 if (m_pedestals ) return m_pedestals ->get_ndarray().shape();
00359
00360 if(m_print_bits) MsgLog(m_name, warning, "CAN'T RETURN SHAPE of ndarray. "
00361 << "For variable shape camera at least one of calib files should be available.");
00362 return TBASE::shape_base();
00363 }
00364
00365
00366
00367
00368
00369
00370 template <typename TBASE>
00371 void GenericCalibPars<TBASE>::printInputPars()
00372 {
00373 WithMsgLog(m_name, info, str) {
00374 str << "printInputPars()"
00375 << "\n m_calibDir = " << m_calibDir
00376 << "\n m_groupName = " << m_groupName
00377 << "\n m_source = " << m_source
00378 << "\n m_runNumber = " << m_runNumber
00379 << "\n m_print_bits = " << m_print_bits
00380 << "\n size = " << m_size
00381 << "\n size_cm = " << m_size_cm
00382 << "\nDetector base configuration parameters:"
00383 << "\n Ndim = " << TBASE::Ndim;
00384 }
00385 std::cout << "\n Shape = [" << str_shape() << "]\n";
00386
00387
00388 }
00389
00390
00391
00392 template <typename TBASE>
00393 std::string GenericCalibPars<TBASE>::str_shape()
00394 {
00395 std::stringstream smsg;
00396 const CalibPars::shape_t* sh = shape();
00397
00398 for (unsigned i=0; i<TBASE::Ndim; i++) {
00399 if (i) smsg << "," << sh[i];
00400 else smsg << sh[i];
00401 }
00402 return smsg.str();
00403 }
00404
00405
00406
00407 template <typename TBASE>
00408 void GenericCalibPars<TBASE>::loadAllCalibPars ()
00409 {
00410 pedestals();
00411 pixel_gain();
00412 pixel_mask();
00413 pixel_bkgd();
00414 pixel_rms();
00415 pixel_status();
00416 common_mode();
00417 }
00418
00419
00420
00421 template <typename TBASE>
00422 void GenericCalibPars<TBASE>::printCalibParsStatus ()
00423 {
00424
00425
00426 std::stringstream smsg; smsg << "\n printCalibParsStatus():";
00427 if (m_pedestals) smsg << "\n pedestals : " << m_pedestals -> str_status();
00428 if (m_pixel_status) smsg << "\n pixel_status : " << m_pixel_status -> str_status();
00429 if (m_pixel_gain) smsg << "\n pixel_gain : " << m_pixel_gain -> str_status();
00430 if (m_pixel_mask) smsg << "\n pixel_mask : " << m_pixel_mask -> str_status();
00431 if (m_pixel_bkgd) smsg << "\n pixel_bkgd : " << m_pixel_bkgd -> str_status();
00432 if (m_pixel_rms) smsg << "\n pixel_rms : " << m_pixel_rms -> str_status();
00433 if (m_common_mode) smsg << "\n common_mode : " << m_common_mode -> str_status();
00434 MsgLog(m_name, info, smsg.str());
00435 }
00436
00437
00438
00439 template <typename TBASE>
00440 void GenericCalibPars<TBASE>::printCalibPars()
00441 {
00442
00443 printInputPars();
00444 printCalibParsStatus ();
00445
00446 std::stringstream smsg; smsg << "\n printCalibPars():";
00447 if (m_pedestals) { smsg << "\n shape = [" << m_pedestals -> str_shape() << "]"
00448 << "\n pedestals : " << m_pedestals -> str_ndarray_info();
00449 }
00450 if (m_pixel_status) smsg << "\n pixel_status : " << m_pixel_status -> str_ndarray_info();
00451 if (m_pixel_gain) smsg << "\n pixel_gain : " << m_pixel_gain -> str_ndarray_info();
00452 if (m_pixel_mask) smsg << "\n pixel_mask : " << m_pixel_mask -> str_ndarray_info();
00453 if (m_pixel_bkgd) smsg << "\n pixel_bkgd : " << m_pixel_bkgd -> str_ndarray_info();
00454 if (m_pixel_rms) smsg << "\n pixel_rms : " << m_pixel_rms -> str_ndarray_info();
00455 if (m_common_mode) smsg << "\n common_mode : " << m_common_mode -> str_ndarray_info();
00456 MsgLog(m_name, info, smsg.str());
00457 }
00458
00459
00460
00461
00462
00463 template <typename TBASE>
00464 GenericCalibPars<TBASE>::~GenericCalibPars ()
00465 {
00466 if( m_print_bits & 64 ) MsgLog(m_name, info, "DESTRUCTOR is called...");
00467
00468 delete m_pedestals;
00469 delete m_pixel_status;
00470 delete m_pixel_gain;
00471 delete m_pixel_mask;
00472 delete m_pixel_bkgd;
00473 delete m_pixel_rms;
00474 delete m_common_mode;
00475
00476 }
00477
00478
00479
00480
00481
00482
00483 template class PSCalib::GenericCalibPars<pdscalibdata::CsPadBaseV2>;
00484 template class PSCalib::GenericCalibPars<pdscalibdata::CsPad2x2BaseV2>;
00485 template class PSCalib::GenericCalibPars<pdscalibdata::PnccdBaseV1>;
00486 template class PSCalib::GenericCalibPars<pdscalibdata::PrincetonBaseV1>;
00487 template class PSCalib::GenericCalibPars<pdscalibdata::AndorBaseV1>;
00488 template class PSCalib::GenericCalibPars<pdscalibdata::Andor3dBaseV1>;
00489 template class PSCalib::GenericCalibPars<pdscalibdata::Epix100aBaseV1>;
00490 template class PSCalib::GenericCalibPars<pdscalibdata::VarShapeCameraBaseV1>;
00491
00492
00493
00494
00495
00496
00497
00498
00499 }