ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
G4UA::Geant4SetupChecker Class Reference

#include <Geant4SetupChecker.h>

Inheritance diagram for G4UA::Geant4SetupChecker:
Collaboration diagram for G4UA::Geant4SetupChecker:

Public Member Functions

 Geant4SetupChecker (const std::string &, const bool)
 
virtual void BeginOfRunAction (const G4Run *) override
 

Private Attributes

std::string m_file_location
 File location for reference file. More...
 
bool m_test
 Do you want to write a reference or read a file to check? More...
 

Detailed Description

Definition at line 14 of file Geant4SetupChecker.h.

Constructor & Destructor Documentation

◆ Geant4SetupChecker()

G4UA::Geant4SetupChecker::Geant4SetupChecker ( const std::string &  file_location,
const bool  test = true 
)

Definition at line 22 of file Geant4SetupChecker.cxx.

22  : m_file_location(file_location) , m_test(test) {;
23 }

Member Function Documentation

◆ BeginOfRunAction()

void G4UA::Geant4SetupChecker::BeginOfRunAction ( const G4Run *  )
overridevirtual

Definition at line 25 of file Geant4SetupChecker.cxx.

25  {
26 
27  // Print the sizes of several stores
28  G4LogicalVolumeStore* g4_logical_volume_store = G4LogicalVolumeStore::GetInstance();
29  G4PhysicalVolumeStore* g4_physical_volume_store = G4PhysicalVolumeStore::GetInstance();
30  G4RegionStore* g4_region_store = G4RegionStore::GetInstance();
31 
32  // For each region: GetNumberOfMaterials GetFastSimulationManager ( GetFastSimulationModelList().size() )
33 
34  // Might be nice to get at some kind of field information? Stepper?
35 // G4TransportationManager* g4_transportation_manager = G4TransportationManager::GetTransportationManager();
36 
37  if (m_test){
38  // open a file for comparing these numbers to
39  std::ifstream infile(m_file_location);
40  for (std::string line; std::getline(infile, line); ){
41  std::istringstream in(line);
42  std::string id;
43  in >> id;
44  // Basic geometry counts
45  if ("Counts"==id){
46  unsigned int lvs=0,pvs=0,regs=0;
47  in >> lvs >> pvs >> regs;
48  if (lvs!=g4_logical_volume_store->size()){
49  G4ExceptionDescription ed;
50  ed << "ERROR! Reference had " << lvs << " and this setup has " << g4_logical_volume_store->size() << " logical volumes" << G4endl;
51  G4Exception("Geant4SetupChecker","LogVolMismatch",FatalException,ed);
52  abort();
53  }
54  if (pvs!=g4_physical_volume_store->size()){
55  G4ExceptionDescription ed;
56  ed << "ERROR! Reference had " << pvs << " and this setup has " << g4_physical_volume_store->size() << " physical volumes" << G4endl;
57  G4Exception("Geant4SetupChecker","PhysVolMismatch",FatalException,ed);
58  abort();
59  }
60  if (regs!=g4_region_store->size()){
61  G4ExceptionDescription ed;
62  ed << "ERROR! Reference had " << regs << " and this setup has " << g4_region_store->size() << " regions" << G4endl;
63  G4Exception("Geant4SetupChecker","RegionMismatch",FatalException,ed);
64  abort();
65  }
66  } // This was the basic geometry counting part
67  else { // This is a region - check materials and fast sim
68  G4Region* areg = g4_region_store->GetRegion(id);
69  if (!areg){
70  G4ExceptionDescription ed;
71  ed << "ERROR! Reference had region named " << id << "that is not in this configuration, or has changed name" << G4endl;
72  G4Exception("Geant4SetupChecker","RegionNotFound",FatalException,ed);
73  abort();
74  }
75  unsigned int nmat=0, nfs=0;
76  in >> nmat >> nfs;
77  if (nmat!=areg->GetNumberOfMaterials()){
78  G4ExceptionDescription ed;
79  ed << "ERROR! Region " << id << " had " << nmat << " materials in ref and " << areg->GetNumberOfMaterials() << " in this setup" << G4endl;
80  G4Exception("Geant4SetupChecker","MaterialMismatch",FatalException,ed);
81  abort();
82  }
83  if ( (!areg->GetFastSimulationManager() && nfs!=0) ||
84  ( areg->GetFastSimulationManager() && nfs!=areg->GetFastSimulationManager()->GetFastSimulationModelList().size()) ){
85  G4ExceptionDescription ed;
86  ed << "ERROR! Region " << id << " had " << nfs << " fast sims in ref and " << (areg->GetFastSimulationManager()?areg->GetFastSimulationManager()->GetFastSimulationModelList().size():0) << " in this setup" << G4endl;
87  G4Exception("Geant4SetupChecker","FastSimMismatch",FatalException,ed);
88  abort();
89  }
90  } // End of region handling
91  } // loop over lines
92  infile.close();
93  G4cout << "All ok!" << G4endl;
94  } // Done with the test!
95  else {
96  std::ofstream outfile(m_file_location);
97  outfile << "Counts " << g4_logical_volume_store->size() << " " << g4_physical_volume_store->size() << " " << g4_region_store->size() << std::endl;
98  // Now go through all the regions
99  for (auto* areg : *g4_region_store){
100  outfile << areg->GetName() << " " << areg->GetNumberOfMaterials() << " " << (areg->GetFastSimulationManager()?areg->GetFastSimulationManager()->GetFastSimulationModelList().size():0) << std::endl;
101  }
102  outfile.close();
103  } // Done with writing a reference file
104 }

Member Data Documentation

◆ m_file_location

std::string G4UA::Geant4SetupChecker::m_file_location
private

File location for reference file.

Definition at line 22 of file Geant4SetupChecker.h.

◆ m_test

bool G4UA::Geant4SetupChecker::m_test
private

Do you want to write a reference or read a file to check?

Definition at line 24 of file Geant4SetupChecker.h.


The documentation for this class was generated from the following files:
checkFileSG.line
line
Definition: checkFileSG.py:75
run.infile
string infile
Definition: run.py:13
TrigInDetValidation_Base.test
test
Definition: TrigInDetValidation_Base.py:144
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:194
G4UA::Geant4SetupChecker::m_file_location
std::string m_file_location
File location for reference file.
Definition: Geant4SetupChecker.h:22
G4UA::Geant4SetupChecker::m_test
bool m_test
Do you want to write a reference or read a file to check?
Definition: Geant4SetupChecker.h:24
PrepareReferenceFile.outfile
outfile
Definition: PrepareReferenceFile.py:42