PSCalib/src/CSPad2x2CalibPars.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id$
00004 //
00005 // Description:
00006 //      Class CSPad2x2CalibPars...
00007 //
00008 // Author List:
00009 //      Mikhail S. Dubrovin
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "PSCalib/CSPad2x2CalibPars.h"
00017 
00018 //-----------------
00019 // C/C++ Headers --
00020 //-----------------
00021 #include <iostream>
00022 #include <iomanip>  // for std::setw
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "MsgLogger/MsgLogger.h"
00028 #include "PSCalib/CalibFileFinder.h"
00029 
00030 //-----------------------------------------------------------------------
00031 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00032 //-----------------------------------------------------------------------
00033 using namespace std;
00034 
00035 //              ----------------------------------------
00036 //              -- Public Function Member Definitions --
00037 //              ----------------------------------------
00038 
00039 namespace PSCalib {
00040 
00041 const char logger[] = "PSCalib";
00042 
00043 //----------------
00044 // Constructors --
00045 //----------------
00046 
00047 CSPad2x2CalibPars::CSPad2x2CalibPars (bool isTestMode)
00048   : m_calibDir     (std::string())
00049   , m_typeGroupName(std::string())
00050   , m_source       (std::string())
00051   , m_runNumber    (0)
00052 {
00053     // Test staff:
00054     m_isTestMode = isTestMode;
00055     if (m_isTestMode) {
00056       //m_calibdir      = "/reg/d/psdm/mec/mec73313/calib";
00057         m_calibdir      = "/reg/d/psdm/xpp/xpptut13/calib";
00058         m_calibfilename = "0-end.data";
00059     }
00060 
00061     fillCalibNameVector ();
00062     loadCalibPars ();
00063     //printCalibPars();
00064 }
00065 
00066 //----------------
00067 
00068 CSPad2x2CalibPars::CSPad2x2CalibPars ( const std::string&   calibDir,      //  "/reg/d/psdm/xpp/xpptut13/calib"
00069                                        const std::string&   typeGroupName, //  "CsPad2x2::CalibV1"
00070                                        const std::string&   source,        //  "XppGon.0:Cspad2x2.1"
00071                                        const unsigned long& runNumber )    //  10
00072   : m_calibDir(calibDir)
00073   , m_typeGroupName(typeGroupName)
00074   , m_source(source)
00075   , m_runNumber(runNumber)
00076 {
00077     m_isTestMode = false;
00078 
00079     fillCalibNameVector ();
00080     loadCalibPars ();
00081 
00082     printInputPars ();
00083     //printCalibPars();
00084 }
00085 
00086 
00087 //----------------
00088 
00089 CSPad2x2CalibPars::CSPad2x2CalibPars ( const std::string&   calibDir,      //  "/reg/d/psdm/xpp/xpptut13/calib"
00090                                        const std::string&   typeGroupName, //  "CsPad2x2::CalibV1"
00091                                        const Pds::Src&      src,           //  Pds::Src m_src; <- is defined in get(...,&m_src)
00092                                        const unsigned long& runNumber )    //  10
00093   : m_calibDir(calibDir)
00094   , m_typeGroupName(typeGroupName)
00095   , m_source(std::string())
00096   , m_src(src)
00097   , m_runNumber(runNumber)
00098 {
00099     m_isTestMode = false;
00100 
00101     fillCalibNameVector ();
00102     loadCalibPars ();
00103 
00104     printInputPars ();
00105     //printCalibPars();
00106 }
00107 
00108 //----------------
00109 
00110 void CSPad2x2CalibPars::fillCalibNameVector ()
00111 {
00112     v_calibname.clear();
00113     v_calibname.push_back("center");
00114     v_calibname.push_back("tilt");
00115 }
00116 
00117 //----------------
00118 
00119 void CSPad2x2CalibPars::loadCalibPars ()
00120 {
00121     for( vector<std::string>::const_iterator iterCalibName  = v_calibname.begin();
00122                                              iterCalibName != v_calibname.end(); iterCalibName++ )
00123       {
00124         m_cur_calibname = *iterCalibName;
00125 
00126         getCalibFileName();
00127 
00128         if (m_fname == std::string()) { 
00129           fillDefaultCalibParsV1 ();
00130           msgUseDefault ();
00131           m_calibtype_status[m_cur_calibname] = 0; 
00132         } 
00133         else 
00134         {
00135           openCalibFile   ();
00136           readCalibPars   ();
00137           closeCalibFile  ();
00138           fillCalibParsV1 ();
00139           m_calibtype_status[m_cur_calibname] = 1; 
00140         }
00141       }
00142 }
00143 
00144 //----------------
00145 
00146 void CSPad2x2CalibPars::getCalibFileName ()
00147 {
00148   if ( m_isTestMode ) 
00149     {
00150       m_fname  = m_calibdir + "/"; 
00151       m_fname += m_cur_calibname + "/"; 
00152       m_fname += m_calibfilename; // "/0-end.data"; // !!! THIS IS A SIMPLIFIED CASE OF THE FILE NAME!!!
00153     }
00154   else if (m_calibDir == std::string())
00155     {
00156       m_fname = std::string();
00157     }
00158   else
00159     {
00160       PSCalib::CalibFileFinder *calibfinder = new PSCalib::CalibFileFinder(m_calibDir, m_typeGroupName);
00161       //m_fname = calibfinder -> findCalibFile(m_src, m_cur_calibname, m_runNumber);
00162 
00163       if (m_source == std::string())
00164           m_fname = calibfinder -> findCalibFile(m_src, m_cur_calibname, m_runNumber);
00165       else
00166           m_fname = calibfinder -> findCalibFile(m_source, m_cur_calibname, m_runNumber);
00167     }
00168   MsgLog("CSPad2x2CalibPars", debug, "getCalibFileName(): " << m_fname);
00169 }
00170 
00171 //----------------
00172 
00173 void CSPad2x2CalibPars::openCalibFile ()
00174 {
00175    m_file.open(m_fname.c_str());
00176 
00177    if (not m_file.good()) {
00178      const std::string msg = "Failed to open file: "+m_fname;
00179      MsgLogRoot(error, msg);
00180      //throw std::runtime_error(msg);
00181    }
00182 }
00183 
00184 //----------------
00185 
00186 void CSPad2x2CalibPars::closeCalibFile ()
00187 {
00188    m_file.close();
00189 }
00190 
00191 //----------------
00192 
00193 void CSPad2x2CalibPars::readCalibPars ()
00194 {
00195   v_parameters.clear();
00196   std::string str;
00197   do{ 
00198       m_file >> str; 
00199       if(m_file.good()) {
00200          v_parameters.push_back(std::atof(str.c_str())); // cout << str << " "; 
00201       }
00202   } while( m_file.good() );                            // cout << endl << endl;
00203 }
00204 
00205 //----------------
00206 
00207 void CSPad2x2CalibPars::fillCalibParsV1 ()
00208 {
00209        if( m_cur_calibname == v_calibname[0] ) m_center = new pdscalibdata::CsPad2x2CenterV1(v_parameters);
00210   else if( m_cur_calibname == v_calibname[1] ) m_tilt   = new pdscalibdata::CsPad2x2TiltV1(v_parameters);
00211 }
00212 
00213 //----------------
00214 
00215 void CSPad2x2CalibPars::fillDefaultCalibParsV1 ()
00216 {
00217   // If default parameters are available - set them.
00218   // For calib types where default parameters are not accaptable and the file is missing - error message and abort.
00219        if( m_cur_calibname == v_calibname[0] ) m_center = new pdscalibdata::CsPad2x2CenterV1();
00220   else if( m_cur_calibname == v_calibname[1] ) m_tilt   = new pdscalibdata::CsPad2x2TiltV1();
00221 
00222   else fatalMissingFileName ();
00223 }
00224 
00225 //----------------
00226 
00227 void CSPad2x2CalibPars::fatalMissingFileName ()
00228 {
00229         MsgLog("CSPad2x2CalibPars", warning, "In getCalibFileName(): the calibration file for the source=" << m_source 
00230                   << ", type=" << m_cur_calibname 
00231                   << ", run=" <<  m_runNumber
00232                   << " is not found ..."
00233                   << "\nWARNING: Default CSPad2x2 alignment constants can not guarantee correct geometry and are not available yet."
00234                   << "\nWARNING: Please provide all expected CSPad alignment constants under the directory .../<experiment>/calib/...");
00235         abort();
00236 }
00237 
00238 //----------------
00239 
00240 void CSPad2x2CalibPars::msgUseDefault ()
00241 {
00242         MsgLog("CSPad2x2CalibPars", info, "In getCalibFileName(): the calibration file for the source=" << m_source 
00243                   << ", type=" << m_cur_calibname 
00244                   << ", run=" <<  m_runNumber
00245                   << " is not found ..."
00246                   << "\nWARNING: Default CSPad2x2 alignment constants will be used.");
00247 }
00248 
00249 //----------------
00250 
00251 void CSPad2x2CalibPars::printCalibPars()
00252 {
00253     WithMsgLog("CSPad2x2CalibPars", info, str) {
00254       str << "printCalibPars()" ;
00255       str << "\n getColSize_um()    = " << getColSize_um() ;
00256       str << "\n getRowSize_um()    = " << getRowSize_um() ;
00257       str << "\n getGapRowSize_um() = " << getGapRowSize_um() ;
00258     }        
00259 
00260      m_center         -> print();
00261      m_tilt           -> print();
00262 }
00263 
00264 //----------------
00265 
00266 void CSPad2x2CalibPars::printInputPars()
00267 {
00268     WithMsgLog("CSPad2x2CalibPars", info, str) {
00269       str << "printInputPars()" ;
00270       str << "\n m_calibDir      = " << m_calibDir ;
00271       str << "\n m_typeGroupName = " << m_typeGroupName ;
00272       str << "\n m_source        = " << m_source ;
00273       str << "\n m_runNumber     = " << m_runNumber ;
00274     }        
00275 }
00276 
00277 //----------------
00278 
00279 void CSPad2x2CalibPars::printCalibParsStatus ()
00280 {
00281     WithMsgLog("CSPad2x2CalibPars", info, str) {
00282       str << "printCalibParsStatus()" ;
00283 
00284       for( vector<std::string>::const_iterator iterCalibName  = v_calibname.begin();
00285                                                iterCalibName != v_calibname.end(); iterCalibName++ )
00286       {
00287           m_cur_calibname = *iterCalibName;
00288           str << "\n type: "  << std::left << std::setw(20) << m_cur_calibname
00289               << " status = " << m_calibtype_status[m_cur_calibname]; 
00290       }
00291     }        
00292 }
00293 
00294 //--------------
00295 // Destructor --
00296 //--------------
00297 
00298 CSPad2x2CalibPars::~CSPad2x2CalibPars ()
00299 {
00300   //delete [] m_data; 
00301 }
00302 
00303 //----------------
00304 //----------------
00305 //----------------
00306 //----------------
00307 
00308 } // namespace PSCalib

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7