00001 // $Header: /nfs/slac/g/glast/ground/cvs/instrument/src/test/main.cxx,v 1.7 2000/11/03 17:30:57 jrb Exp $ 00002 00003 // Test program for the instrument classes 00004 00005 #include "instrument/Instrument.h" 00006 #include "instrument/GlastDetector.h" 00007 #include "instrument/DetectorConverter.h" 00008 #include <iostream> 00009 00010 #include "instrument/CsIDetector.h" 00011 #include "instrument/MCTruth.h" 00012 #include "instrument/Scintillator.h" 00013 #include "instrument/SiDetector.h" 00014 #include "instrument/SiTracker.h" 00015 00016 00017 extern void FATAL ( const char* msg ) 00018 { 00019 std::cerr << "FATAL " << msg << std::endl; 00020 } 00021 00022 extern void WARNING ( const char* msg ) 00023 { 00024 std::cerr << "WARNING " << msg << std::endl; 00025 } 00026 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00027 // Example visitor 00028 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00029 class ResponseConverter : public DetectorConverter { 00030 public: 00031 00032 void forward ( const CsIDetector& d ) 00033 { 00034 if ( !(d.empty()) ) { 00035 // write this guy out! 00036 //std::cout << "csi " << std::endl; 00037 } 00038 } 00039 00040 void forward ( const MCTruth& d ) 00041 { 00042 if ( !(d.empty()) ) { 00043 // write out 00044 //std::cout << "MCTRUTH data!" << std::endl; 00045 } 00046 } 00047 00048 void forward ( const Scintillator& d ) 00049 { 00050 if ( !(d.empty()) ) { 00051 // write 00052 //std::cout<< "ACD data!" << std::endl; 00053 } 00054 } 00055 00056 void forward ( const SiDetector& d ) 00057 { 00058 if ( !(d.empty()) ) { 00059 // write out 00060 //std::cout << "we have some Si Data " << std::endl; 00061 } 00062 } 00063 00064 }; 00065 00066 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00067 00068 int main(int argc, char* argv[]) { 00069 00070 Instrument g; 00071 00072 // initialize, by reading default ini and xml files 00073 int rc = g.initialize(); 00074 00075 if( rc) { 00076 return rc; 00077 } 00078 else std::cout << "Loaded " << g.detector_count() 00079 << " elements from detector definition file " 00080 << g.xmlFileName() << std::endl; 00081 00082 if( argc <2 ) { 00083 std::cerr << "Need to specify an IRF file name!" << std::endl; return 1; 00084 } 00085 00086 rc = g.openIRF(argv[1]); 00087 00088 if (rc==0 ) { 00089 std::cout << "Opened " << g.irfFileName() << " for reading" << std::endl; 00090 } else return rc; 00091 00092 int irec=0; 00093 while( rc==0 ) { 00094 rc = g.readIRF(); 00095 if(rc==0) std::cout << "Record " << (++irec) 00096 <<": found " << g.detectors_with_data() 00097 << " detectors with hits" << std::endl; 00098 00099 // Look at the resulting detectors, brute force 00100 int count=0; 00101 for (GlastDetector::MemberList::const_iterator it = 00102 GlastDetector::allbegin(); it !=GlastDetector::allend(); ++it) { 00103 const GlastDetector * d =(*it).second; 00104 if (!(d->empty())) { 00105 ++ count; 00106 } 00107 } 00108 // now use a visitor, defined above 00109 g.accept(ResponseConverter()); 00110 } 00111 00112 00113 return 0; 00114 }
1.2.3 written by Dimitri van Heesch,
© 1997-2000