Skip to content

Commit

Permalink
Merge pull request #182 from mach3-software/feature_Tidy
Browse files Browse the repository at this point in the history
Tidy
  • Loading branch information
KSkwarczynski authored Oct 24, 2024
2 parents 963bba0 + 8461aeb commit 42d2582
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 325 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md → .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ Logger by default will print whole float. Normally to show only several signific
```cpp
MACH3LOG_INFO("Here is full LLH but I only show 2 significant figures {:.2f}", LLH);
```
If you want to mimic std::setw<<10
```cpp
MACH3LOG_INFO("Some break {:<10}", blarb);
```
Laslty if you want combine precision and std::setw like format
```cpp
MACH3LOG_INFO("Some break {:<10.2f}", blarb);
```
## Config Syntax
MaCh3 currently uses yaml as config handler. To help unify syntax over the code there are several YamlHelper function available [here](https://github.com/mach3-software/MaCh3/blob/develop/manager/YamlHelper.h). Most important is `GetFromManager`. For code below which checks if config entry exist and if doesn't set some default value
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH)

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
#KS: Store some handy cmake functions
#KS: Load cmake function like DefineEnabledRequiredSwitch allowing to write more compact cmake
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/MaCh3Utils.cmake)

################################## Dependencies ################################
Expand All @@ -65,7 +65,6 @@ if(ROOT_CXX_STANDARD LESS 14 AND ROOT_VERSION VERSION_LESS 6.32.00)
endif()

############################ Setting Flags ####################################
# Check the where to install
cmessage(STATUS "CMAKE_INSTALL_PREFIX: \"${CMAKE_INSTALL_PREFIX}\"")

# add cmake script files
Expand Down
21 changes: 6 additions & 15 deletions Diagnostics/RHat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,16 @@ int main(int argc, char *argv[]) {
// Load chain and prepare toys
void PrepareChains() {
// *******************

TRandom3 *rnd = new TRandom3(0);
auto rnd = std::make_unique<TRandom3>(0);

MACH3LOG_INFO("Generating {}", Ntoys);

TStopwatch clock;
clock.Start();

int *BurnIn = new int[Nchains]();
int *nEntries = new int[Nchains]();
int *nBranches = new int[Nchains]();

std::vector<int> BurnIn(Nchains);
std::vector<int> nEntries(Nchains);
std::vector<int> nBranches(Nchains);
std::vector<int> step(Nchains);

Draws = new double**[Nchains]();
Expand Down Expand Up @@ -325,7 +323,7 @@ void PrepareChains() {
for(int j = 0; j < nDraw; j++)
{
MedianArr[j] = 0.;
double* TempDraws = new double[Ntoys*Nchains]();
std::vector<double> TempDraws(Ntoys * Nchains);
for(int m = 0; m < Nchains; m++)
{
for(int i = 0; i < Ntoys; i++)
Expand All @@ -334,8 +332,7 @@ void PrepareChains() {
TempDraws[im] = Draws[m][i][j];
}
}
MedianArr[j] = CalcMedian(TempDraws, Ntoys*Nchains);
delete[] TempDraws;
MedianArr[j] = CalcMedian(TempDraws.data(), Ntoys*Nchains);
}

#ifdef MULTITHREAD
Expand All @@ -351,12 +348,6 @@ void PrepareChains() {
}
}
}
delete rnd;

delete[] BurnIn;
delete[] nEntries;
delete[] nBranches;

clock.Stop();
MACH3LOG_INFO("Finished calculating Toys, it took {:.2f}s to finish", clock.RealTime());
}
Expand Down
2 changes: 1 addition & 1 deletion cmake/Modules/NuOscillatorSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ get_target_property(compile_options MaCh3CompilerOptions INTERFACE_COMPILE_OPTIO
# Join the compile options list into a space-separated string
string(REPLACE ";" " " compile_options_string "${compile_options}")

#KS this may look hacky however CPM isn't build for passing stuff like this. If CMAKE_CUDA_ARCHITECTURES is passed CPM it will be string not list. Thus we convert it to list
#KS: This may seem hacky, but when CMAKE_CUDA_ARCHITECTURES is passed, it's treated as a string rather than a list. Since CMake uses semi-colon-delimited strings to represent lists, we convert it to a proper list to handle CUDA architectures correctly.
set(CMAKE_CUDA_ARCHITECTURES_STRING ${CMAKE_CUDA_ARCHITECTURES})
string(REPLACE " " ";" CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")

Expand Down
18 changes: 9 additions & 9 deletions covariance/covarianceBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ covarianceBase::~covarianceBase(){
delete[] randParams;
delete[] corr_throw;

if (covMatrix != NULL) delete covMatrix;
if (invCovMatrix != NULL) delete invCovMatrix;
if (throwMatrix_CholDecomp != NULL) delete throwMatrix_CholDecomp;
if (covMatrix != nullptr) delete covMatrix;
if (invCovMatrix != nullptr) delete invCovMatrix;
if (throwMatrix_CholDecomp != nullptr) delete throwMatrix_CholDecomp;

for(int i = 0; i < _fNumPar; i++)
{
Expand All @@ -63,7 +63,7 @@ covarianceBase::~covarianceBase(){
const int nThreads = MaCh3Utils::GetNThreads();
for (int iThread = 0;iThread < nThreads; iThread++) delete random_number[iThread];
delete[] random_number;
if (throwMatrix != NULL) delete throwMatrix;
if (throwMatrix != nullptr) delete throwMatrix;
}

// ********************************************
Expand Down Expand Up @@ -118,7 +118,7 @@ void covarianceBase::init(const char *name, const char *file) {

// Should put in a
TMatrixDSym *CovMat = (TMatrixDSym*)(infile->Get(name));
if (CovMat == NULL) {
if (CovMat == nullptr) {
MACH3LOG_ERROR("Could not find covariance matrix name {} in file {}", name, file);
MACH3LOG_ERROR("Are you really sure {} exists in the file?", name);
throw MaCh3Exception(__FILE__ , __LINE__ );
Expand Down Expand Up @@ -349,7 +349,7 @@ void covarianceBase::init(TMatrixDSym* covMat) {
// Set the covariance matrix for this class
void covarianceBase::setCovMatrix(TMatrixDSym *cov) {
// ********************************************
if (cov == NULL) {
if (cov == nullptr) {
MACH3LOG_ERROR("Could not find covariance matrix you provided to setCovMatrix");
throw MaCh3Exception(__FILE__ , __LINE__ );
}
Expand Down Expand Up @@ -1149,7 +1149,7 @@ void covarianceBase::resetIndivStepScale() {
// HW: Code for throwing from separate throw matrix, needs to be set after init to ensure pos-def
void covarianceBase::setThrowMatrix(TMatrixDSym *cov){
// ********************************************
if (cov == NULL) {
if (cov == nullptr) {
MACH3LOG_ERROR("Could not find covariance matrix you provided to setThrowMatrix");
throw MaCh3Exception(__FILE__ , __LINE__ );
}
Expand Down Expand Up @@ -1192,9 +1192,9 @@ void covarianceBase::setThrowMatrix(TMatrixDSym *cov){
void covarianceBase::updateThrowMatrix(TMatrixDSym *cov){
// ********************************************
delete throwMatrix;
throwMatrix = NULL;
throwMatrix = nullptr;
delete throwMatrix_CholDecomp;
throwMatrix_CholDecomp = NULL;
throwMatrix_CholDecomp = nullptr;
setThrowMatrix(cov);
}

Expand Down
7 changes: 3 additions & 4 deletions mcmc/FitterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ FitterBase::~FitterBase() {
clock = nullptr;
if(stepClock != nullptr) delete stepClock;
stepClock = nullptr;
MACH3LOG_INFO("Closing MaCh3 Fitter Engine");
MACH3LOG_DEBUG("Closing MaCh3 Fitter Engine");
}


// *******************
// Prepare the output tree
void FitterBase::SaveSettings() {
Expand Down Expand Up @@ -1134,8 +1133,8 @@ void FitterBase::RunSigmaVar() {
TH1D ***sigmaArray_y_norm = new TH1D**[numVar]();

// Set up for single mode
TH1D ****sigmaArray_mode_x = NULL;
TH1D ****sigmaArray_mode_y = NULL;
TH1D ****sigmaArray_mode_x = nullptr;
TH1D ****sigmaArray_mode_y = nullptr;
if (DoByMode)
{
sigmaArray_mode_x = new TH1D***[numVar]();
Expand Down
Loading

0 comments on commit 42d2582

Please sign in to comment.