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

In This Package:

DbiSimDataSvc.cc

Go to the documentation of this file.
00001 #include "DbiSimDataSvc.h"
00002 #include "DataSvc/ICableSvc.h"
00003 #include "GaudiKernel/IMessageSvc.h"
00004 #include "GaudiKernel/SystemOfUnits.h"
00005 
00006 #include "genDbi/GSimPmtSpec.h"
00007 
00008 #include "Conventions/Site.h"
00009 #include "Conventions/SimFlag.h"
00010 #include "Context/TimeStamp.h"
00011 #include "DatabaseInterface/Dbi.h"
00012 #include "DatabaseInterface/DbiResultAgg.h"
00013 #include "DatabaseInterface/DbiCascader.h"
00014 #include "DatabaseInterface/DbiConfigSet.h"
00015 #include "DatabaseInterface/DbiLogEntry.h"
00016 #include "DatabaseInterface/DbiResultKey.h"
00017 #include "DatabaseInterface/DbiResultNonAgg.h"
00018 #include "DatabaseInterface/DbiResultPtr.h"
00019 #include "DatabaseInterface/DbiResultSet.h"
00020 #include "DatabaseInterface/DbiServices.h"
00021 #include "DatabaseInterface/DbiValRecSet.h"
00022 #include "DatabaseInterface/DbiLog.h"
00023 #include "DatabaseInterface/DbiCache.h"
00024 
00025 #include <sstream>
00026 
00027 #include <list>
00028 #include <map>
00029 #include <memory>
00030 using std::auto_ptr;
00031 
00032 using namespace Gaudi;
00033 
00034 DbiSimDataSvc::DbiSimDataSvc(const std::string& name, ISvcLocator *svc)
00035     : Service(name,svc)
00036 {
00037   declareProperty("CableSvcName",m_cableSvcName="DbiCableSvc",
00038                   "Name of service which provides the list of sensors to simulate");
00039 }
00040 
00041 DbiSimDataSvc::~DbiSimDataSvc()
00042 {
00043 }
00044 
00045 StatusCode DbiSimDataSvc::initialize()
00046 {
00047   this->Service::initialize();
00048   
00049 /*  IMessageSvc* msg = msgSvc();//cxs 2010-12-7
00050   if( !msg ){    
00051     return StatusCode::FAILURE;
00052   }
00053 */
00054    MsgStream msg(msgSvc(),name());
00055   // Initialize the data with a static table of numbers
00056   ICableSvc* cableSvc = 0;
00057   StatusCode sc = service("StaticCableSvc",cableSvc,true);
00058 
00059   if( sc != StatusCode::SUCCESS ){
00060     std::ostringstream msgStr;
00061     msgStr << "Failed to access cable service: " << m_cableSvcName;
00062     //msg->reportMessage("DbiSimDataSvc",MSG::ERROR,msgStr.str());
00063     return sc;    
00064   }
00065 
00066   // Use a dummy service mode for initialization
00067 /*  Context context;
00068   context.SetSite(Site::kAll);
00069   context.SetDetId(DetectorId::kAll);
00070   ServiceMode svcMode(context,0);
00071   const std::vector<DayaBay::DetectorSensor> sensors = 
00072     cableSvc->sensors(svcMode);
00073 */
00074   // =======================================================
00075   // FIXME: since there's only one context range, hard coding context for now
00076   // =======================================================
00077   //TimeStamp tstamp(2007, 1, 15, 0, 0, 1);
00078   //Context vc(Site::kDayaBay, SimFlag::kMC, tstamp);
00079   Context vc(Site::kAll, SimFlag::kMC);
00080   DbiResultPtr<GSimPmtSpec> pr("SimPmtSpec",vc);
00081   //pr.NewQuery(vc);
00082 
00083   // Delete any residual objects and check for leaks.
00084 
00085   DbiTableProxyRegistry::Instance().ShowStatistics();
00086   
00087 
00088   // Check number of entires in result set
00089   unsigned int numRows = pr.GetNumRows();
00090   std::cout << "CJSLIN: Database rows = " << numRows << std::endl;
00091   const GSimPmtSpec* row ;
00092 //  int site, detectorID, ring, column;
00093   
00094   for (unsigned int idx=0; idx < numRows; idx++) {
00095 
00096     row = pr.GetRowByIndex(idx);  
00097 //    site = row->GetSite();
00098 //    detectorID = row->GetAD();
00099 //    ring = row->GetRing();
00100 //    column = row->GetColumn();
00101 
00102 //    DayaBay::Detector detector((Site::Site_t)site, 
00103 //                         (DetectorId::DetectorId_t)detectorID);
00104 //    DayaBay::AdPmtSensor pmtId(ring, column, (Site::Site_t)site, 
00105 //                             (DetectorId::DetectorId_t)detectorID);
00106     DayaBay::PmtSimData pmt;
00107     DayaBay::DetectorSensor pmtId(row->GetPmtId());
00108     DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00109 //    pmt.m_pmtId = pmtId.fullPackedData();
00110     pmt.m_pmtId = pmtId;
00111     pmt.m_gain = row->GetGain();
00112     pmt.m_sigmaGain = row->GetSigmaGain();
00113     pmt.m_timeOffset = row->GetTimeOffset() * Units::ns;
00114     pmt.m_timeSpread = row->GetTimeSpread() * Units::ns;
00115     pmt.m_efficiency = row->GetEfficiency();
00116     pmt.m_prePulseProb = row->GetPrePulseProb();
00117     pmt.m_afterPulseProb = row->GetAfterPulseProb();
00118     pmt.m_darkRate = row->GetDarkRate() * Units::hertz;
00119     std::vector<DayaBay::PmtSimData>& pmtList = m_pmtData[detector];
00120     pmtList.push_back(pmt);
00121     // Add lookup by sensor ID
00122     m_pmtDataBySensor[pmtId] = pmtList[pmtList.size()-1];
00123 
00124   }
00125 
00126   //FIXME: leaving out RPC stuff for now
00127 
00128 
00129   return StatusCode::SUCCESS;
00130 }
00131 
00132 StatusCode DbiSimDataSvc::finalize()
00133 {
00134   return this->Service::finalize();
00135 }
00136 
00137 StatusCode DbiSimDataSvc::queryInterface(const InterfaceID& riid, 
00138                                             void** ppvInterface)
00139 {
00140   StatusCode sc = StatusCode::FAILURE;
00141   if (ppvInterface) {
00142     *ppvInterface = 0;
00143     
00144     if (ISimDataSvc::interfaceID().versionMatch(riid)) {
00145       *ppvInterface = static_cast<ISimDataSvc*>(this);
00146       sc = StatusCode::SUCCESS;
00147       addRef();
00148     }
00149     else sc = Service::queryInterface( riid, ppvInterface );    
00150   }
00151   return sc;
00152 }
00153 
00154 const DayaBay::PmtSimData* DbiSimDataSvc::pmtSimData(
00155                                        const DayaBay::DetectorSensor& pmtId,
00156                                        const ServiceMode& /*svcMode*/)
00157 {
00158   std::map<DayaBay::DetectorSensor, DayaBay::PmtSimData>::iterator result = 
00159     m_pmtDataBySensor.find(pmtId); 
00160   if(result != m_pmtDataBySensor.end()){
00161     return &(result->second);
00162   }
00163   return 0;
00164 }
00165 
00166 const DayaBay::RpcSimData* DbiSimDataSvc::rpcSimData(
00167                                               const DayaBay::RpcSensor& rpcId,
00168                                               const ServiceMode& /*svcMode*/)
00169 {
00170   std::map<DayaBay::RpcSensor, DayaBay::RpcSimData>::iterator result = 
00171     m_rpcDataBySensor.find(rpcId); 
00172   if(result != m_rpcDataBySensor.end()){
00173     return &(result->second);
00174   }
00175   return 0;
00176 }
00177 
00178 
00179 const DayaBay::FeeSimData* DbiSimDataSvc::feeSimData(
00180                                        const DayaBay::FeeChannelId& channelId,
00181                                        const ServiceMode& /*svcMode*/)
00182 {
00183   std::map<DayaBay::FeeChannelId, DayaBay::FeeSimData>::iterator result = 
00184     m_feeDataByChannel.find(channelId); 
00185   if(result != m_feeDataByChannel.end()){
00186     return &(result->second);
00187   }
00188   return 0;
00189 }
00190 
00191 const DayaBay::FecSimData* DbiSimDataSvc::fecSimData(
00192                                        const DayaBay::FecChannelId& channelId,
00193                                        const ServiceMode& /*svcMode*/)
00194 {
00195   std::map<DayaBay::FecChannelId, DayaBay::FecSimData>::iterator result = 
00196     m_fecDataByChannel.find(channelId); 
00197   if(result != m_fecDataByChannel.end()){
00198     return &(result->second);
00199   }
00200   return 0;
00201 }
00202 
00203 
00204 const std::vector<DayaBay::PmtSimData>& DbiSimDataSvc::pmtSimList(
00205                                           const DayaBay::Detector& detectorId,
00206                                           const ServiceMode& /*svcMode*/)
00207 {
00208   return m_pmtData[detectorId];
00209 }
00210 
00211 const std::vector<DayaBay::RpcSimData>& DbiSimDataSvc::rpcSimList(
00212                                           const DayaBay::Detector& detectorId,
00213                                           const ServiceMode& /*svcMode*/)
00214 {
00215   return m_rpcData[detectorId];
00216 }
00217 
00218 
00219 const std::vector<DayaBay::FeeSimData>& DbiSimDataSvc::feeSimList(
00220                                           const DayaBay::Detector& detectorId,
00221                                           const ServiceMode& /*svcMode*/)
00222 {
00223   return m_feeData[detectorId];
00224 }
00225 
00226 const std::vector<DayaBay::FecSimData>& DbiSimDataSvc::fecSimList(
00227                                           const DayaBay::Detector& detectorId,
00228                                           const ServiceMode& /*svcMode*/)
00229 {
00230   return m_fecData[detectorId];
00231 }
| 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