Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:43

0001 #include "DD4hep/DDTest.h"
0002 
0003 #include <iostream>
0004 #include <iomanip>
0005 #include <vector>
0006 #include <algorithm>
0007 #include <exception>
0008 
0009 #include "DD4hep/Plugins.h"
0010 #include "DD4hep/Primitives.h"
0011 #include "DDG4/Geant4InputAction.h"
0012 #include "DDG4/Geant4Particle.h"
0013 #include "DDG4/Geant4Vertex.h"
0014 
0015 //using namespace dd4hep::sim;
0016 typedef dd4hep::sim::Geant4Vertex   Vertex;
0017 typedef dd4hep::sim::Geant4Particle Particle;
0018 
0019 static dd4hep::DDTest test( "EventReader" ) ;
0020 
0021 class TestTuple {
0022 public:
0023   std::string readerType;
0024   std::string inputFile;
0025   bool skipEOF; //LCIO skipNEvents does not signal end of file??
0026   TestTuple( std::string const& rT, std::string const& iF, bool sEOF=false): readerType(rT), inputFile(iF), skipEOF(sEOF) {}
0027 };
0028 
0029 
0030 int main(int argc, char** argv ){
0031 
0032   if( argc < 2 ) {
0033     std::cout << " usage:  test_EventReaders Path/To/InputFiles " << std::endl ;
0034     exit(1) ;
0035   }
0036 
0037   std::string inputFileFolder = argv[1];
0038 
0039   std::vector<TestTuple> tests;
0040   #ifdef DD4HEP_USE_LCIO
0041   tests.push_back( TestTuple( "LCIOStdHepReader", "bbudsc_3evt.stdhep" ) );
0042   tests.push_back( TestTuple( "LCIOFileReader",   "muons.slcio" , /*skipEOF= */ true ) );
0043   #endif
0044   tests.push_back( TestTuple( "Geant4EventReaderHepEvtShort", "Muons10GeV.HEPEvt" ) );
0045   #ifdef DD4HEP_USE_HEPMC3
0046   tests.push_back( TestTuple( "HEPMC3FileReader", "g4pythia.hepmc", /*skipEOF= */ true) );
0047   tests.push_back( TestTuple( "HEPMC3FileReader", "Pythia_output.hepmc", /*skipEOF= */ true) );
0048   #endif
0049 
0050   try{
0051     for(std::vector<TestTuple>::const_iterator it = tests.begin(); it != tests.end(); ++it) {
0052       std::string readerType = (*it).readerType;
0053       std::string fileName = (*it).inputFile;
0054       bool skipEOF =  (*it).skipEOF;
0055       //InputFiles are in DDTest/inputFiles, argument is cmake_source directory
0056       std::string inputFile = argv[1]+ std::string("/inputFiles/") + fileName;
0057       dd4hep::sim::Geant4EventReader* thisReader = dd4hep::PluginService::Create<dd4hep::sim::Geant4EventReader*>(readerType, inputFile);
0058       if ( not thisReader ) {
0059         test.log( "Plugin not found" );
0060         test.log( readerType );
0061         continue;
0062       }
0063       test( thisReader->currentEventNumber() == 0 , readerType + std::string("Initial Event Number") );
0064       thisReader->moveToEvent(1);
0065       test( thisReader->currentEventNumber() == 1 , readerType + std::string("Event Number after Skip") );
0066       std::vector<Particle*> particles;
0067       std::vector<Vertex*> vertices ;
0068 
0069       dd4hep::sim::Geant4EventReader::EventReaderStatus sc = thisReader->readParticles(3,vertices,particles);
0070       std::for_each(particles.begin(),particles.end(),dd4hep::detail::deleteObject<Particle>);
0071       test( thisReader->currentEventNumber() == 2 && sc == dd4hep::sim::Geant4EventReader::EVENT_READER_OK,
0072             readerType + std::string("Event Number Read") );
0073 
0074       //Reset Reader to check what happens if moving to far in the file
0075       if (not skipEOF) {
0076         thisReader = dd4hep::PluginService::Create<dd4hep::sim::Geant4EventReader*>(readerType, std::move(inputFile));
0077         sc = thisReader->moveToEvent(1000000);
0078         test( sc != dd4hep::sim::Geant4EventReader::EVENT_READER_OK , readerType + std::string("EventReader False") );
0079       }
0080     }
0081 
0082   } catch( std::exception &e ){
0083     //} catch( ... ){
0084 
0085     test.log( e.what() );
0086     test.error( "exception occurred" );
0087   }
0088   return 0;
0089 }
0090