00001
00002
00003
00004
00005
00006
00007 #include "GlastDetSvc.h"
00008
00009 #include <fstream>
00010 #include "GaudiKernel/SvcFactory.h"
00011 #include "GaudiKernel/MsgStream.h"
00012 #include "instrument/Instrument.h"
00013 #include "xml/IFile.h"
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 static SvcFactory<GlastDetSvc> a_factory;
00024 const ISvcFactory& GlastDetSvcFactory = a_factory;
00025
00026
00027
00028 static MsgStream * s_log;
00029
00030
00031
00032
00033
00034
00035
00037
00038 : Service(name,svc)
00039 , m_instrument (0)
00040 , m_xmlFile ("")
00041 , m_iniFile ("")
00042 {
00043
00044
00045 declareProperty ("PersistencyFile", m_xmlFile);
00046 declareProperty ("IniFile", m_iniFile);
00047
00048 }
00050 GlastDetSvc::~GlastDetSvc()
00051 {
00052
00053
00054
00055 finalize();
00056 }
00057
00058
00059 StatusCode GlastDetSvc::queryInterface (const IID& riid, void **ppvIF)
00060 {
00061 if (IID_IGlastDetSvc == riid) {
00062 *ppvIF = dynamic_cast<IGlastDetSvc*> (this);
00063 return StatusCode::SUCCESS;
00064 }
00065 else {
00066 return Service::queryInterface (riid, ppvIF);
00067 }
00068 }
00069
00070
00071
00072 StatusCode GlastDetSvc::initialize ()
00073 {
00074 StatusCode status = StatusCode::SUCCESS;
00075
00076
00077 Service::initialize ();
00078
00079
00080 status = setProperties ();
00081
00082
00083
00084 MsgStream log( msgSvc(), name() );
00085 s_log = & log;
00086
00087 log << MSG::DEBUG << "Loading instrument ...";
00088
00089 m_instrument = new Instrument;
00090 if (m_instrument->initialize(m_iniFile, m_xmlFile) ) status=StatusCode::FAILURE;
00091 log << MSG::DEBUG << "done. Loaded "<< m_instrument->detector_count() << " detectors." << endreq;
00092 return status;
00093 }
00094 void GlastDetSvc::setDetector(GlastDetector* d)
00095 {
00096 m_instrument->setDetector(d);
00097 }
00098
00099
00100 StatusCode GlastDetSvc::finalize ()
00101 {
00102 StatusCode status = StatusCode::SUCCESS;
00103
00104
00105 delete m_instrument;
00106 m_instrument = 0;
00107
00108 return status;
00109 }
00110
00111
00112
00113
00114 StatusCode GlastDetSvc::readIRF ()
00115 {
00116 StatusCode status = StatusCode::SUCCESS;
00117
00118 if (m_instrument->readIRF() ) status = StatusCode::FAILURE;
00119 return status;
00120 }
00121
00122
00123
00124 const IID& GlastDetSvc::type () const {
00125 return IID_IGlastDetSvc;
00126 }
00127
00128
00129
00130
00131 StatusCode GlastDetSvc::openIRF (std::string filename)
00132 {
00133 MsgStream log( msgSvc(), name() );
00134 s_log = & log;
00135
00136 int rc = m_instrument->openIRF(filename);
00137 return rc==0? StatusCode::SUCCESS : StatusCode::FAILURE;
00138 }
00139
00141 int GlastDetSvc::detectors_with_data()const
00142 {
00143 return m_instrument->detectors_with_data();
00144 }
00145
00146 GlastDetector* GlastDetSvc::getRootDetector(void)
00147 {
00148 return m_instrument->rootDetector();
00149 }
00150
00152 void GlastDetSvc::accept(DetectorConverter& v)const {
00153 m_instrument->accept(v);
00154 }
00155
00157 const xml::IFile* GlastDetSvc::iniFile()const{
00158 return m_instrument->iniFile();
00159 }
00160
00162 extern void FATAL ( const char* msg )
00163 {
00164 (*s_log) << MSG::FATAL << msg << endreq;
00165 }
00166
00168 extern void WARNING ( const char* msg )
00169 {
00170 (*s_log) << MSG::WARNING << msg << endreq;
00171 }
00172
00173