00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "GaudiKernel/StatusCode.h"
00014 #include "GaudiKernel/SvcFactory.h"
00015 #include "GaudiKernel/MsgStream.h"
00016 #include "GaudiKernel/IIncidentSvc.h"
00017 #include "GaudiKernel/Incident.h"
00018 #include "GaudiKernel/IIncidentListener.h"
00019 #include "GaudiKernel/IDataProviderSvc.h"
00020 #include "GaudiKernel/DataSvc.h"
00021 #include "GaudiKernel/SmartDataPtr.h"
00022 #include "GaudiKernel/Service.h"
00023 #include "CalibData/Tof/TofSimData.h"
00024 #include "TofSimSvc/TofSimSvc.h"
00025
00026 using namespace std;
00027
00028 TofSimSvc::TofSimSvc( const std::string& name, ISvcLocator* svcloc ) : Service(name, svcloc) {
00029 declareProperty("Run",m_run=1);
00030 }
00031
00032 StatusCode TofSimSvc::queryInterface (const InterfaceID& riid, void** ppvInterface ){
00033
00034 if ( IID_ITofSimSvc.versionMatch(riid) ) {
00035 *ppvInterface = static_cast<ITofSimSvc*> (this);
00036 } else {
00037 return Service::queryInterface(riid, ppvInterface) ;
00038 }
00039 return StatusCode::SUCCESS;
00040 }
00041
00042 StatusCode TofSimSvc::initialize ( ) {
00043 m_hasbeeninitialized=false;
00044
00045 MsgStream log(msgSvc(), name());
00046 log << MSG::INFO << name() << ": Start of run initialisation" << endreq;
00047
00048 StatusCode sc = Service::initialize();
00049 if ( sc.isFailure() ) return sc;
00050
00051 IIncidentSvc* incsvc;
00052 sc = service("IncidentSvc", incsvc);
00053 int priority = 100;
00054 if( sc.isSuccess() ){
00055 incsvc -> addListener(this, "NewRun", priority);
00056 }
00057
00058 StatusCode scc;
00059
00060 log<<MSG::INFO << "setProperties()" << endreq;
00061 scc = service("CalibDataSvc", m_pSimDataSvc, true);
00062 if ( !scc.isSuccess() ) {
00063 log<<MSG::ERROR<<"Could not get IDataProviderSvc interface of SimXmlCnvSvc"<<endreq;
00064 return scc;
00065 } else {
00066 log << MSG::DEBUG<< "Retrieved IDataProviderSvc interface of SimXmlCnvSvc"<<endreq;
00067 }
00068
00069 scc = setProperties();
00070
00071 return sc;
00072 }
00073
00074 StatusCode TofSimSvc::finalize ( ) {
00075 MsgStream log(msgSvc(), name());
00076 log << MSG::INFO << name() << ": End of Run" << endreq;
00077 return StatusCode::SUCCESS;
00078 }
00079
00080 TofSimSvc::~TofSimSvc(){
00081 MsgStream log(msgSvc(), name());
00082 log << MSG::INFO << name() << ": Destructor function of TofSimSvc" << endreq;
00083
00084 for(vector<TofConst*>::iterator it1 = fTofConst.begin(); it1 != fTofConst.end(); it1++) { delete (*it1); }
00085 fTofConst.clear();
00086 for(vector<BTofSim*>::iterator it2 = fBTofSim.begin(); it2 != fBTofSim.end(); it2++) { delete (*it2); }
00087 fBTofSim.clear();
00088 for(vector<ETofSim*>::iterator it3 = fETofSim.begin(); it3 != fETofSim.end(); it3++) { delete (*it3); }
00089 fETofSim.clear();
00090
00091 return;
00092 }
00093
00094 StatusCode TofSimSvc::FillfromDatabase(){
00095
00096 MsgStream log(msgSvc(), name());
00097 std::string fullPath = "/Calib/TofSim";
00098 log << MSG::INFO<<" Tof simulation fullPath = "<<fullPath<< endreq;
00099 SmartDataPtr<CalibData::TofSimData> test(m_pSimDataSvc, fullPath);
00100 if(!test){
00101 log << MSG::FATAL << "TofSimSvc could not find TofSimData in TDS!!" << endreq;
00102 return StatusCode::FAILURE;
00103 }
00104
00105 for(vector<TofConst*>::iterator it1 = fTofConst.begin(); it1 != fTofConst.end(); it1++) { delete (*it1); }
00106 fTofConst.clear();
00107 for(vector<BTofSim*>::iterator it2 = fBTofSim.begin(); it2 != fBTofSim.end(); it2++) { delete (*it2); }
00108 fBTofSim.clear();
00109 for(vector<ETofSim*>::iterator it3 = fETofSim.begin(); it3 != fETofSim.end(); it3++) { delete (*it3); }
00110 fETofSim.clear();
00111
00112 TofConst* tofConst = new TofConst;
00113 tofConst->setBarLowThres( test->getBarLowThres() );
00114 tofConst->setBarHighThres( test->getBarHighThres() );
00115 tofConst->setEndLowThres( test->getEndLowThres() );
00116 tofConst->setEndHighThres( test->getEndHighThres() );
00117 tofConst->setBarPMTGain( test->getBarPMTGain() );
00118 tofConst->setEndPMTGain( test->getEndPMTGain() );
00119 tofConst->setBarConstant( test->getBarConstant() );
00120 tofConst->setEndConstant( test->getEndConstant() );
00121 tofConst->setEndNoiseSwitch( test->getEndNoiseSwitch() );
00122 fTofConst.push_back(tofConst);
00123
00124 for( unsigned int id=0; id<176; id++ ) {
00125
00126 BTofSim* btof = new BTofSim;
00127 btof->setGain( test->getBarGain(id) );
00128 btof->setRatio( test->getBarRatio(id) );
00129 btof->setAttenLength( test->getBarAttenLength(id) );
00130 fBTofSim.push_back(btof);
00131 }
00132
00133 for( unsigned int id=0; id<96; id++ ) {
00134 ETofSim* etof = new ETofSim;
00135 etof->setGain( test->getEndGain(id) );
00136 etof->setAttenLength( test->getEndAttenLength(id) );
00137 etof->setNoiseSmear( test->getEndNoiseSmear(id) );
00138 fETofSim.push_back(etof);
00139 }
00140
00141 return StatusCode::SUCCESS;
00142 }
00143
00144 void TofSimSvc::Dump(){
00145 std::cout<<"Now We can get the TOF Simulation Service"<<std::endl;
00146 return;
00147 }
00148
00149 void TofSimSvc::handle(const Incident& inc){
00150 MsgStream log( messageService(), name() );
00151 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
00152
00153 if ( inc.type() == "NewRun" ){
00154 log << MSG::DEBUG << "New Run" << endreq;
00155 StatusCode sc= FillfromDatabase();
00156 if(sc.isSuccess()){
00157 m_hasbeeninitialized=true;
00158 }
00159 }
00160 return;
00161 }
00162
00163 const double TofSimSvc::BarLowThres() {
00164 return fTofConst[0]->getBarLowThres();
00165 }
00166
00167 const double TofSimSvc::BarHighThres() {
00168 return fTofConst[0]->getBarHighThres();
00169 }
00170
00171 const double TofSimSvc::EndLowThres() {
00172 return fTofConst[0]->getEndLowThres();
00173 }
00174
00175 const double TofSimSvc::EndHighThres() {
00176 return fTofConst[0]->getEndHighThres();
00177 }
00178
00179 const double TofSimSvc::BarPMTGain() {
00180 return fTofConst[0]->getBarPMTGain();
00181 }
00182
00183 const double TofSimSvc::EndPMTGain() {
00184 return fTofConst[0]->getEndPMTGain();
00185 }
00186
00187 const double TofSimSvc::BarConstant() {
00188 return fTofConst[0]->getBarConstant();
00189 }
00190
00191 const double TofSimSvc::EndConstant() {
00192 return fTofConst[0]->getEndConstant();
00193 }
00194
00195 const double TofSimSvc::EndNoiseSwitch() {
00196 return fTofConst[0]->getEndNoiseSwitch();
00197 }
00198
00199 const double TofSimSvc::BarGain1(unsigned int id) {
00200 if( id < 176 ) {
00201 return fBTofSim[id]->getGain1();
00202 }
00203 else {
00204 std::cout<<"TofSimSvc::BarGain1: bad id="<<id<<std::endl;
00205 return 0.0;
00206 }
00207 }
00208
00209 const double TofSimSvc::BarGain2(unsigned int id) {
00210 if( id < 176 ) {
00211 return fBTofSim[id]->getGain2();
00212 }
00213 else {
00214 std::cout<<"TofSimSvc::BarGain2: bad id="<<id<<std::endl;
00215 return 0.0;
00216 }
00217 }
00218
00219 const double TofSimSvc::EndGain(unsigned int id) {
00220 if( id < 96 ) {
00221 return fETofSim[id]->getGain();
00222 }
00223 else {
00224 std::cout<<"TofSimSvc::EndGain: bad id="<<id<<std::endl;
00225 return 0.0;
00226 }
00227 }
00228
00229 const double TofSimSvc::BarAttenLength(unsigned int id) {
00230 if( id < 176 ) {
00231 return fBTofSim[id]->getAttenLength();
00232 }
00233 else {
00234 std::cout<<"TofSimSvc::BarAttenLength: bad id="<<id<<std::endl;
00235 return 0.0;
00236 }
00237 }
00238
00239 const double TofSimSvc::EndAttenLength(unsigned int id) {
00240 if( id < 96 ) {
00241 return fETofSim[id]->getAttenLength();
00242 }
00243 else {
00244 std::cout<<"TofSimSvc::EndAttenLength: bad id="<<id<<std::endl;
00245 return 0.0;
00246 }
00247 }
00248
00249 const double TofSimSvc::EndNoiseSmear(unsigned int id) {
00250 if( id < 96 ) {
00251 return fETofSim[id]->getNoiseSmear();
00252 }
00253 else {
00254 std::cout<<"TofSimSvc::EndNoiseSmear: bad id="<<id<<std::endl;
00255 return 0.0;
00256 }
00257 }