Skip to content

Commit

Permalink
updated nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
martinunland committed Aug 28, 2024
1 parent 480b758 commit 59236a3
Show file tree
Hide file tree
Showing 64 changed files with 2,342 additions and 2,436 deletions.
21 changes: 9 additions & 12 deletions common/framework/include/OMSim.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
* @ingroup common
*/

#ifndef OMSIM_H
#define OMSIM_H
#pragma once


#include "OMSimDetectorConstruction.hh"
Expand Down Expand Up @@ -51,9 +50,9 @@ public:
bool handleArguments(int pArgumentCount, char *pArgumentVector[]);
void startVisualisation();

G4Navigator *getNavigator() { return mNavigator.get(); };
G4Navigator *getNavigator() { return m_navigator.get(); };
void extendOptions(po::options_description pNewOptions);
po::options_description mGeneralOptions;
po::options_description m_generalOptions;

private:
void initialLoggerConfiguration();
Expand All @@ -62,13 +61,11 @@ private:
void setUserArgumentsToArgTable(po::variables_map pVariablesMap);
void setGeneralOptions();

std::unique_ptr<G4MTRunManager> mRunManager;
std::unique_ptr<G4VisExecutive> mVisManager;
std::unique_ptr<G4VUserPhysicsList> mPhysics;
std::unique_ptr<G4TouchableHistory> mHistory;
std::unique_ptr<G4Navigator> mNavigator;
std::unique_ptr<G4MTRunManager> m_runManager;
std::unique_ptr<G4VisExecutive> m_visManager;
std::unique_ptr<G4VUserPhysicsList> m_physics;
std::unique_ptr<G4TouchableHistory> m_history;
std::unique_ptr<G4Navigator> m_navigator;

std::chrono::high_resolution_clock::time_point mStartingTime;
std::chrono::high_resolution_clock::time_point m_startingTime;
};

#endif // OMSIM_H
6 changes: 1 addition & 5 deletions common/framework/include/OMSimActionInitialization.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#ifndef OMSimActionInitialization_h
#define OMSimActionInitialization_h 1

#pragma once
#include "G4VUserActionInitialization.hh"

class OMSimActionInitialization : public G4VUserActionInitialization
Expand All @@ -12,5 +10,3 @@ public:
virtual void BuildForMaster() const;
virtual void Build() const;
};

#endif
160 changes: 26 additions & 134 deletions common/framework/include/OMSimCommandArgsTable.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* @ingroup common
*/

#ifndef OMSIMCOMMANDARGSTABLE_H
#define OMSIMCOMMANDARGSTABLE_H
#pragma once

/**
* @brief Writes a key-value pair to a JSON file if the value type matches TYPE.
Expand All @@ -14,14 +13,14 @@
#define WRITE_TO_JSON_IF_TYPE_MATCHES(VARIANT, TYPE) \
if (type == typeid(TYPE)) \
{ \
lOutputFile << "\t\"" << kv.first << "\": "; \
outputFile << "\t\"" << kv.first << "\": "; \
if (typeid(TYPE) == typeid(std::string)) \
{ \
lOutputFile << "\"" << boost::any_cast<TYPE>(VARIANT) << "\""; \
outputFile << "\"" << boost::any_cast<TYPE>(VARIANT) << "\""; \
} \
else \
{ \
lOutputFile << boost::any_cast<TYPE>(VARIANT); \
outputFile << boost::any_cast<TYPE>(VARIANT); \
} \
}

Expand All @@ -30,13 +29,13 @@
#include <fstream>
#include <boost/any.hpp>
#include <sys/time.h>

#include <map>

// Forward declaration of the class
class OMSimCommandArgsTable;

// Declaration and definition of the inline global pointer
inline OMSimCommandArgsTable* gCommandArgsTable = nullptr;
inline OMSimCommandArgsTable* g_commandArgsTable = nullptr;


/**
Expand All @@ -55,154 +54,47 @@ class OMSimCommandArgsTable
OMSimCommandArgsTable &operator=(const OMSimCommandArgsTable &) = delete;
~OMSimCommandArgsTable() = default;


public:
using Key = std::string;
using Value = boost::any; // Using boost::any to hold any type
private:
bool m_finalized = false;
std::map<Key, Value> m_parameters;

/**
* @brief Initializes the global instance of OMSimCommandArgsTable.
*
* This method is normally called in the constructor of OMSim.
*/
static void init()
{
if (!gCommandArgsTable)
gCommandArgsTable = new OMSimCommandArgsTable();
}

/**
* @brief Deletes the global instance of OMSimCommandArgsTable.
*
* This method is normally called in the destructor ~OMSim.
*/
static void shutdown()
{
delete gCommandArgsTable;
gCommandArgsTable = nullptr;
}

/**
* @return A reference to the OMSimCommandArgsTable instance.
* @throw std::runtime_error if accessed before initialization or after shutdown.
*/
static OMSimCommandArgsTable &getInstance()
{
if (!gCommandArgsTable)
throw std::runtime_error("OMSimCommandArgsTable accessed before initialization or after shutdown!");
return *gCommandArgsTable;
}

/**
* @brief Sets a parameter in the arg table.
* @param pKey The key for the parameter.
* @param pValue The value for the parameter.
* @throw std::runtime_error If the table is already finalized (i.e. somebody is trying to set a new arg parameter after args were parsed (?!)).
*/
void setParameter(const Key &pKey, const Value &pValue)
{
if (mFinalized)
{
throw std::runtime_error("Cannot modify OMSimCommandArgsTable after it's been finalized!");
}
mParameters[pKey] = pValue;
}
public:

static void init();
static void shutdown();
static OMSimCommandArgsTable &getInstance();
void setParameter(const Key &p_key, const Value &p_value);
bool keyExists(const Key &p_key);
void writeToJson(std::string p_fileName);
void finalize();

/**
* @brief Retrieves a parameter from the table.
* @param pKey The key for the parameter.
* @param p_key The key for the parameter.
* @return The parameter value.
* @throw std::invalid_argument If the parameter is not of type T, or if the key does not exist.
*/
template <typename T>
T get(const std::string &pKey)
T get(const std::string &p_key)
{
try
{
return boost::any_cast<T>(mParameters.at(pKey));
return boost::any_cast<T>(m_parameters.at(p_key));
}
catch (const boost::bad_any_cast &e)
{
log_error(("Failed to get parameter " + pKey + " as type " + typeid(T).name()).c_str());
throw std::invalid_argument("Failed to get parameter " + pKey + " as type " + typeid(T).name());
log_error(("Failed to get parameter " + p_key + " as type " + typeid(T).name()).c_str());
throw std::invalid_argument("Failed to get parameter " + p_key + " as type " + typeid(T).name());
}
catch (const std::out_of_range &e)
{
log_error(("Parameter " + pKey + " does not exist").c_str());
throw std::invalid_argument("Parameter " + pKey + " does not exist");
}
}

bool keyExists(const Key &pKey) const
{
return mParameters.find(pKey) != mParameters.end();
}

/**
* @brief Writes the parameters to a JSON-formatted file.
* @param pFileName The name of the JSON file.
* @throw std::runtime_error If the file fails to open.
*/
void writeToJson(std::string pFileName)
{
std::ofstream lOutputFile(pFileName);

if (!lOutputFile.is_open())
{
throw std::runtime_error("Failed to open file " + pFileName);
}

lOutputFile << "{\n";
size_t lCount = mParameters.size();
for (const auto &kv : mParameters)
{
--lCount; // Decrease count for each iteration

if (kv.second.empty())
{
lOutputFile << "\t\"" << kv.first << "\": \"\"";
}
else
{
const std::type_info &type = kv.second.type();

WRITE_TO_JSON_IF_TYPE_MATCHES(kv.second, int)
WRITE_TO_JSON_IF_TYPE_MATCHES(kv.second, double)
WRITE_TO_JSON_IF_TYPE_MATCHES(kv.second, long)
WRITE_TO_JSON_IF_TYPE_MATCHES(kv.second, bool)
WRITE_TO_JSON_IF_TYPE_MATCHES(kv.second, std::string)
}

// Append comma if it's not the last item
if (lCount != 0)
{
lOutputFile << ",";
}

lOutputFile << "\n";
log_error(("Parameter " + p_key + " does not exist").c_str());
throw std::invalid_argument("Parameter " + p_key + " does not exist");
}
lOutputFile << "}\n";
lOutputFile.close();
}

/**
* @brief Finalizes the table, setting a random seed if none was provided. mFinalized is set to true preventing any further modifications.
*/
void finalize()
{
long lSeed;
if (!keyExists("seed"))
{
struct timeval time_for_randy;
gettimeofday(&time_for_randy, NULL);
lSeed = time_for_randy.tv_sec + 4294 * time_for_randy.tv_usec;
setParameter("seed", lSeed);
}
mFinalized = true;
}

private:
bool mFinalized = false;
std::map<Key, Value> mParameters;
};

#endif // OMSIMCOMMANDARGSTABLE_H
24 changes: 10 additions & 14 deletions common/framework/include/OMSimHitManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* @ingroup common
*/

#ifndef OMSimHitManager_h
#define OMSimHitManager_h 1
#pragma once

#include "OMSimPMTResponse.hh"

Expand Down Expand Up @@ -86,27 +85,24 @@ public:
bool areThereHitsInModuleSingleThread(int pModuleIndex = 0);
void sortHitStatsByTime(HitStats &pHits);
std::vector<int> calculateMultiplicity(const G4double pTimeWindow, int pModuleNumber = 0);
G4int getNextDetectorIndex() { return ++mCurrentIndex; }
G4int getNumberOfModules() { return mCurrentIndex + 1; }
G4int getNextDetectorIndex() { return ++m_currentIndex; }
G4int getNumberOfModules() { return m_currentIndex + 1; }

void mergeThreadData();

std::map<G4int, HitStats> mModuleHits; ///< Map of a HitStats containing hit information for each simulated optical module
std::map<G4int, HitStats> m_moduleHits; ///< Map of a HitStats containing hit information for each simulated optical module

private:
std::map<G4int, G4int> mNumPMTs; ///< Map of number of PMTs in the used optical modules
G4int mCurrentIndex;

static G4Mutex mMutex;
static OMSimHitManager *mInstance;

std::map<G4int, G4int> m_numberOfPMTs; ///< Map of number of PMTs in the used optical modules
G4int m_currentIndex;
static G4Mutex m_mutex;
static OMSimHitManager *m_instance;
struct ThreadLocalData
{
std::map<G4int, HitStats> moduleHits;
};
G4ThreadLocal static ThreadLocalData *mThreadData;
G4ThreadLocal static ThreadLocalData *m_threadData;
};

inline OMSimHitManager *gHitManager = nullptr;
inline OMSimHitManager *g_hitManager = nullptr;

#endif
9 changes: 2 additions & 7 deletions common/framework/include/OMSimLogger.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#ifndef OMSimLogger_h
#define OMSimLogger_h 1

#pragma once
#include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <memory>
#include "spdlog/fmt/fmt.h"

// Global logger instance
extern std::shared_ptr<spdlog::logger> globalLogger;
extern std::shared_ptr<spdlog::logger> g_logger;

// Custom logging function
void customLog(spdlog::level::level_enum log_level, const char* file, int line, const char* func, const std::string& message);
Expand All @@ -19,6 +17,3 @@ void customLog(spdlog::level::level_enum log_level, const char* file, int line,
#define log_warning(...) customLog(spdlog::level::warn, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__))
#define log_error(...) customLog(spdlog::level::err, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__))
#define log_critical(...) customLog(spdlog::level::critical, __FILE__, __LINE__, __func__, fmt::format(__VA_ARGS__))

#endif
//
5 changes: 1 addition & 4 deletions common/framework/include/OMSimOpBoundaryProcess.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@
//
////////////////////////////////////////////////////////////////////////

#ifndef G4OpBoundaryProcess_h
#define G4OpBoundaryProcess_h 1

#pragma once
#include "G4OpticalPhoton.hh"
#include "G4OpticalSurface.hh"
#include "G4RandomTools.hh"
Expand Down Expand Up @@ -412,4 +410,3 @@ inline void G4OpBoundaryProcess::DoReflection()
-fOldPolarization + (2. * fOldPolarization * fFacetNormal * fFacetNormal);
}

#endif /* G4OpBoundaryProcess_h */
Loading

0 comments on commit 59236a3

Please sign in to comment.