| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

DbiCalibDataSvc.cc

Go to the documentation of this file.
00001 #include "DbiCalibDataSvc.h"
00002 #include "DataSvc/ICableSvc.h"
00003 #include "GaudiKernel/IMessageSvc.h"
00004 #include "GaudiKernel/SystemOfUnits.h"
00005 
00006 #include "genDbi/GCalibPmtSpec.h"
00007 #include "genDbi/GCalibFeeSpec.h"
00008 
00009 #include "Conventions/Site.h"
00010 #include "Conventions/SimFlag.h"
00011 #include "Conventions/Electronics.h"
00012 #include "Context/TimeStamp.h"
00013 #include "DatabaseInterface/Dbi.h"
00014 #include "DatabaseInterface/DbiResultAgg.h"
00015 #include "DatabaseInterface/DbiCascader.h"
00016 #include "DatabaseInterface/DbiConfigSet.h"
00017 #include "DatabaseInterface/DbiLogEntry.h"
00018 #include "DatabaseInterface/DbiResultKey.h"
00019 #include "DatabaseInterface/DbiResultNonAgg.h"
00020 #include "DatabaseInterface/DbiResultPtr.h"
00021 #include "DatabaseInterface/DbiResultSet.h"
00022 #include "DatabaseInterface/DbiServices.h"
00023 #include "DatabaseInterface/DbiValRecSet.h"
00024 #include "DatabaseInterface/DbiLog.h"
00025 #include "DatabaseInterface/DbiCache.h"
00026 #include "DatabaseInterface/DbiSqlContext.h"
00027 
00028 #include <sstream>
00029 
00030 #include <list>
00031 #include <map>
00032 #include <memory>
00033 using std::auto_ptr;
00034 
00035 using namespace Gaudi;
00036 
00037 DbiCalibDataSvc::DbiCalibDataSvc(const std::string& name, ISvcLocator *svc)
00038     : Service(name,svc)
00039 {
00040   declareProperty("CableSvcName",m_cableSvcName="StaticCableSvc",
00041                   "Name of service which provides the list of sensors to calibration");
00042 }
00043 
00044 DbiCalibDataSvc::~DbiCalibDataSvc()
00045 {
00046 }
00047 
00048 StatusCode DbiCalibDataSvc::initialize()
00049 {
00050   this->Service::initialize();
00051 /*  IMessageSvc* msg = msgSvc();//cxs 2010-12-7
00052   if( !msg ){    
00053     return StatusCode::FAILURE;
00054   }
00055 */
00056   MsgStream msg(msgSvc(),name());
00057   // Initialize the data with a static table of numbers
00058   ICableSvc* cableSvc = 0;
00059   StatusCode sc = service("StaticCableSvc",cableSvc,true);
00060   if( sc != StatusCode::SUCCESS ){
00061     std::ostringstream msgStr;
00062     msgStr << "Failed to access cable service: " << m_cableSvcName;
00063     //msg->reportMessage("DbiCalibDataSvc",MSG::ERROR,msgStr.str());
00064     return sc;    
00065   }
00066   feeLastResult = 0;   //cxs 2010-10-28
00067   fecLastResult = 0;   //cxs 2010-10-28
00068   pmtLastResult = 0;   //cxs 2010-10-28
00069   return StatusCode::SUCCESS;
00070 }
00071 
00072 StatusCode DbiCalibDataSvc::finalize()
00073 {
00074   return this->Service::finalize();
00075 }
00076 
00077 StatusCode DbiCalibDataSvc::queryInterface(const InterfaceID& riid, 
00078                                             void** ppvInterface)
00079 {
00080   StatusCode sc = StatusCode::FAILURE;
00081   if (ppvInterface) {
00082     *ppvInterface = 0;
00083     if (ICalibDataSvc::interfaceID().versionMatch(riid)) {
00084       *ppvInterface = static_cast<ICalibDataSvc*>(this);
00085       sc = StatusCode::SUCCESS;
00086       addRef();
00087     }
00088     else sc = Service::queryInterface( riid, ppvInterface );    
00089   }
00090   return sc;
00091 }
00092 
00093 const DayaBay::PmtCalibData* DbiCalibDataSvc::pmtCalibData(
00094                                        const DayaBay::DetectorSensor& pmtId,
00095                                        const ServiceMode& serviceMode)
00096 {
00097 /*
00098   if(serviceMode.context() != lastContext){  //XiaoSu Chen 2010/7/10
00099     readCalibPmtTable(serviceMode.context());//XiaoSu Chen 2010/6/30
00100     lastContext = serviceMode.context();
00101   }
00102 */
00103   readCalibPmtTable(serviceMode);
00104   std::map<DayaBay::DetectorSensor, DayaBay::PmtCalibData>::iterator result = 
00105     m_pmtDataBySensor.find(pmtId); 
00106   if(result != m_pmtDataBySensor.end()){
00107     return &(result->second);
00108   }
00109   return 0;
00110 }
00111 
00112 const DayaBay::RpcCalibData* DbiCalibDataSvc::rpcCalibData(
00113                                               const DayaBay::RpcSensor& rpcId,
00114                                               const ServiceMode& /*serviceMode*/)
00115 {
00116   std::map<DayaBay::RpcSensor, DayaBay::RpcCalibData>::iterator result = 
00117     m_rpcDataBySensor.find(rpcId); 
00118   if(result != m_rpcDataBySensor.end()){
00119     return &(result->second);
00120   }
00121   return 0;
00122 }
00123 
00124 const DayaBay::FeeCalibData* DbiCalibDataSvc::feeCalibData(
00125                                        const DayaBay::FeeChannelId& channelId,
00126                                        const ServiceMode& serviceMode)
00127 {
00128 /*
00129   if(serviceMode.context() != lastContext){  //XiaoSu Chen 2010/7/10
00130     readCalibFeeTable(serviceMode.context());//XiaoSu Chen 2010/6/30
00131     lastContext = serviceMode.context();
00132   }
00133 */
00134   readCalibFeeTable(serviceMode);
00135   std::map<DayaBay::FeeChannelId, DayaBay::FeeCalibData>::iterator result = 
00136     m_feeDataByChannel.find(channelId); 
00137   if(result != m_feeDataByChannel.end()){
00138     return &(result->second);
00139   }
00140   return 0;
00141 }
00142 
00143 const DayaBay::FecCalibData* DbiCalibDataSvc::fecCalibData(
00144                                        const DayaBay::FecChannelId& channelId,
00145                                        const ServiceMode& /*serviceMode*/)
00146 {
00147   std::map<DayaBay::FecChannelId, DayaBay::FecCalibData>::iterator result = 
00148     m_fecDataByChannel.find(channelId); 
00149   if(result != m_fecDataByChannel.end()){
00150     return &(result->second);
00151   }
00152   return 0;
00153 }
00154 
00155 const std::vector<DayaBay::PmtCalibData>& DbiCalibDataSvc::pmtCalibList(
00156                                           const DayaBay::Detector& detectorId,
00157                                           const ServiceMode& serviceMode)
00158 {
00159   readCalibPmtTable(serviceMode);
00160   return m_pmtData[detectorId];
00161 }
00162 
00163 const std::vector<DayaBay::RpcCalibData>& DbiCalibDataSvc::rpcCalibList(
00164                                           const DayaBay::Detector& detectorId,
00165                                           const ServiceMode& /*serviceMode*/)
00166 {
00167   return m_rpcData[detectorId];
00168 }
00169 
00170 const std::vector<DayaBay::FeeCalibData>& DbiCalibDataSvc::feeCalibList(
00171                                           const DayaBay::Detector& detectorId,
00172                                           const ServiceMode& serviceMode)
00173 {
00174   readCalibFeeTable(serviceMode);
00175   return m_feeData[detectorId];
00176 }
00177 
00178 const std::vector<DayaBay::FecCalibData>& DbiCalibDataSvc::fecCalibList(
00179                                           const DayaBay::Detector& detectorId,
00180                                           const ServiceMode& /*serviceMode*/)
00181 {
00182   return m_fecData[detectorId];
00183 }
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191 
00192 inline int DbiCalibDataSvc::readCalibPmtTable(const ServiceMode& serviceMode){
00193   if(serviceMode.context() == pmtLastContext){  //XiaoSu Chen 2010/10/28
00194     return 2;    
00195   }
00196   pmtLastContext = serviceMode.context();       //XiaoSu Chen 2010/10/28
00197 
00198   DbiResultPtr<GCalibPmtSpec> pr("CalibPmtSpec",pmtLastContext,pmtLastContext.GetDetId());
00199   // Check whether the result is the same as the last one
00200   const DbiResultKey* thisResult= pr.GetKey(); 
00201   if(pmtLastResult == 0){                       //XiaoSu Chen 2010/7/8
00202     pmtLastResult = thisResult;
00203   }else if(thisResult->IsEqualTo(pmtLastResult))
00204   {
00205     return 2;
00206   }else{
00207     pmtLastResult = thisResult;
00208   }
00209 
00210   //DbiTableProxyRegistry::Instance().ShowStatistics();
00211   // Check number of entires in result set
00212   unsigned int numRows = pr.GetNumRows();
00213 
00214   std::cout << "Database rows = " << numRows << std::endl;
00215   const GCalibPmtSpec* row ;
00216 //  int site, detectorID, ring, column;
00217   //DayaBay::Detector lastDetector;
00218   for (unsigned int idx=0; idx < numRows; idx++) {
00219     row = pr.GetRowByIndex(idx);  
00220 //    site = row->GetSite();
00221 //    detectorID = row->GetAD();
00222 //    ring = row->GetRing();
00223 //    column = row->GetColumn();
00224 //    DayaBay::Detector detector((Site::Site_t)site, 
00225 //                         (DetectorId::DetectorId_t)detectorID);
00226 //    DayaBay::AdPmtSensor pmtId(ring, column, (Site::Site_t)site, 
00227 //                             (DetectorId::DetectorId_t)detectorID);
00228     DayaBay::PmtCalibData pmt;
00229     DayaBay::DetectorSensor pmtId(row->GetPmtId());
00230     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00231     pmt.m_pmtId = pmtId;
00232     pmt.m_status = DayaBay::PmtCalibData::Status_t(row->GetStatus());               // rewrited by ChenXiaosu
00233     pmt.m_speHigh = row->GetSpeHigh();
00234     pmt.m_sigmaSpeHigh = row->GetSigmaSpeHigh();
00235     pmt.m_speLow = row->GetSpeLow();
00236     pmt.m_timeOffset = row->GetTimeOffset() * Units::ns;
00237     pmt.m_timeSpread = row->GetTimeSpread() * Units::ns;
00238     pmt.m_efficiency = row->GetEfficiency();
00239     pmt.m_prePulseProb = row->GetPrePulseProb();
00240     pmt.m_afterPulseProb = row->GetAfterPulseProb();
00241     pmt.m_darkRate = row->GetDarkRate() * Units::hertz;
00242     //std::cout << "Adding PMT = " << pmtId.fullPackedData() << std::endl;
00243     //std::vector<DayaBay::PmtCalibData>& pmtList = m_pmtData[detector];
00244     //Add lookup by sensor ID
00245     m_pmtDataBySensor[pmtId] = pmt;
00246   }
00247   for(std::map<DayaBay::Detector, std::vector<DayaBay::PmtCalibData> >::iterator pmtData = m_pmtData.begin(); pmtData != m_pmtData.end(); pmtData++)//Xiaosu Chen 2010/7/8
00248   {
00249     std::vector<DayaBay::PmtCalibData>& pmtList = pmtData->second;
00250     pmtList.clear();
00251   }
00252 
00253   for(std::map<DayaBay::DetectorSensor, DayaBay::PmtCalibData>::iterator pmtDataBySensor = m_pmtDataBySensor.begin(); pmtDataBySensor != m_pmtDataBySensor.end(); pmtDataBySensor++)//Xiaosu Chen 2010/7/8
00254   {
00255     DayaBay::DetectorSensor pmtId = pmtDataBySensor->first;
00256     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00257     std::vector<DayaBay::PmtCalibData>& pmtList = m_pmtData[detector];
00258     pmtList.push_back(pmtDataBySensor->second);
00259   }
00260   return 1;
00261 }
00262 
00263 
00264 inline int DbiCalibDataSvc::readCalibFeeTable(const ServiceMode& serviceMode){
00265   if(serviceMode.context() == feeLastContext){  //XiaoSu Chen 2010/10/28
00266     return 2;    
00267   }
00268   feeLastContext = serviceMode.context();       //XiaoSu Chen 2010/10/28
00269 
00270   DbiResultPtr<GCalibFeeSpec> pr("CalibFeeSpec",feeLastContext,feeLastContext.GetDetId());
00271   const DbiResultKey* thisResult= pr.GetKey(); 
00272   if(feeLastResult == 0){                       //XiaoSu Chen 2010/7/8
00273     feeLastResult = thisResult;
00274   }else if(thisResult->IsEqualTo(feeLastResult))
00275   {
00276     return 2;
00277   }else{
00278     feeLastResult = thisResult;
00279   }
00280 
00281   //DbiTableProxyRegistry::Instance().ShowStatistics();
00282   // Check number of entires in result set
00283   unsigned int numRows = pr.GetNumRows();
00284   std::cout << "Database rows = " << numRows << std::endl;
00285   const GCalibFeeSpec* row;
00286   for (unsigned int idx=0; idx < numRows; idx++) {
00287     row = pr.GetRowByIndex(idx); 
00288     DayaBay::FeeChannelId feeId(row->GetChannelId());
00289     DayaBay::FeeCalibData fee;
00290     fee.m_channelId = row->GetChannelId();  
00291     fee.m_status = DayaBay::FeeCalibData::Status_t(row->GetStatus());         
00292     fee.m_adcThresholdHigh = row->GetAdcThresholdHigh(); 
00293     fee.m_adcThresholdLow = row->GetAdcThresholdLow(); 
00294     fee.m_adcBaselineHigh = row->GetAdcPedestalHigh();  
00295     fee.m_adcBaselineLow = row->GetAdcPedestalLow(); 
00296     m_feeDataByChannel[feeId] = fee;  
00297   }
00298   for(std::map<DayaBay::Detector, std::vector<DayaBay::FeeCalibData> >::iterator feeData = m_feeData.begin(); feeData != m_feeData.end(); feeData++)//Xiaosu Chen 2010/7/8
00299   {
00300     std::vector<DayaBay::FeeCalibData>& feeList = feeData->second;
00301     feeList.clear();
00302   }
00303   for(std::map<DayaBay::FeeChannelId, DayaBay::FeeCalibData>::iterator feeDataByChannel = m_feeDataByChannel.begin(); feeDataByChannel != m_feeDataByChannel.end(); feeDataByChannel++)//Xiaosu Chen 2010/7/8
00304   {
00305     DayaBay::FeeChannelId feeId = feeDataByChannel->first;
00306     DayaBay::Detector detector( feeId.site(), feeId.detectorId() );
00307     std::vector<DayaBay::FeeCalibData>& feeList = m_feeData[detector];
00308     feeList.push_back(feeDataByChannel->second);
00309   }
00310 
00311   return 1;
00312 }
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322 
00323 
00324 
00325 
00326 
00327 
00328 
00329 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:21:48 2011 for DbiDataSvc by doxygen 1.4.7