Skip to content

Commit efe8692

Browse files
committed
added glogger to gphysics
1 parent c3a4548 commit efe8692

13 files changed

Lines changed: 52 additions & 61 deletions

File tree

.github/workflows/sanitize.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,10 @@ jobs:
2525
image: jeffersonlab/geant4:g4v11.3.1-fedora36
2626
- name: almalinux93
2727
image: jeffersonlab/geant4:g4v11.3.1-almalinux94
28-
# to be revisited
29-
# NOTE1: `b_sanitize=memory` is not used because `libc++` needs to be re-compiled with `-fsanitize=memory`, otherwise
30-
# we are bothered by false positives (e.g., from `std::map` insertion)
31-
# NOTE2: additional packages needed for the sanitizer: libasan libubsan libtsan
32-
# NOTE3: address, thread, leak: some examples are not working. Need to investigate.
33-
sanitize: [ none, address, thread, undefined, memory, leak ]
34-
#sanitize: [ standard, undefined ]
28+
# NOTE: additional packages needed for the sanitizer: libasan libubsan libtsan
29+
# MacOS: address, thread, undefined
30+
# Linux: address, hwaddress, leak, undefined, integer, thread, cfi, kcfi, shadowcallstack
31+
sanitize: [ none, address, hwaddress, leak, undefined, integer, thread, cfi, kcfi, shadowcallstack ]
3532
runs-on: ubuntu-latest
3633
continue-on-error: true
3734
container: ${{ matrix.container.image }}

glogging/glogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class GLogger {
164164

165165
private:
166166
std::string verbosity_name; ///< Verbosity name
167-
std::string calling_class; ///< Class name calling the logger constructor
167+
std::string calling_class; ///< Name of class/method calling the logger constructor
168168
int verbosity_level{}; ///< Verbosity level (0 = low, >0 = detailed)
169169
int debug_level{}; ///< Debug level: 0 = off, 1 = normal, 10/-10 = ctor/dtor
170170

goptions/goptions.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ GOptions::GOptions(int argc, char *argv[], const GOptions &user_defined_options)
3939
defineSwitch("gui", "use Graphical User Interface");
4040
defineSwitch("i", "use interactive batch mode");
4141
defineOption(
42-
GVariable("conf_yaml", "saved_configuration", "the yaml filename prefix where all used options are saved"),
42+
GVariable("conf_yaml", "saved_configuration", "the prefix for filename that store the used options"),
4343
"The default value appends \"_saved_configuration\" to the executable name.");
4444

4545
// version is a special option, not settable by the user

gphysics/examples/example.cc

Lines changed: 0 additions & 20 deletions
This file was deleted.

gphysics/examples/example.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// gphysics
2+
#include "gphysics.h"
3+
#include "gphysics_options.h"
4+
5+
// goptions
6+
#include "goptions.h"
7+
8+
9+
int main(int argc, char* argv[]) {
10+
auto gopts = new GOptions(argc, argv, gphysics::defineOptions());
11+
auto log = std::make_shared<GLogger>(gopts, GPHYSICS_LOGGER, "gphysics_example");
12+
13+
[[maybe_unused]] auto gphysics = new GPhysics(gopts, log);
14+
15+
delete gphysics;
16+
return EXIT_SUCCESS;
17+
}

gphysics/gphysics.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
#include "gphysics.h"
33
#include "gphysicsConventions.h"
44

5-
// glibrary
5+
// gemc
66
#include "gutilities.h"
77

88
// geant4 version
99
#include "G4Version.hh"
1010

11-
// c++
12-
using namespace std;
1311

1412
// geant4
1513

@@ -29,8 +27,8 @@ using namespace std;
2927
#include "G4PhysicsConstructorFactory.hh"
3028

3129

32-
GPhysics::GPhysics(GOptions *gopts) : physList(nullptr) {
33-
30+
GPhysics::GPhysics(GOptions *gopts, std::shared_ptr<GLogger> logger) : physList(nullptr), log(logger) {
31+
log->debug(CONSTRUCTOR, "GPhysics");
3432

3533
bool showPhys = gopts->getSwitch("showAvailablePhysics");
3634
bool showPhysX = gopts->getSwitch("showAvailablePhysicsX");
@@ -50,31 +48,35 @@ GPhysics::GPhysics(GOptions *gopts) : physList(nullptr) {
5048
// would make this a drop-in replacement, but we'll list the explicit
5149
// namespace here just for clarity
5250
g4alt::G4PhysListFactory factory;
53-
string g4physList = removeAllSpacesFromString(gphysList);
51+
string g4physList = gutilities::removeAllSpacesFromString(gphysList);
5452

5553
physList = factory.GetReferencePhysList(g4physList);
5654

5755
if (!physList) {
58-
cerr << FATALERRORL << "physics list <" << gphysList << "> could not be loaded." << endl;
59-
gexit(EC__PHYSLISTERROR);
56+
log->error(ERR_PHYSLISTERROR, "physics list <" + gphysList + "> could not be loaded.");
6057
}
6158

62-
cout << GPHYSLOGHEADER << "Geant4 physics list: <" << g4physList << ">" << endl;
59+
log->info(0, "G4PhysListFactory: <" + g4physList + "> loaded.");
6360
}
6461

65-
GPhysics::~GPhysics() {}
62+
GPhysics::~GPhysics() {
63+
log->debug(DESTRUCTOR, "GPhysics");
64+
}
6665

6766

6867
// calls PrintAvailablePhysLists
6968
// if verbosity is > 0 calls PrintAvailablePhysicsConstructors
7069
void GPhysics::printAvailable() {
7170

72-
cout << endl << "Geant4 Version " << replaceCharInStringWithChars(G4Version, "$", "") << " " << G4Date << endl << endl;
71+
string g4ver = gutilities::replaceCharInStringWithChars(G4Version, "$", "");
72+
73+
log->info(0, "Geant4 Version ", g4ver, " ", G4Date);;
7374

7475
g4alt::G4PhysListFactory factory;
7576
factory.PrintAvailablePhysLists();
7677

77-
G4cout << GPHYSLOGHEADER << " Geant4 available physics constructor that can be added to physicsList:" << G4endl;
78+
log->info(0, "Available Geant4 Physics Lists:");
79+
7880
G4PhysicsConstructorRegistry *g4pctorFactory = G4PhysicsConstructorRegistry::Instance();
7981
g4pctorFactory->PrintAvailablePhysicsConstructors();
8082

gphysics/gphysics.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#pragma once
22

3-
// glibrary
4-
#include "goptions.h"
3+
// gemc
4+
#include "glogger.h"
55

66
// geant4
77
#include "G4VModularPhysicsList.hh"
88

9-
// GPhysics Builds and provide a new G4VModularPhysicsList
9+
// GPhysics Builds and provides a new G4VModularPhysicsList
1010
// rather than being a class derived from G4VModularPhysicsList
1111
class GPhysics {
1212
public:
@@ -15,13 +15,13 @@ class GPhysics {
1515

1616
~GPhysics();
1717

18-
G4VModularPhysicsList *getPhysList() { return physList; }
18+
[[nodiscard]] G4VModularPhysicsList *getPhysList() const { return physList; }
1919

2020
private:
2121
// logs physics modules and constructors
22-
void printAvailable(std::shared_ptr<GLogger> log);
23-
22+
void printAvailable();
2423
G4VModularPhysicsList *physList;
24+
std::shared_ptr<GLogger> log;
2525
};
2626

2727

gphysics/gphysicsConventions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
#define DEFAULTPHYSICSLIST "FTFP_BERT"
44

5-
#define EC__PHYSLISTERROR 401
5+
#define ERR_PHYSLISTERROR 401
6+
67

7-
#endif

gphysics/gphysics_options.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ GOptions defineOptions() {
140140
physicsListHelp += string(HELPFILLSPACE) + " - G4WeightWindowBiasing\n";
141141
goptions.defineOption(GVariable("phys_list", DEFAULTPHYSICSLIST, "Select Physics List"), physicsListHelp);
142142

143-
goptions.defineSwitch("showAvailablePhysics", "Log Geant4 Physics Modules that can be used with the \\\"physicsList\\\" option");
144-
goptions.defineSwitch("showAvailablePhysicsX", "Log Geant4 Physics Modules that can be used with the \\\"physicsList\\\" option and exit");
143+
goptions.defineSwitch("showAvailablePhysics", "Log Geant4 Physics Modules that can be used with the \"phys_list\" option");
144+
goptions.defineSwitch("showAvailablePhysicsX", "Log Geant4 Physics Modules that can be used with the \"phys_list\" option and exit");
145145

146146
return goptions;
147147
}

0 commit comments

Comments
 (0)