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

Generated on Mon Apr 11 20:21:04 2011 for DataSvc by doxygen 1.4.7