/search.css" rel="stylesheet" type="text/css"/> /search.js">
| 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/GCalibPmtPedBias.h"
00008 #include "genDbi/GCalibPmtHighGain.h"
00009 //#include "genDbi/GCalibPmtTiming.h"
00010 //#include "genDbi/GCalibFeeGainConv.h"
00011 #include "genDbi/GCalibFeeSpec.h"
00012 #include "genDbi/GCalibSrcEnergy.h"
00013 
00014 #include "Conventions/Site.h"
00015 #include "Conventions/SimFlag.h"
00016 #include "Conventions/Electronics.h"
00017 #include "Context/TimeStamp.h"
00018 #include "DatabaseInterface/Dbi.h"
00019 #include "DatabaseInterface/DbiResultAgg.h"
00020 #include "DatabaseInterface/DbiCascader.h"
00021 #include "DatabaseInterface/DbiConfigSet.h"
00022 #include "DatabaseInterface/DbiLogEntry.h"
00023 #include "DatabaseInterface/DbiResultKey.h"
00024 #include "DatabaseInterface/DbiResultNonAgg.h"
00025 #include "DatabaseInterface/DbiResultPtr.h"
00026 #include "DatabaseInterface/DbiResultSet.h"
00027 #include "DatabaseInterface/DbiServices.h"
00028 #include "DatabaseInterface/DbiValRecSet.h"
00029 #include "DatabaseInterface/DbiLog.h"
00030 #include "DatabaseInterface/DbiCache.h"
00031 #include "DatabaseInterface/DbiSqlContext.h"
00032 
00033 #include <sstream>
00034 #include <iostream>
00035 #include <list>
00036 #include <map>
00037 #include <memory>
00038 using std::auto_ptr;
00039 using namespace std;
00040 using namespace Gaudi;
00041 
00042 DbiCalibDataSvc::DbiCalibDataSvc(const std::string& name, ISvcLocator *svc)
00043     : Service(name,svc)
00044 {
00045   declareProperty("CableSvcName",m_cableSvcName="CableSvc",
00046                   "Name of service which provides the list of sensors to calibration");
00047 }
00048 
00049 DbiCalibDataSvc::~DbiCalibDataSvc()
00050 {
00051 }
00052 
00053 StatusCode DbiCalibDataSvc::initialize()
00054 {
00055   this->Service::initialize();
00056 /*  IMessageSvc* msg = msgSvc();//cxs 2010-12-7
00057   if( !msg ){    
00058     return StatusCode::FAILURE;
00059   }
00060 */
00061   MsgStream msg(msgSvc(),name());
00062   // Initialize the data with a static table of numbers
00063   ICableSvc* cableSvc = 0;
00064   StatusCode sc = service("CableSvc",cableSvc,true);
00065   if( sc != StatusCode::SUCCESS ){
00066     std::ostringstream msgStr;
00067     msgStr << "Failed to access cable service: " << m_cableSvcName;
00068     //msg->reportMessage("DbiCalibDataSvc",MSG::ERROR,msgStr.str());
00069     return sc;    
00070   }
00071   feeLastResult = 0;   //cxs 2010-10-28
00072   fecLastResult = 0;   //cxs 2010-10-28
00073   pmtLastResult = 0;   //cxs 2010-10-28
00074   pmtPedBiasLastResult = 0; //jpochoa 2011-06-15
00075   pmtHighGainLastResult = 0; //jpochoa 2011-06-15
00076   //pmtTimingLastResult = 0; //jpochoa 2011-06-24
00077   //feeGainConvLastResult = 0;//jpochoa 2011-07-08
00078   
00079   return StatusCode::SUCCESS;
00080 }
00081 
00082 StatusCode DbiCalibDataSvc::finalize()
00083 {
00084   return this->Service::finalize();
00085 }
00086 
00087 StatusCode DbiCalibDataSvc::queryInterface(const InterfaceID& riid, 
00088                                             void** ppvInterface)
00089 {
00090   StatusCode sc = StatusCode::FAILURE;
00091   if (ppvInterface) {
00092     *ppvInterface = 0;
00093     if (ICalibDataSvc::interfaceID().versionMatch(riid)) {
00094       *ppvInterface = static_cast<ICalibDataSvc*>(this);
00095       sc = StatusCode::SUCCESS;
00096       addRef();
00097     }
00098     else sc = Service::queryInterface( riid, ppvInterface );    
00099   }
00100   return sc;
00101 }
00102 
00103 const DayaBay::PmtCalibData* DbiCalibDataSvc::pmtCalibData(
00104                                        const DayaBay::DetectorSensor& pmtId,
00105                                        const ServiceMode& serviceMode)
00106 {
00107 /*
00108   if(serviceMode.context() != lastContext){  //XiaoSu Chen 2010/7/10
00109     readCalibPmtTable(serviceMode.context());//XiaoSu Chen 2010/6/30
00110     lastContext = serviceMode.context();
00111   }
00112 */
00113 
00114   readCalibPmtTable(serviceMode);
00115   std::map<DayaBay::DetectorSensor, DayaBay::PmtCalibData>::iterator result = 
00116     m_pmtDataBySensor.find(pmtId); 
00117   if(result != m_pmtDataBySensor.end()){
00118     return &(result->second);
00119   }
00120   return 0;
00121 }
00122 
00123 const DayaBay::PedBiasCalibData* DbiCalibDataSvc::pedBiasCalibData(
00124                                        const DayaBay::DetectorSensor& pmtId,
00125                                        const ServiceMode& serviceMode)
00126 {  
00127   readCalibPmtPedBiasTable(serviceMode);
00128   std::map<DayaBay::DetectorSensor, DayaBay::PedBiasCalibData>::iterator result = 
00129     m_pedBiasDataBySensor.find(pmtId);  
00130   if(result != m_pedBiasDataBySensor.end()){
00131     return &(result->second);
00132   }
00133   return 0;
00134 }
00135 
00136 const DayaBay::HighGainCalibData* DbiCalibDataSvc::highGainCalibData(
00137                                        const DayaBay::DetectorSensor& pmtId,
00138                                        const ServiceMode& serviceMode)
00139 {  
00140   readCalibPmtHighGainTable(serviceMode);
00141   std::map<DayaBay::DetectorSensor, DayaBay::HighGainCalibData>::iterator result = 
00142     m_highGainDataBySensor.find(pmtId);  
00143   if(result != m_highGainDataBySensor.end()){
00144     return &(result->second);
00145   }
00146   return 0;
00147 }
00148 
00149 /*const DayaBay::TimingCalibData* DbiCalibDataSvc::timingCalibData(
00150                                        const DayaBay::DetectorSensor& pmtId,
00151                                        const ServiceMode& serviceMode)
00152 {  
00153   readCalibPmtTimingTable(serviceMode);
00154   std::map<DayaBay::DetectorSensor, DayaBay::TimingCalibData>::iterator result = 
00155     m_timingDataBySensor.find(pmtId);  
00156   if(result != m_timingDataBySensor.end()){
00157     return &(result->second);
00158   }
00159   return 0;
00160   }*/
00161 
00162  /*const DayaBay::GainConvCalibData* DbiCalibDataSvc::gainConvCalibData(
00163                                        const DayaBay::FeeChannelId& channelId,
00164                                        const ServiceMode& serviceMode)
00165 {  
00166   readCalibFeeGainConvTable(serviceMode);
00167   std::map<DayaBay::FeeChannelId, DayaBay::GainConvCalibData>::iterator result = 
00168     m_gainConvDataByChannel.find(channelId);  
00169   if(result != m_gainConvDataByChannel.end()){
00170     return &(result->second);
00171   }
00172   return 0;
00173   }*/
00174 
00175 const DayaBay::RpcCalibData* DbiCalibDataSvc::rpcCalibData(
00176                                               const DayaBay::RpcSensor& rpcId,
00177                                               const ServiceMode& /*serviceMode*/)
00178 {
00179   std::map<DayaBay::RpcSensor, DayaBay::RpcCalibData>::iterator result = 
00180     m_rpcDataBySensor.find(rpcId); 
00181   if(result != m_rpcDataBySensor.end()){
00182     return &(result->second);
00183   }
00184   return 0;
00185 }
00186 
00187 const DayaBay::FeeCalibData* DbiCalibDataSvc::feeCalibData(
00188                                        const DayaBay::FeeChannelId& channelId,
00189                                        const ServiceMode& serviceMode)
00190 {
00191 /*
00192   if(serviceMode.context() != lastContext){  //XiaoSu Chen 2010/7/10
00193     readCalibFeeTable(serviceMode.context());//XiaoSu Chen 2010/6/30
00194     lastContext = serviceMode.context();
00195   }
00196 */
00197   readCalibFeeTable(serviceMode);
00198   std::map<DayaBay::FeeChannelId, DayaBay::FeeCalibData>::iterator result = 
00199     m_feeDataByChannel.find(channelId); 
00200   if(result != m_feeDataByChannel.end()){
00201     return &(result->second);
00202   }
00203   return 0;
00204 }
00205 
00206 const DayaBay::FecCalibData* DbiCalibDataSvc::fecCalibData(
00207                                        const DayaBay::FecChannelId& channelId,
00208                                        const ServiceMode& /*serviceMode*/)
00209 {
00210   std::map<DayaBay::FecChannelId, DayaBay::FecCalibData>::iterator result = 
00211     m_fecDataByChannel.find(channelId); 
00212   if(result != m_fecDataByChannel.end()){
00213     return &(result->second);
00214   }
00215   return 0;
00216 }
00217 
00218 const DayaBay::SrcEnergyData* DbiCalibDataSvc::srcEnergyData( int type,
00219                                                                 const ServiceMode& svcMode)
00220 {
00221   //error
00222   readCalibSrcEnergyTable(svcMode);
00223   DayaBay::Detector detector(svcMode.context().GetSite(),svcMode.context().GetDetId());
00224   std::vector<DayaBay::SrcEnergyData> energyList = m_srcEnergyData[detector];
00225   std::vector<DayaBay::SrcEnergyData>::iterator be = energyList.begin(), en = energyList.end();
00226   for(;be!=en;be++){
00227         if((*be).m_sourcePeakType==type)
00228                 return &(*be);
00229   }
00230   //Not implemented for StaticCalibDataSvc (jpochoa)
00231   return 0;
00232 
00233 }
00234 
00235 const std::vector<DayaBay::PmtCalibData>& DbiCalibDataSvc::pmtCalibList(
00236                                           const DayaBay::Detector& detectorId,
00237                                           const ServiceMode& serviceMode)
00238 {
00239   readCalibPmtTable(serviceMode);
00240   return m_pmtData[detectorId];
00241 }
00242 
00243 const std::vector<DayaBay::PedBiasCalibData>& DbiCalibDataSvc::pedBiasCalibList(
00244                                           const DayaBay::Detector& detectorId,
00245                                           const ServiceMode& serviceMode)
00246 {
00247   readCalibPmtPedBiasTable(serviceMode);
00248   return m_pedBiasData[detectorId];
00249 }
00250 
00251 const std::vector<DayaBay::HighGainCalibData>& DbiCalibDataSvc::highGainCalibList(
00252                                           const DayaBay::Detector& detectorId,
00253                                           const ServiceMode& serviceMode)
00254 {
00255   readCalibPmtHighGainTable(serviceMode);
00256   return m_highGainData[detectorId];
00257 }
00258 
00259 /*const std::vector<DayaBay::TimingCalibData>& DbiCalibDataSvc::timingCalibList(
00260                                           const DayaBay::Detector& detectorId,
00261                                           const ServiceMode& serviceMode)
00262 {
00263   readCalibPmtTimingTable(serviceMode);
00264   return m_timingData[detectorId];
00265   }*/
00266 
00267  /*const std::vector<DayaBay::GainConvCalibData>& DbiCalibDataSvc::gainConvCalibList(
00268                                           const DayaBay::Detector& detectorId,
00269                                           const ServiceMode& serviceMode)
00270 {
00271   readCalibFeeGainConvTable(serviceMode);
00272   return m_gainConvData[detectorId];
00273 }*/
00274 
00275 const std::vector<DayaBay::RpcCalibData>& DbiCalibDataSvc::rpcCalibList(
00276                                           const DayaBay::Detector& detectorId,
00277                                           const ServiceMode& /*serviceMode*/)
00278 {
00279   return m_rpcData[detectorId];
00280 }
00281 
00282 const std::vector<DayaBay::FeeCalibData>& DbiCalibDataSvc::feeCalibList(
00283                                           const DayaBay::Detector& detectorId,
00284                                           const ServiceMode& serviceMode)
00285 {
00286   readCalibFeeTable(serviceMode);
00287   return m_feeData[detectorId];
00288 }
00289 
00290 const std::vector<DayaBay::FecCalibData>& DbiCalibDataSvc::fecCalibList(
00291                                           const DayaBay::Detector& detectorId,
00292                                           const ServiceMode& /*serviceMode*/)
00293 {
00294   return m_fecData[detectorId];
00295 }
00296 
00297 const std::vector<DayaBay::SrcEnergyData>& DbiCalibDataSvc::srcEnergyList(
00298                                                                           const ServiceMode& serviceMode)
00299 {
00300  // readCalibSrcEnergyTable(serviceMode);
00301   //return m_srcEnergyData;
00302 }
00303 
00304 
00305 inline int DbiCalibDataSvc::readCalibPmtTable(const ServiceMode& serviceMode){
00306   if(serviceMode.context() == pmtLastContext){  //XiaoSu Chen 2010/10/28
00307     return 2;    
00308   }
00309   pmtLastContext = serviceMode.context();       //XiaoSu Chen 2010/10/28
00310 
00311   DbiResultPtr<GCalibPmtSpec> pr("CalibPmtSpec",pmtLastContext,pmtLastContext.GetDetId());
00312   // Check whether the result is the same as the last one
00313   const DbiResultKey* thisResult= pr.GetKey(); 
00314   if(pmtLastResult == 0){                       //XiaoSu Chen 2010/7/8
00315     pmtLastResult = thisResult;
00316   }else if(thisResult->IsEqualTo(pmtLastResult))
00317   {
00318     return 2;
00319   }else{
00320     pmtLastResult = thisResult;
00321   }
00322 
00323   //DbiTableProxyRegistry::Instance().ShowStatistics();
00324   // Check number of entires in result set
00325   unsigned int numRows = pr.GetNumRows();
00326 
00327   std::cout << "Database rows = " << numRows << std::endl;
00328   const GCalibPmtSpec* row ;
00329 //  int site, detectorID, ring, column;
00330   //DayaBay::Detector lastDetector;
00331   for (unsigned int idx=0; idx < numRows; idx++) {
00332     row = pr.GetRowByIndex(idx);  
00333 //    site = row->GetSite();
00334 //    detectorID = row->GetAD();
00335 //    ring = row->GetRing();
00336 //    column = row->GetColumn();
00337 //    DayaBay::Detector detector((Site::Site_t)site, 
00338 //                         (DetectorId::DetectorId_t)detectorID);
00339 //    DayaBay::AdPmtSensor pmtId(ring, column, (Site::Site_t)site, 
00340 //                             (DetectorId::DetectorId_t)detectorID);
00341     DayaBay::PmtCalibData pmt;
00342     DayaBay::DetectorSensor pmtId(row->GetPmtId());
00343     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00344     pmt.m_pmtId = pmtId;
00345     pmt.m_status = DayaBay::PmtCalibData::Status_t(row->GetStatus());               // rewrited by ChenXiaosu
00346     pmt.m_speHigh = row->GetSpeHigh();
00347     pmt.m_sigmaSpeHigh = row->GetSigmaSpeHigh();
00348     pmt.m_speLow = row->GetSpeLow();
00349     pmt.m_timeOffset = row->GetTimeOffset() * Units::ns;
00350     pmt.m_timeSpread = row->GetTimeSpread() * Units::ns;
00351     pmt.m_efficiency = row->GetEfficiency();
00352     pmt.m_prePulseProb = row->GetPrePulseProb();
00353     pmt.m_afterPulseProb = row->GetAfterPulseProb();
00354     pmt.m_darkRate = row->GetDarkRate() * Units::hertz;
00355     //std::cout << "Adding PMT = " << pmtId.fullPackedData() << std::endl;
00356     //std::vector<DayaBay::PmtCalibData>& pmtList = m_pmtData[detector];
00357     //Add lookup by sensor ID
00358     m_pmtDataBySensor[pmtId] = pmt;
00359   }
00360   for(std::map<DayaBay::Detector, std::vector<DayaBay::PmtCalibData> >::iterator pmtData = m_pmtData.begin(); pmtData != m_pmtData.end(); pmtData++)//Xiaosu Chen 2010/7/8
00361   {
00362     std::vector<DayaBay::PmtCalibData>& pmtList = pmtData->second;
00363     pmtList.clear();
00364   }
00365 
00366   for(std::map<DayaBay::DetectorSensor, DayaBay::PmtCalibData>::iterator pmtDataBySensor = m_pmtDataBySensor.begin(); pmtDataBySensor != m_pmtDataBySensor.end(); pmtDataBySensor++)//Xiaosu Chen 2010/7/8
00367   {
00368     DayaBay::DetectorSensor pmtId = pmtDataBySensor->first;
00369     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00370     std::vector<DayaBay::PmtCalibData>& pmtList = m_pmtData[detector];
00371     pmtList.push_back(pmtDataBySensor->second);
00372   }
00373   return 1;
00374 }
00375 
00376 // J. Pedro Ochoa 2011/05/22 
00377 // Inspired from Xiaosu's readCalibPmtTable 
00378 inline int DbiCalibDataSvc::readCalibPmtPedBiasTable(const ServiceMode& serviceMode){
00379  
00380   if(serviceMode.context() == pmtPedBiasLastContext){  
00381     return 2;    
00382   }
00383   pmtPedBiasLastContext = serviceMode.context();       
00384 
00385   DbiResultPtr<GCalibPmtPedBias> pr("CalibPmtPedBias",pmtPedBiasLastContext,pmtPedBiasLastContext.GetDetId());
00386   // Check whether the result is the same as the last one
00387   const DbiResultKey* thisResult= pr.GetKey(); 
00388   if(pmtPedBiasLastResult == 0){                       
00389     pmtPedBiasLastResult = thisResult;
00390   }else if(thisResult->IsEqualTo(pmtPedBiasLastResult))
00391   {
00392     return 2;
00393   }else{
00394     pmtPedBiasLastResult = thisResult;
00395   }
00396 
00397   // Check number of entries in result set
00398   unsigned int numRows = pr.GetNumRows();
00399 
00400   std::cout << "Database rows = " << numRows << std::endl;
00401   const GCalibPmtPedBias* row ;
00402 
00403   for (unsigned int idx=0; idx < numRows; idx++) {
00404     row = pr.GetRowByIndex(idx);  
00405     DayaBay::PedBiasCalibData pedbias;  
00406     DayaBay::DetectorSensor pmtId(row->GetSensorId());
00407     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00408 
00409     pedbias.m_pmtId = pmtId;
00410     pedbias.m_amp.b=row->GetAmp_b();
00411     pedbias.m_amp.m=row->GetAmp_m();
00412     pedbias.m_mean.amp = row->GetMean_amp();
00413     pedbias.m_mean.mean = row->GetMean_mean();
00414     pedbias.m_mean.sigma = row->GetMean_sigma();
00415     pedbias.m_mean.offset = row->GetMean_offset();
00416     pedbias.m_mean.b = row->GetMean_b();
00417     pedbias.m_mean.m = row->GetMean_m();
00418     pedbias.m_sigma.amp = row->GetSigma_amp();
00419     pedbias.m_sigma.mean = row->GetSigma_mean();
00420     pedbias.m_sigma.sigma = row->GetSigma_sigma();
00421     pedbias.m_sigma.offset = row->GetSigma_offset();
00422     pedbias.m_sigma.b = row->GetSigma_b();
00423     pedbias.m_sigma.m = row->GetSigma_m();
00424     pedbias.m_a0.b = row->GetA0_b();
00425     pedbias.m_a0.m = row->GetA0_m();
00426     pedbias.m_a1.b = row->GetA1_b();
00427     pedbias.m_a1.m = row->GetA1_m();
00428     pedbias.m_a2.b = row->GetA2_b();
00429     pedbias.m_a2.m = row->GetA2_m();
00430     pedbias.m_a3.b = row->GetA3_b();
00431     pedbias.m_a3.m = row->GetA3_m();
00432    
00433     m_pedBiasDataBySensor[pmtId] = pedbias;
00434   }
00435   for(std::map<DayaBay::Detector, std::vector<DayaBay::PedBiasCalibData> >::iterator pedBiasData = m_pedBiasData.begin(); pedBiasData != m_pedBiasData.end(); pedBiasData++)
00436   {
00437     std::vector<DayaBay::PedBiasCalibData>& pmtList = pedBiasData->second;
00438     pmtList.clear();
00439   }
00440 
00441   for(std::map<DayaBay::DetectorSensor, DayaBay::PedBiasCalibData>::iterator pedBiasDataBySensor = m_pedBiasDataBySensor.begin(); pedBiasDataBySensor != m_pedBiasDataBySensor.end(); pedBiasDataBySensor++)
00442   {
00443     DayaBay::DetectorSensor pmtId = pedBiasDataBySensor->first;
00444     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00445     std::vector<DayaBay::PedBiasCalibData>& pmtList = m_pedBiasData[detector];
00446     pmtList.push_back(pedBiasDataBySensor->second);
00447   }
00448   return 1;
00449 }
00450 
00451 // J. Pedro Ochoa 2011/06/15 
00452 // Inspired from Xiaosu's readCalibPmtTable 
00453 inline int DbiCalibDataSvc::readCalibPmtHighGainTable(const ServiceMode& serviceMode){
00454  
00455   if(serviceMode.context() == pmtHighGainLastContext){  
00456     return 2;    
00457   }
00458   pmtHighGainLastContext = serviceMode.context();       
00459 
00460   DbiResultPtr<GCalibPmtHighGain> pr("CalibPmtHighGain",pmtHighGainLastContext,pmtHighGainLastContext.GetDetId());
00461   // Check whether the result is the same as the last one
00462   const DbiResultKey* thisResult= pr.GetKey(); 
00463   if(pmtHighGainLastResult == 0){                       
00464     pmtHighGainLastResult = thisResult;
00465   }else if(thisResult->IsEqualTo(pmtHighGainLastResult))
00466   {
00467     return 2;
00468   }else{
00469     pmtHighGainLastResult = thisResult;
00470   }
00471 
00472   // Check number of entries in result set
00473   unsigned int numRows = pr.GetNumRows();
00474 
00475   std::cout << "Database rows = " << numRows << std::endl;
00476   const GCalibPmtHighGain* row ;
00477 
00478   for (unsigned int idx=0; idx < numRows; idx++) {
00479     row = pr.GetRowByIndex(idx);  
00480     DayaBay::HighGainCalibData highgain;  
00481     DayaBay::DetectorSensor pmtId(row->GetSensorId());
00482     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00483 
00484     highgain.m_pmtId = pmtId;
00485     highgain.m_speHigh = row->GetSpeHigh();
00486     highgain.m_speHighError = row->GetSpeHighError();
00487     highgain.m_sigmaSpeHigh = row->GetSigmaSpeHigh();
00488     highgain.m_speHighFitQual = row->GetSpeHighFitQual();
00489    
00490     m_highGainDataBySensor[pmtId] = highgain;
00491   }
00492   for(std::map<DayaBay::Detector, std::vector<DayaBay::HighGainCalibData> >::iterator highGainData = m_highGainData.begin(); highGainData != m_highGainData.end(); highGainData++)
00493   {
00494     std::vector<DayaBay::HighGainCalibData>& pmtList = highGainData->second;
00495     pmtList.clear();
00496   }
00497 
00498   for(std::map<DayaBay::DetectorSensor, DayaBay::HighGainCalibData>::iterator highGainDataBySensor = m_highGainDataBySensor.begin(); highGainDataBySensor != m_highGainDataBySensor.end(); highGainDataBySensor++)
00499   {
00500     DayaBay::DetectorSensor pmtId = highGainDataBySensor->first;
00501     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00502     std::vector<DayaBay::HighGainCalibData>& pmtList = m_highGainData[detector];
00503     pmtList.push_back(highGainDataBySensor->second);
00504   }
00505   return 1;
00506 }
00507 
00508 // J. Pedro Ochoa 2011/06/24 
00509 // Inspired from Xiaosu's readCalibPmtTable 
00510 /*inline int DbiCalibDataSvc::readCalibPmtTimingTable(const ServiceMode& serviceMode){
00511  
00512   if(serviceMode.context() == pmtTimingLastContext){  
00513     return 2;    
00514   }
00515   pmtTimingLastContext = serviceMode.context();       
00516 
00517   DbiResultPtr<GCalibPmtTiming> pr("CalibPmtTiming",pmtTimingLastContext,pmtTimingLastContext.GetDetId());
00518   // Check whether the result is the same as the last one
00519   const DbiResultKey* thisResult= pr.GetKey(); 
00520   if(pmtTimingLastResult == 0){                       
00521     pmtTimingLastResult = thisResult;
00522   }else if(thisResult->IsEqualTo(pmtTimingLastResult))
00523   {
00524     return 2;
00525   }else{
00526     pmtTimingLastResult = thisResult;
00527   }
00528 
00529   // Check number of entries in result set
00530   unsigned int numRows = pr.GetNumRows();
00531 
00532   std::cout << "Database rows = " << numRows << std::endl;
00533   const GCalibPmtTiming* row ;
00534 
00535   for (unsigned int idx=0; idx < numRows; idx++) {
00536     row = pr.GetRowByIndex(idx);  
00537     DayaBay::TimingCalibData timepars;  
00538     DayaBay::DetectorSensor chanId(row->GetChannelId());
00539     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00540 
00541     timepars.m_channelId = chanId;
00542     timepars.m_par0 = row->GetPar0();
00543     timepars.m_par1 = row->GetPar1();
00544     timepars.m_par2 = row->GetPar2();
00545     timepars.m_par3 = row->GetPar3();
00546    
00547     m_timingDataBySensor[pmtId] = timepars;
00548   }
00549   for(std::map<DayaBay::Detector, std::vector<DayaBay::TimingCalibData> >::iterator timingData = m_timingData.begin(); timingData != m_timingData.end(); timingData++)
00550   {
00551     std::vector<DayaBay::TimingCalibData>& pmtList = timingData->second;
00552     pmtList.clear();
00553   }
00554 
00555   for(std::map<DayaBay::DetectorSensor, DayaBay::TimingCalibData>::iterator timingDataBySensor = m_timingDataBySensor.begin(); timingDataBySensor != m_timingDataBySensor.end(); timingDataBySensor++)
00556   {
00557     DayaBay::DetectorSensor pmtId = timingDataBySensor->first;
00558     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00559     std::vector<DayaBay::TimingCalibData>& pmtList = m_timingData[detector];
00560     pmtList.push_back(timingDataBySensor->second);
00561   }
00562   return 1;
00563   }*/
00564 
00565 /*
00566 // J. Pedro Ochoa 2011/06/24 
00567 // Inspired from Xiaosu's readCalibPmtTable 
00568 inline int DbiCalibDataSvc::readCalibFeeGainConvTable(const ServiceMode& serviceMode){
00569  
00570   if(serviceMode.context() == feeGainConvLastContext){  
00571     return 2;    
00572   }
00573   feeGainConvLastContext = serviceMode.context();       
00574 
00575   DbiResultPtr<GCalibFeeGainConv> pr("CalibFeeGainConv",feeGainConvLastContext,feeGainConvLastContext.GetDetId());
00576   // Check whether the result is the same as the last one
00577   const DbiResultKey* thisResult= pr.GetKey(); 
00578   if(feeGainConvLastResult == 0){                       
00579     feeGainConvLastResult = thisResult;
00580   }else if(thisResult->IsEqualTo(feeGainConvLastResult))
00581   {
00582     return 2;
00583   }else{
00584     feeGainConvLastResult = thisResult;
00585   }
00586 
00587   // Check number of entries in result set
00588   unsigned int numRows = pr.GetNumRows();
00589 
00590   std::cout << "Database rows = " << numRows << std::endl;
00591   const GCalibFeeGainConv* row ;
00592 
00593   for (unsigned int idx=0; idx < numRows; idx++) {
00594     row = pr.GetRowByIndex(idx);  
00595     DayaBay::GainConvCalibData gcpars;  
00596     DayaBay::FeeChannelId channelId(row->GetChannelId());
00597     DayaBay::Detector detector( channelId.site(), channelId.detectorId() );
00598 
00599     gcpars.m_channelId = channelId;
00600     gcpars.m_gainConv = row->GetGainConv();
00601     gcpars.m_gainConvError = row->GetGainConvError();
00602     gcpars.m_frline.slope = row->GetFRLineSlope();
00603     gcpars.m_frline.offset = row->GetFRLineOffset();
00604     gcpars.m_frline.uncert = row->GetFRLineUncert();
00605     gcpars.m_crline.slope = row->GetCRLineSlope();
00606     gcpars.m_crline.offset = row->GetCRLineOffset();
00607     gcpars.m_crline.uncert = row->GetCRLineUncert();
00608    
00609     m_gainConvDataByChannel[channelId] = gcpars;
00610   }
00611   for(std::map<DayaBay::Detector, std::vector<DayaBay::GainConvCalibData> >::iterator gainConvData = m_gainConvData.begin(); gainConvData != m_gainConvData.end(); gainConvData++)
00612   {
00613     std::vector<DayaBay::GainConvCalibData>& feeList = gainConvData->second;
00614     feeList.clear();
00615   }
00616 
00617   for(std::map<DayaBay::FeeChannelId, DayaBay::GainConvCalibData>::iterator gainConvDataByChannel = m_gainConvDataByChannel.begin(); gainConvDataByChannel != m_gainConvDataByChannel.end(); gainConvDataByChannel++)
00618   {
00619     DayaBay::FeeChannelId channelId = gainConvDataByChannel->first;
00620     DayaBay::Detector detector( channelId.site(), channelId.detectorId() );
00621     std::vector<DayaBay::GainConvCalibData>& feeList = m_gainConvData[detector];
00622     feeList.push_back(gainConvDataByChannel->second);
00623   }
00624   return 1;
00625 }
00626 */
00627 
00628 inline int DbiCalibDataSvc::readCalibFeeTable(const ServiceMode& serviceMode){
00629   if(serviceMode.context() == feeLastContext){  //XiaoSu Chen 2010/10/28
00630     return 2;    
00631   }
00632   feeLastContext = serviceMode.context();       //XiaoSu Chen 2010/10/28
00633 
00634   DbiResultPtr<GCalibFeeSpec> pr("CalibFeeSpec",feeLastContext,feeLastContext.GetDetId());
00635   const DbiResultKey* thisResult= pr.GetKey(); 
00636   if(feeLastResult == 0){                       //XiaoSu Chen 2010/7/8
00637     feeLastResult = thisResult;
00638   }else if(thisResult->IsEqualTo(feeLastResult))
00639   {
00640     return 2;
00641   }else{
00642     feeLastResult = thisResult;
00643   }
00644 
00645   //DbiTableProxyRegistry::Instance().ShowStatistics();
00646   // Check number of entires in result set
00647   unsigned int numRows = pr.GetNumRows();
00648   std::cout << "Database rows = " << numRows << std::endl;
00649   const GCalibFeeSpec* row;
00650   for (unsigned int idx=0; idx < numRows; idx++) {
00651     row = pr.GetRowByIndex(idx); 
00652     DayaBay::FeeChannelId feeId(row->GetChannelId());
00653     DayaBay::FeeCalibData fee;
00654     fee.m_channelId = row->GetChannelId();  
00655     fee.m_status = DayaBay::FeeCalibData::Status_t(row->GetStatus());         
00656     fee.m_adcThresholdHigh = row->GetAdcThresholdHigh(); 
00657     fee.m_adcThresholdLow = row->GetAdcThresholdLow(); 
00658     fee.m_adcBaselineHigh = row->GetAdcPedestalHigh();  
00659     fee.m_adcBaselineLow = row->GetAdcPedestalLow(); 
00660     m_feeDataByChannel[feeId] = fee;  
00661   }
00662   for(std::map<DayaBay::Detector, std::vector<DayaBay::FeeCalibData> >::iterator feeData = m_feeData.begin(); feeData != m_feeData.end(); feeData++)//Xiaosu Chen 2010/7/8
00663   {
00664     std::vector<DayaBay::FeeCalibData>& feeList = feeData->second;
00665     feeList.clear();
00666   }
00667   for(std::map<DayaBay::FeeChannelId, DayaBay::FeeCalibData>::iterator feeDataByChannel = m_feeDataByChannel.begin(); feeDataByChannel != m_feeDataByChannel.end(); feeDataByChannel++)//Xiaosu Chen 2010/7/8
00668   {
00669     DayaBay::FeeChannelId feeId = feeDataByChannel->first;
00670     DayaBay::Detector detector( feeId.site(), feeId.detectorId() );
00671     std::vector<DayaBay::FeeCalibData>& feeList = m_feeData[detector];
00672     feeList.push_back(feeDataByChannel->second);
00673   }
00674 
00675   return 1;
00676 }
00677 
00678 
00679 // B. Littlejohn 2011/07/25
00680 // Extension/Simplification of Above for Calibration Peak Database Readout
00681 inline int DbiCalibDataSvc::readCalibSrcEnergyTable(const ServiceMode& serviceMode){
00682 
00683   if(serviceMode.context() == srcEnergyLastContext){
00684     return 2;
00685   }
00686   srcEnergyLastContext = serviceMode.context();
00687 
00688   DbiResultPtr<GCalibSrcEnergy> pr("CalibSrcEnergy",srcEnergyLastContext,srcEnergyLastContext.GetDetId());
00689   // Check whether the result is the same as the last one
00690   const DbiResultKey* thisResult= pr.GetKey();
00691   if(srcEnergyLastResult == 0){
00692     srcEnergyLastResult = thisResult;
00693   }else if(thisResult->IsEqualTo(srcEnergyLastResult))
00694     {
00695       return 2;
00696     }else{
00697       srcEnergyLastResult = thisResult;
00698     }
00699 
00700   // Check number of entries in result set
00701   unsigned int numRows = pr.GetNumRows();
00702 
00703   std::cout << "Database rows = " << numRows << std::endl;
00704   const GCalibSrcEnergy* row ;
00705   for(std::map<DayaBay::Detector, std::vector<DayaBay::SrcEnergyData> >::iterator energyData = m_srcEnergyData.begin(); energyData != m_srcEnergyData.end(); energyData++)//Xiaosu Chen 2010/7/8
00706   {
00707     std::vector<DayaBay::SrcEnergyData>& energyList = energyData->second;
00708     energyList.clear();
00709   }
00710 
00711   for (unsigned int idx=0; idx < numRows; idx++) {
00712     row = pr.GetRowByIndex(idx);
00713     DayaBay::SrcEnergyData srcenergy;
00714 
00715     srcenergy.m_sourcePeakType = row->GetSourcePeakType();
00716     srcenergy.m_xSrcPosition = row->GetXSrcPosition();
00717     srcenergy.m_ySrcPosition = row->GetYSrcPosition();
00718     srcenergy.m_zSrcPosition = row->GetZSrcPosition();
00719     srcenergy.m_pePeak = row->GetPEPeak();
00720     srcenergy.m_pePeakUnc = row->GetPEPeakUnc();
00721     srcenergy.m_pePeakFitQuality = row->GetPEPeakFitQuality();
00722     DayaBay::Detector detector(serviceMode.context().GetSite(),serviceMode.context().GetDetId());
00723     std::vector<DayaBay::SrcEnergyData>& energyList = m_srcEnergyData[detector];
00724     energyList.push_back(srcenergy);
00725    // m_srcEnergyData.push_back(srcenergy);
00726   }
00727   
00728   return 1;
00729 }
00730 
00731 
00732 
00733 
00734 
00735 
00736 
00737 
00738 
00739 
00740 
00741 
00742 
00743 
00744 
00745 
00746 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:59:43 for DbiDataSvc by doxygen 1.7.4