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

AOrecon.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/aoRecon/src/AOrecon.cxx,v 1.9 2001/08/31 14:57:55 burnett Exp $
00002 
00003 // Include files
00004 
00005 #include "GaudiKernel/MsgStream.h"
00006 #include "GaudiKernel/AlgFactory.h"
00007 #include "GaudiKernel/IDataProviderSvc.h"
00008 #include "GaudiKernel/SmartDataPtr.h"
00009 #include "GaudiKernel/Algorithm.h"
00010 
00011 #include "GlastSvc/GlastDetSvc/IGlastDetSvc.h"
00012 
00013 #include "xml/IFile.h"
00014 
00015 #include "reconstruction/GlastTuple.h"
00016 #include "reconstruction/PrintReconData.h"
00017 #include "reconstruction/SummaryData.h"
00018 
00019 // TDS class declarations: input data, 
00020 #include "GlastEvent/data/TdGlastData.h"
00021 
00022 #include "GuiSvc/IGuiSvc.h"
00023 #include "gui/GuiMgr.h"
00024 #include "gui/DisplayControl.h"
00025 
00026 // Include files
00027 #include "instrument/MCTruth.h"
00028 #include "instrument/FluxGenerator.h"
00029 
00030 #include "reconstruction/SummaryData.h"
00031 #include "reconstruction/ReconData.h"
00032 
00033 #include "GaudiTuple.h"
00034 #include "ntupleWriterSvc/INTupleWriterSvc.h"
00035 
00036 
00037 //------------------------------------------------------------------------------
00043 class AOrecon : public Algorithm {
00044     
00045 public:
00047     AOrecon(const std::string& name, ISvcLocator* pSvcLocator); 
00048     
00049     StatusCode initialize();
00050     StatusCode execute();
00051     StatusCode finalize();
00052     
00053 private:
00054     // the GlastDetSvc used for access to detector info
00055     IGlastDetSvc*    m_detSvc;
00056     // ptr to the GlastRecon object used to do the analysis
00057     GlastRecon*    m_recon;
00058     
00059     // constants from the "instrument.xml" file.
00060     xml::IFile * m_ini;
00061     SummaryData<GaudiTuple>* m_gsummary;
00062 
00063     INTupleWriterSvc* m_ntupleWriterSvc; //pointer to Heather's ntupleWriterSvc 
00064     
00065 
00066     std::string m_tuple_name; 
00067 };
00068 
00069 //------------------------------------------------------------------------------
00070 static const AlgFactory<AOrecon>  Factory;
00071 const IAlgFactory& AOreconFactory = Factory;
00072 //------------------------------------------------------------------------------
00074 AOrecon::AOrecon(const std::string& name, ISvcLocator* pSvcLocator) :
00075 Algorithm(name, pSvcLocator), m_detSvc(0)
00076 , m_recon(0), m_gsummary(0){
00077 
00078     declareProperty("tuple_name",  m_tuple_name="");
00079 
00080 }
00081 
00082 //------------------------------------------------------------------------------
00085 StatusCode AOrecon::initialize() {
00086     
00087     MsgStream log(msgSvc(), name());
00088     
00089     // Use the Job options service to set the Algorithm's parameters
00090     setProperties();
00091     
00092     // now try to find the GlastDevSvc service
00093     StatusCode sc = service("GlastDetSvc", m_detSvc);
00094     
00095     
00096     if (!sc.isSuccess ()){
00097         log << MSG::ERROR << "Couldn't find the GlastDetSvc!" << endreq;
00098         return sc;
00099     }
00100     
00101     // test: get a constant from the ini file
00102     m_ini = const_cast<xml::IFile*>(m_detSvc->iniFile()); //OOPS!
00103     int nx = m_ini->getInt("glast", "xNum");
00104     
00105     m_recon=new GlastRecon;
00106     
00107 
00108     // get the Gui service (not required)
00109     IGuiSvc* guiSvc=0;
00110     sc = service("GuiSvc", guiSvc);
00111 
00112     if (!sc.isSuccess ()){
00113         log << MSG::WARNING << "No GuiSvc, so no display" << endreq;
00114         sc =StatusCode::SUCCESS; 
00115     }else{
00116        guiSvc->guiMgr()->display().add(m_recon->displayRep(), "Glast reco");
00117     }
00118 
00119         // access heather ntupleWiterSvc so that it can be passed
00120         // to GaudiTuple
00121         sc = service("ntupleWriterSvc", m_ntupleWriterSvc);
00122 
00123         if (!sc.isSuccess()){
00124                 log << MSG::ERROR << "Unable to get ntupleWriterSvc" << endreq;
00125                 return sc;
00126         }
00127 
00128 
00129     if( !m_tuple_name.empty() ) {
00130         // create and set the entries into a Gaudi Tuple
00131         m_gsummary = new SummaryData<GaudiTuple>(
00132             *new GaudiTuple(m_ntupleWriterSvc,"AO Recon output", m_tuple_name.c_str() ));
00133         m_recon->accept(*m_gsummary);   
00134         log << MSG::INFO << "Generating n-tuple to logical file " << m_tuple_name << endreq;
00135     }
00136 
00137     // make sure exists
00138     if(MCTruth::instance() ==0) new MCTruth();
00139     return sc;
00140 }
00141 
00142 
00143 //------------------------------------------------------------------------------
00144 StatusCode AOrecon::execute() {
00145     
00146  
00147     StatusCode  sc = StatusCode::SUCCESS;
00148     MsgStream   log( msgSvc(), name() );
00149     
00150     static std::string path("/Event/TdGlastData");
00151     SmartDataPtr<TdGlastData> data(eventSvc(), path);
00152     
00153     if( 0==data) { log << MSG::ERROR << "could not find \""<< path <<"\"" << endreq;
00154        return StatusCode::FAILURE;
00155     }
00156 
00157  
00158     // see what is there
00159     if( msgSvc()->outputLevel()<3 ) data->printOn(std::cout);
00160     
00161     
00162     m_recon->clear();
00163     //  pass data to the GlastRecon object.
00164     m_recon->accept(ReconData(data));
00165 
00166     
00167     // see how many tracks found
00168     log << MSG::DEBUG << "Found " 
00169         <<  (m_recon->getTracker()->data.getData("No_Tracks")) << " tracks" << endreq;
00170 
00171     // print out the  tuple
00172     if( msgSvc()->outputLevel()<3 ) m_recon->accept(PrintReconData(std::cout));
00173     
00174 
00175     // fill and write out the Gaudi tuple   
00176     if( m_gsummary !=0)  m_gsummary->tuple()->fill();
00177 
00178     return sc;
00179 }
00180 
00181 
00182 //------------------------------------------------------------------------------
00183 StatusCode AOrecon::finalize() {
00184     StatusCode  sc = StatusCode::SUCCESS;
00185     
00186     MsgStream log(msgSvc(), name());
00187     log << MSG::INFO << "finalize" << endreq;
00188     delete m_recon;
00189     delete m_gsummary;
00190 #if 0 // does not work
00191     //try to read tuple back
00192     NTuplePtr nt(ntupleSvc(), "/NTUPLES/CALRECON/1");
00193     if( nt) {
00194         int count=0;
00195         NTuple::Item<float>esum;
00196         sc = nt->item("CsI_Energy_Sum", esum);
00197         while( ntupleSvc()->readRecord(nt.ptr()).isSuccess() ) {
00198             log << MSG::INFO << " Entry [" << (count++) <<"]" << "Etot=" << esum << endreq;
00199         }
00200         log << MSG::INFO << count << " entries " << endreq;
00201                
00202     }else {
00203         log << MSG::INFO << "Could not open tuple  /NTUPLES/AOrecon/1" << endreq;
00204     }
00205 #endif   
00206     return StatusCode::SUCCESS;
00207 }
00208 
00209 //------------------------------------------------------------------------------
00212 #if 0
00213 StatusCode AOrecon::printNewNTuple(std::string dname) {
00214     StatusCode status;
00215     MsgStream log(msgSvc(), name());
00216     
00217     NTuplePtr nt = m_gsummary->tuple()->getNTuple();
00218     if( nt) {
00219         NTuple::Item<float> data;
00220         status = nt->item(dname ,data);
00221        
00222         if(status.isSuccess()) {
00223             log << MSG::INFO << "Test Value of :"
00224                 << dname << "= " << data << endreq;
00225         } else {
00226             log << MSG::ERROR << "Didn't load the Item!" << endreq;
00227         }
00228     } else {
00229         log << MSG::ERROR << "Dead NTuple !" << endreq;
00230     }
00231     return status;
00232 }
00233 
00234 
00235 #endif
00236 
00237 
00238 

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