/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

StaticSimDataSvc.cc
Go to the documentation of this file.
00001 #include "StaticSimDataSvc.h"
00002 #include "GaudiKernel/IMessageSvc.h"
00003 #include "GaudiKernel/SystemOfUnits.h"
00004 #include <sstream>
00005 #include <fstream>
00006 #include <string>
00007 #include <stdlib.h>
00008 
00009 using namespace Gaudi;
00010 
00011 StaticSimDataSvc::StaticSimDataSvc(const std::string& name, ISvcLocator *svc)
00012     : Service(name,svc)
00013 {
00014   std::string path = getenv ("DATASVCROOT");
00015 
00016   declareProperty("PmtDataFile",m_pmtDataFileName = path + "/share/pmtDataTable.txt",
00017                   "Optional filename for loading pmt simulation input data");
00018   declareProperty("RpcDataFile",m_rpcDataFileName="",
00019                   "Optional filename for loading rpc simulation input data");
00020   declareProperty("FeeDataFile",m_feeDataFileName = path + "/share/feeDataTable.txt",
00021                   "Optional filename for loading FEE simulation input data");
00022   declareProperty("FecDataFile",m_fecDataFileName="",
00023                   "Optional filename for loading FEC simulation input data");
00024 }
00025 
00026 StaticSimDataSvc::~StaticSimDataSvc()
00027 {
00028 }
00029 
00030 StatusCode StaticSimDataSvc::initialize()
00031 {
00032   this->Service::initialize();
00033   
00034   IMessageSvc* msg = msgSvc();
00035   if( !msg ){    
00036     return StatusCode::FAILURE;
00037   }
00038 
00039   if(m_pmtDataFileName!=""){
00040     std::ifstream input( m_pmtDataFileName.c_str() );
00041     if( !input.is_open() ){
00042       std::ostringstream msgStr;
00043       msgStr << "Failed to open input file: " << m_pmtDataFileName;
00044       msg->reportMessage("StaticSimDataSvc",MSG::ERROR,msgStr.str());
00045       return StatusCode::FAILURE;
00046     }
00047     else {
00048       std::ostringstream msgStr;
00049       msgStr << "Opened input file: " << m_pmtDataFileName;
00050       msg->reportMessage("StaticSimDataSvc",MSG::INFO,msgStr.str());
00051     }
00052     int sensorId;
00053     std::string description;
00054     double gain, sigmaGain, timeOffset, timeSpread, efficiency;
00055     double prePulseProb, afterPulseProb, darkRate;
00056     std::string line;
00057     while( std::getline(input,line) ){
00058       std::ostringstream msgStr;
00059       msgStr << "Got line: " << line;
00060       msg->reportMessage("StaticSimDataSvc",MSG::VERBOSE,msgStr.str());
00061       msgStr.str("");
00062       std::stringstream streamLine(line);
00063       if( streamLine.peek() == '#' ){
00064         continue;
00065       }
00066       streamLine >> sensorId >> description
00067                  >> gain >> sigmaGain >> timeOffset >> timeSpread 
00068                  >> efficiency >> prePulseProb >> afterPulseProb 
00069                  >> darkRate;
00070       msgStr << "Adding PMT: " << description;
00071       msg->reportMessage("StaticSimDataSvc",MSG::VERBOSE,msgStr.str());
00072     
00073       DayaBay::DetectorSensor pmtId(sensorId); 
00074       DayaBay::Detector detector( pmtId.site(), pmtId.detectorId() );
00075       DayaBay::PmtSimData pmt;
00076       pmt.m_pmtId = pmtId;
00077       pmt.m_gain = gain;
00078       pmt.m_sigmaGain = sigmaGain;
00079       pmt.m_timeOffset = timeOffset * Units::ns;
00080       pmt.m_timeSpread = timeSpread * Units::ns;
00081       pmt.m_efficiency = efficiency;
00082       pmt.m_prePulseProb = prePulseProb;
00083       pmt.m_afterPulseProb = afterPulseProb;
00084       pmt.m_darkRate = darkRate * Units::hertz;
00085       std::vector<DayaBay::PmtSimData>& pmtList = m_pmtData[detector];
00086       pmtList.push_back(pmt);
00087       // Add lookup by sensor ID
00088       m_pmtDataBySensor[pmtId] = pmtList[pmtList.size()-1];
00089     }
00090   }
00091 
00092   if(m_feeDataFileName!=""){
00093     std::ifstream input( m_feeDataFileName.c_str() );
00094     if( !input.is_open() ){
00095       std::ostringstream msgStr;
00096       msgStr << "Failed to open input file: " << m_feeDataFileName;
00097       msg->reportMessage("StaticSimDataSvc",MSG::ERROR,msgStr.str());
00098       return StatusCode::FAILURE;
00099     }
00100     else {
00101       std::ostringstream msgStr;
00102       msgStr << "Opening input file: " << m_feeDataFileName;
00103       msg->reportMessage("StaticSimDataSvc",MSG::INFO,msgStr.str());
00104     }
00105     int channelId;
00106     std::string description;
00107     double channelThreshold, adcRangeHigh, adcRangeLow; 
00108     double adcBaselineHigh, adcBaselineLow;
00109     std::string line;
00110     while( std::getline(input,line) ){
00111       std::ostringstream msgStr;
00112       msgStr << "Got line: " << line;
00113       msg->reportMessage("StaticSimDataSvc",MSG::VERBOSE,msgStr.str());
00114       msgStr.str("");
00115       std::stringstream streamLine(line);
00116       if( streamLine.peek() == '#' ){
00117         continue;
00118       }
00119       streamLine >> channelId >> description
00120                  >> channelThreshold >> adcRangeHigh >> adcRangeLow 
00121                  >> adcBaselineHigh >> adcBaselineLow;
00122 
00123       msgStr << "Adding FEE Channel: " << description;
00124       msg->reportMessage("StaticSimDataSvc",MSG::VERBOSE,msgStr.str());
00125     
00126       DayaBay::FeeChannelId feeChannelId(channelId); 
00127       DayaBay::Detector detector(feeChannelId.site(),feeChannelId.detectorId());
00128       DayaBay::FeeSimData fee;
00129       fee.m_channelId = feeChannelId;
00130       fee.m_channelThreshold = channelThreshold * Units::volt;
00131       fee.m_adcRangeHigh = adcRangeHigh * Units::volt;
00132       fee.m_adcRangeLow = adcRangeLow * Units::volt;
00133       fee.m_adcBaselineHigh = adcBaselineHigh;
00134       fee.m_adcBaselineLow = adcBaselineLow;
00135       std::vector<DayaBay::FeeSimData>& feeList = m_feeData[detector];
00136       feeList.push_back(fee);
00137       // Add lookup by channel ID
00138       m_feeDataByChannel[feeChannelId] = feeList[feeList.size()-1];
00139     }
00140   }
00141 
00142   if(m_rpcDataFileName!=""){
00143     // FIXME: Add RPC data file
00144     std::ostringstream msgStr;
00145     msgStr << "RPC simulation data file not yet implemented!";
00146     msg->reportMessage("StaticSimDataSvc",MSG::ERROR,msgStr.str());
00147     return StatusCode::FAILURE;
00148   }
00149 
00150   if(m_fecDataFileName!=""){
00151     // FIXME: Add FEC data file
00152     std::ostringstream msgStr;
00153     msgStr << "FEC simulation data file not yet implemented!";
00154     msg->reportMessage("StaticSimDataSvc",MSG::ERROR,msgStr.str());
00155     return StatusCode::FAILURE;
00156   }
00157 
00158   return StatusCode::SUCCESS;
00159 }
00160 
00161 StatusCode StaticSimDataSvc::finalize()
00162 {
00163   return this->Service::finalize();
00164 }
00165 
00166 StatusCode StaticSimDataSvc::queryInterface(const InterfaceID& riid, 
00167                                             void** ppvInterface)
00168 {
00169   StatusCode sc = StatusCode::FAILURE;
00170   if (ppvInterface) {
00171     *ppvInterface = 0;
00172     
00173     if (ISimDataSvc::interfaceID().versionMatch(riid)) {
00174       *ppvInterface = static_cast<ISimDataSvc*>(this);
00175       sc = StatusCode::SUCCESS;
00176       addRef();
00177     }
00178     else sc = Service::queryInterface( riid, ppvInterface );    
00179   }
00180   return sc;
00181 }
00182 
00183 const DayaBay::PmtSimData* StaticSimDataSvc::pmtSimData(
00184                                        const DayaBay::DetectorSensor& pmtId,
00185                                        const ServiceMode& /*svcMode*/)
00186 {
00187   std::map<DayaBay::DetectorSensor, DayaBay::PmtSimData>::iterator result = 
00188     m_pmtDataBySensor.find(pmtId); 
00189   if(result != m_pmtDataBySensor.end()){
00190     return &(result->second);
00191   }
00192   return 0;
00193 }
00194 
00195 const DayaBay::RpcSimData* StaticSimDataSvc::rpcSimData(
00196                                               const DayaBay::RpcSensor& rpcId,
00197                                               const ServiceMode& /*svcMode*/)
00198 {
00199   std::map<DayaBay::RpcSensor, DayaBay::RpcSimData>::iterator result = 
00200     m_rpcDataBySensor.find(rpcId); 
00201   if(result != m_rpcDataBySensor.end()){
00202     return &(result->second);
00203   }
00204   return 0;
00205 }
00206 
00207 const DayaBay::FeeSimData* StaticSimDataSvc::feeSimData(
00208                                        const DayaBay::FeeChannelId& channelId,
00209                                        const ServiceMode& /*svcMode*/)
00210 {
00211   std::map<DayaBay::FeeChannelId, DayaBay::FeeSimData>::iterator result = 
00212     m_feeDataByChannel.find(channelId); 
00213   if(result != m_feeDataByChannel.end()){
00214     return &(result->second);
00215   }
00216   // FIXME: Temporarily return a default FEE channel until cabling settles down
00217   DayaBay::FeeChannelId tmpId(1,1,Site::kDayaBay,DetectorId::kAD1);
00218   result = m_feeDataByChannel.find(tmpId); 
00219   if(result != m_feeDataByChannel.end()){
00220     return &(result->second);
00221   }
00222   return 0;
00223 }
00224 
00225 const DayaBay::FecSimData* StaticSimDataSvc::fecSimData(
00226                                        const DayaBay::FecChannelId& channelId,
00227                                        const ServiceMode& /*svcMode*/)
00228 {
00229   std::map<DayaBay::FecChannelId, DayaBay::FecSimData>::iterator result = 
00230     m_fecDataByChannel.find(channelId); 
00231   if(result != m_fecDataByChannel.end()){
00232     return &(result->second);
00233   }
00234   return 0;
00235 }
00236 
00237 const std::vector<DayaBay::PmtSimData>& StaticSimDataSvc::pmtSimList(
00238                                           const DayaBay::Detector& detectorId,
00239                                           const ServiceMode& /*svcMode*/)
00240 {
00241   return m_pmtData[detectorId];
00242 }
00243 
00244 const std::vector<DayaBay::RpcSimData>& StaticSimDataSvc::rpcSimList(
00245                                           const DayaBay::Detector& detectorId,
00246                                           const ServiceMode& /*svcMode*/)
00247 {
00248   return m_rpcData[detectorId];
00249 }
00250 
00251 const std::vector<DayaBay::FeeSimData>& StaticSimDataSvc::feeSimList(
00252                                           const DayaBay::Detector& detectorId,
00253                                           const ServiceMode& /*svcMode*/)
00254 {
00255   return m_feeData[detectorId];
00256 }
00257 
00258 const std::vector<DayaBay::FecSimData>& StaticSimDataSvc::fecSimList(
00259                                           const DayaBay::Detector& detectorId,
00260                                           const ServiceMode& /*svcMode*/)
00261 {
00262   return m_fecData[detectorId];
00263 }
00264 
00265 
00266 // Local Variables: **
00267 // c-basic-offset:2 **
00268 // End: **
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:59:23 for DataSvc by doxygen 1.7.4