Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GlastDetSvc.cpp

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/GlastSvc/src/GlastDetSvc/GlastDetSvc.cpp,v 1.10 2001/04/19 01:32:30 igable Exp $
00002 // 
00003 //  Original author: Sawyer Gillespie
00004 //                   hgillesp@u.washington.edu
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 // define the class-id (unique) for the GlastDetSvc
00016 // moved to Kernel! const IID&  IID_IGlastDetSvc  =  401;   // Unique to GLAST 
00017 
00018 // define the class-id (unique) for the GlastIRFSvc
00019 //const IID&  IID_IGlastIRFLoadSvc  =  402;   // Unique to GLAST
00020 
00021 
00022 // declare the service factories for the GlastDetSvc
00023 static SvcFactory<GlastDetSvc> a_factory;
00024 const ISvcFactory& GlastDetSvcFactory = a_factory;
00025 
00026 
00027 // file scope for WARNING and ERROR
00028 static MsgStream * s_log;
00029 
00030 // external declarations of the service identifiers
00031 // HSG - not necessary from the Gaudi example - extern const IID& IID_IGlastDetSvc;
00032 
00033 // ------------------------------------------------
00034 // Implementation of the GlastDetSvc class
00035 // ------------------------------------------------
00037 GlastDetSvc::GlastDetSvc(const std::string& name,ISvcLocator* svc)
00038 : Service(name,svc)
00039 , m_instrument (0)
00040 , m_xmlFile ("")
00041 , m_iniFile ("")
00042 {
00043     
00044     // declare the properties
00045     declareProperty ("PersistencyFile", m_xmlFile);
00046     declareProperty ("IniFile", m_iniFile);
00047     
00048 }
00050 GlastDetSvc::~GlastDetSvc()  
00051 {
00052     // this is  repetetive in case finalize was
00053     // not called.
00054     
00055     finalize();
00056 }
00057 
00058 // queryInterface
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 // initialize
00072 StatusCode GlastDetSvc::initialize () 
00073 {
00074     StatusCode  status = StatusCode::SUCCESS;
00075     
00076     // call super-class
00077     Service::initialize ();
00078     
00079     // bind all of the properties for this service
00080     status = setProperties ();
00081     
00082     
00083     // open the message log
00084     MsgStream log( msgSvc(), name() );
00085     s_log = & log;  // make available globally while executing the following
00086     
00087     log << MSG::DEBUG << "Loading instrument ...";
00088     // now create and initialize the instruemtn
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 // finalize
00100 StatusCode GlastDetSvc::finalize ()
00101 {
00102     StatusCode  status = StatusCode::SUCCESS;
00103     
00104     // get rid of a glast detector hierarchy
00105     delete m_instrument;
00106     m_instrument = 0;
00107     
00108     return status;
00109 }
00110 
00111 
00112 // loadNextEvent - attempt to load the next event from the
00113 //                 IRF file.
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 // access the type of this service
00124 const IID&  GlastDetSvc::type () const {
00125     return IID_IGlastDetSvc;
00126 }
00127 
00128 
00129 
00130 // loadIRFFile - attempt to open the IRF file here
00131 StatusCode  GlastDetSvc::openIRF (std::string filename)
00132 {
00133     MsgStream log( msgSvc(), name() );
00134     s_log = & log;  // make available globally while executing the following
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 

Generated at Wed Nov 21 12:21:12 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000