-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckGeometry.cpp
More file actions
128 lines (99 loc) · 3.9 KB
/
checkGeometry.cpp
File metadata and controls
128 lines (99 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <vector>
#include <unistd.h>
#include <sys/stat.h>
#include <libgen.h>
#include <termios.h>
#include <sys/statvfs.h>
#include <glob.h>
using namespace std;
#include <TROOT.h>
#include <TApplication.h>
#include <TEnv.h>
#include <MString.h>
#include <TSystem.h>
#include "MInterfaceGeomega.h"
/**
@brief Gets file of given file
## Get file size of given file. Credit to Matt on StackOverflow.
### Arguments
- `std::string filename` - Filename to get size of
*/
long getFileSize(std::string filename){
struct stat stat_buf;
int rc = stat(filename.c_str(), &stat_buf);
return rc == 0 ? stat_buf.st_size : -1;
}
/**
@brief Interface to geomega to run geometry checks
## Interface to geomega to run geometry checks
### Purpose
Extends MInterfaceGeomega in order to allow autoMEGA to directly check the geometry for overlaps without a bash call or GUI.
*/
class aMInterfaceGeomega : public MInterfaceGeomega {
public:
aMInterfaceGeomega() : MInterfaceGeomega() {}
/**
@brief Set geometry filename
*/
bool SetGeometry(MString FileName, bool UpdateGui = true) { return m_Data->SetCurrentFileName(FileName); }
/**
@brief Check geometry for overlaps
## Check geometry for overlaps
### Arguments
- `std::string outputFile` - Temp file to write cosima warnings to
### Notes
Returns 1 if there is an overlap, returns 0 otherwise. If cosima cannot be found or files cannot be created for a test, then that test may be skipped.
*/
bool TestIntersections(std::string outputFile){
if(!ReadGeometry()) return 1;
bool status = m_Geometry->CheckOverlaps();
if(!status) return 1;
if(!MFile::Exists(g_MEGAlibPath + "/bin/cosima")) return 0;
MString FileName = gSystem->TempDirectory();
FileName += "/DelMe.source";
ofstream out;
out.open(FileName);
if (!out.is_open()) return 0;
out<<"Version 1\nGeometry "<<m_Data->GetCurrentFileName()<<"\nCheckForOverlaps 10000 0.0001\nPhysicsListEM Standard\nRun Minimum\nMinimum.FileName DelMe\nMinimum.NEvents 1\nMinimum.Source MinimumS\nMinimumS.ParticleType 1\nMinimumS.Position 1 1 0 0 \nMinimumS.SpectralType 1\nMinimumS.Energy 10\nMinimumS.Intensity 1\n";
out.close();
MString WorkingDirectory = gSystem->WorkingDirectory();
gSystem->ChangeDirectory(gSystem->TempDirectory());
gSystem->Exec(MString("bash -c \"source ${MEGALIB}/bin/source-megalib.sh; cosima ") + FileName + MString(" 2>&1 | grep 'issued by : G4PVPlacement::CheckOverlaps()' &> "+outputFile+"\""));
gSystem->Exec(MString("rm -f DelMe.*.sim ") + FileName);
long int size = getFileSize(outputFile);
gSystem->ChangeDirectory(WorkingDirectory);
return size!=0;
}
};
/**
@brief External cpp file to check geomega geometries without linking libraries or opening a GUI
## External cpp file to check geomega geometries without linking libraries or opening a GUI
### Notes:
All arguments are parsed as filenames to be checked, and the program returns the total number of invalid geometries
Returns the total number of invalid geometries
### To build:
```
g++ checkGeometry.cpp -o checkGeometry -std=c++11 -pthread -O2 -Wall $(root-config --cflags --libs) -I$MEGALIB/include -L$MEGALIB/lib -lGeomegaGui -lGeomega -lCommonGui -lCommonMisc
```
*/
int main(int argc,char** argv){
int overall = 0;
// Attempt to mostly quiet the tests
cout.setstate(ios_base::failbit);
cerr.setstate(ios_base::failbit);
gROOT->SetBatch(true);
mout.setstate(std::ios_base::failbit);
gErrorIgnoreLevel = kFatal;
// Check each geometry, return number of failures
for(int i=1;i<argc;i++){
aMInterfaceGeomega geomega;
geomega.SetGeometry(argv[i]);
bool good = geomega.TestIntersections(string(argv[i])+".out");
overall +=good;
}
return overall;
}