Skip to content

Commit

Permalink
Merge pull request #433 from gundam-organization/feature/janitorial
Browse files Browse the repository at this point in the history
Ordering json entries + janitorial with new compiler warnings
  • Loading branch information
nadrino authored Dec 21, 2023
2 parents 4a68e12 + f7af3ec commit 8494aca
Show file tree
Hide file tree
Showing 54 changed files with 209 additions and 323 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ FROM rootproject/root as base

SHELL ["/bin/bash", "-c"]

RUN apt-get update
RUN apt-get install -y \
git libyaml-cpp-dev nlohmann-json3-dev

Expand Down
6 changes: 0 additions & 6 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,7 @@ execute_process(COMMAND root-config --has-cxx20 COMMAND grep yes
OUTPUT_VARIABLE ROOT_cxx20_FOUND
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (NOT ROOT_minuit2_FOUND)
cmessage( STATUS "[ROOT]:Rebuild root using -Dminuit2=on in the cmake command")
cmessage(FATAL_ERROR "[ROOT]: minuit2 is required")
endif(NOT ROOT_minuit2_FOUND)

include_directories( ${ROOT_INCLUDE_DIR} )
link_libraries( ${ROOT_LIBRARIES} )


####################
Expand Down
2 changes: 1 addition & 1 deletion src/Applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if( WITH_GUNDAM_ROOT_APP )
)
#target_compile_features(GundamRootDict PRIVATE cxx_std_17)

target_link_libraries( GundamRootDict ${ROOT_LIBRARIES} )
target_link_libraries( GundamRootDict PRIVATE ${ROOT_LIBRARIES} )
install(TARGETS GundamRootDict DESTINATION lib)

# Also need to install dict files
Expand Down
20 changes: 10 additions & 10 deletions src/Applications/src/gundamCalcXsec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int main(int argc, char** argv){
// Reading fitter file
std::string fitterFile{clParser.getOptionVal<std::string>("fitterFile")};
std::unique_ptr<TFile> fitterRootFile{nullptr};
nlohmann::json fitterConfig; // will be used to load the propagator
JsonType fitterConfig; // will be used to load the propagator

if( GenericToolbox::doesFilePathHasExtension(fitterFile, "root") ){
LogWarning << "Opening fitter output file: " << fitterFile << std::endl;
Expand Down Expand Up @@ -123,13 +123,13 @@ int main(int argc, char** argv){
);

// Defining signal samples
nlohmann::json xsecConfig{ ConfigUtils::readConfigFile( clParser.getOptionVal<std::string>("configFile") ) };
JsonType xsecConfig{ ConfigUtils::readConfigFile( clParser.getOptionVal<std::string>("configFile") ) };
cHandler.override( xsecConfig );
LogInfo << "Override done." << std::endl;


LogInfo << "Fetching propagator config into fitter config..." << std::endl;
auto configPropagator = GenericToolbox::Json::fetchValuePath<nlohmann::json>( cHandler.getConfig(), "fitterEngineConfig/propagatorConfig" );
auto configPropagator = GenericToolbox::Json::fetchValuePath<JsonType>( cHandler.getConfig(), "fitterEngineConfig/propagatorConfig" );

// Create a propagator object
Propagator propagator;
Expand Down Expand Up @@ -269,7 +269,7 @@ int main(int argc, char** argv){
LogInfo << "Creating normalizer objects..." << std::endl;
// flux renorm with toys
struct ParSetNormaliser{
void readConfig(const nlohmann::json& config_){
void readConfig(const JsonType& config_){
LogScopeIndent;

name = GenericToolbox::Json::fetchValue<std::string>(config_, "name");
Expand All @@ -281,7 +281,7 @@ int main(int argc, char** argv){
axisVariable = GenericToolbox::Json::fetchValue<std::string>(config_, "axisVariable");

// optionals
for( auto& parSelConfig : GenericToolbox::Json::fetchValue<nlohmann::json>(config_, "parSelections") ){
for( auto& parSelConfig : GenericToolbox::Json::fetchValue<JsonType>(config_, "parSelections") ){
parSelections.emplace_back();
parSelections.back().first = GenericToolbox::Json::fetchValue<std::string>(parSelConfig, "name");
parSelections.back().second = GenericToolbox::Json::fetchValue<double>(parSelConfig, "value");
Expand Down Expand Up @@ -373,7 +373,7 @@ int main(int argc, char** argv){
std::vector<ParSetNormaliser> parSetNormList;
for( auto& parSet : propagator.getParametersManager().getParameterSetsList() ){
if( GenericToolbox::Json::doKeyExist(parSet.getConfig(), "normalisations") ){
for( auto& parSetNormConfig : GenericToolbox::Json::fetchValue<nlohmann::json>(parSet.getConfig(), "normalisations") ){
for( auto& parSetNormConfig : GenericToolbox::Json::fetchValue<JsonType>(parSet.getConfig(), "normalisations") ){
parSetNormList.emplace_back();
parSetNormList.back().readConfig( parSetNormConfig );

Expand All @@ -393,7 +393,7 @@ int main(int argc, char** argv){

// to be filled up
struct BinNormaliser{
void readConfig(const nlohmann::json& config_){
void readConfig(const JsonType& config_){
LogScopeIndent;

name = GenericToolbox::Json::fetchValue<std::string>(config_, "name");
Expand Down Expand Up @@ -435,7 +435,7 @@ int main(int argc, char** argv){

struct CrossSectionData{
Sample* samplePtr{nullptr};
nlohmann::json config{};
JsonType config{};
GenericToolbox::RawDataArray branchBinsData{};

TH1D histogram{};
Expand Down Expand Up @@ -473,7 +473,7 @@ int main(int argc, char** argv){
GenericToolbox::joinVectorString(leafNameList, ":").c_str()
);

auto normConfigList = GenericToolbox::Json::fetchValue( xsecEntry.config, "normaliseParameterList", nlohmann::json() );
auto normConfigList = GenericToolbox::Json::fetchValue( xsecEntry.config, "normaliseParameterList", JsonType() );
xsecEntry.normList.reserve( normConfigList.size() );
for( auto& normConfig : normConfigList ){
xsecEntry.normList.emplace_back();
Expand Down Expand Up @@ -508,7 +508,7 @@ int main(int argc, char** argv){

bool enableEventMcThrow{true};
bool enableStatThrowInToys{true};
auto xsecCalcConfig = GenericToolbox::Json::fetchValue( cHandler.getConfig(), "xsecCalcConfig", nlohmann::json() );
auto xsecCalcConfig = GenericToolbox::Json::fetchValue( cHandler.getConfig(), "xsecCalcConfig", JsonType() );
enableStatThrowInToys = GenericToolbox::Json::fetchValue( xsecCalcConfig, "enableStatThrowInToys", enableStatThrowInToys);
enableEventMcThrow = GenericToolbox::Json::fetchValue( xsecCalcConfig, "enableEventMcThrow", enableEventMcThrow);

Expand Down
13 changes: 6 additions & 7 deletions src/Applications/src/gundamConfigCompare.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "GenericToolbox.Json.h"

#include "nlohmann/json.hpp"
#include "TNamed.h"

#include <string>
#include <vector>
Expand All @@ -27,7 +26,7 @@ LoggerInit([]{

CmdLineParser clp{};

void compareConfigStage(const nlohmann::json& config1_, const nlohmann::json& config2_);
void compareConfigStage(const JsonType& config1_, const JsonType& config2_);


int main( int argc, char** argv ){
Expand Down Expand Up @@ -99,13 +98,13 @@ int main( int argc, char** argv ){
}


void compareConfigStage(const nlohmann::json& config1_, const nlohmann::json& config2_){
void compareConfigStage(const JsonType& config1_, const JsonType& config2_){


std::vector<std::string> pathBuffer;

std::function<void(const nlohmann::json&, const nlohmann::json&)> recursiveFct =
[&](const nlohmann::json& entry1_, const nlohmann::json& entry2_){
std::function<void(const JsonType&, const JsonType&)> recursiveFct =
[&](const JsonType& entry1_, const JsonType& entry2_){
std::string path = GenericToolbox::joinVectorString(pathBuffer, "/");

if( entry1_.is_array() and entry2_.is_array() ){
Expand Down Expand Up @@ -180,8 +179,8 @@ void compareConfigStage(const nlohmann::json& config1_, const nlohmann::json& co
}

// both have the key:
auto content1 = GenericToolbox::Json::fetchValue<nlohmann::json>(entry1_, key);
auto content2 = GenericToolbox::Json::fetchValue<nlohmann::json>(entry2_, key);
auto content1 = GenericToolbox::Json::fetchValue<JsonType>(entry1_, key);
auto content2 = GenericToolbox::Json::fetchValue<JsonType>(entry2_, key);

pathBuffer.emplace_back(key);
recursiveFct(content1, content2);
Expand Down
2 changes: 1 addition & 1 deletion src/Applications/src/gundamInputZipper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main(int argc, char** argv) {
LogInfo << "Now copying input src files..." << std::endl;
std::string pathBuffer;
std::vector<std::string> recursivePathBufferList;
std::function<void(nlohmann::json&)> recursive = [&](nlohmann::json& config_){
std::function<void(JsonType&)> recursive = [&](JsonType& config_){

if( config_.is_string() ){
std::string srcPath = GenericToolbox::expandEnvironmentVariables(config_.get<std::string>());
Expand Down
7 changes: 2 additions & 5 deletions src/CacheManager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ endif()
target_include_directories( GundamCache PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)

target_link_libraries( GundamCache PUBLIC
GundamDialDictionary
GundamParametersManager
GundamSamplesManager
${ROOT_LIBRARIES}
target_link_libraries( GundamCache
PUBLIC GundamDialDictionary GundamParametersManager GundamSamplesManager
)

# set_target_properties(GundamCache PROPERTIES VERSION "${GUNDAM_VERSION_STRING}")
Expand Down
5 changes: 1 addition & 4 deletions src/DatasetManager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ target_include_directories(${LIB_NAME} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include)

target_link_libraries( ${LIB_NAME}
GundamParametersManager
GundamSamplesManager
GundamDialDictionary
${ROOT_LIBRARIES}
PUBLIC GundamParametersManager GundamSamplesManager GundamDialDictionary
)

#set_target_properties(${LIB_NAME} PROPERTIES VERSION "${GUNDAM_VERSION_STRING}")
Expand Down
2 changes: 1 addition & 1 deletion src/DatasetManager/include/DataDispenserUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct DataDispenserParameters{
int iThrow{-1};
size_t debugNbMaxEventsToLoad{0};

nlohmann::json fromHistContent{};
JsonType fromHistContent{};

[[nodiscard]] std::string getSummary() const;
};
Expand Down
2 changes: 1 addition & 1 deletion src/DatasetManager/include/DatasetLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DatasetLoader : public JsonBaseClass {
void initializeImpl() override;

public:
explicit DatasetLoader(const nlohmann::json& config_, int datasetIndex_): _dataSetIndex_(datasetIndex_) { this->readConfig(config_); }
explicit DatasetLoader(const JsonType& config_, int datasetIndex_): _dataSetIndex_(datasetIndex_) { this->readConfig(config_); }

void setDataSetIndex(int dataSetIndex){ _dataSetIndex_ = dataSetIndex; }
void setSelectedDataEntry(const std::string &selectedDataEntry){ _selectedDataEntry_ = selectedDataEntry; }
Expand Down
2 changes: 1 addition & 1 deletion src/DatasetManager/include/EventTreeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <vector>
#include <string>

class EventTreeWriter : public GenericToolbox::ConfigBaseClass<nlohmann::json> {
class EventTreeWriter : public GenericToolbox::ConfigBaseClass<JsonType> {

public:
EventTreeWriter() = default;
Expand Down
16 changes: 8 additions & 8 deletions src/DatasetManager/include/EventVarTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class EventVarTransform : public JsonBaseClass {

public:
EventVarTransform() = default;
explicit EventVarTransform(const nlohmann::json& config_);
explicit EventVarTransform(const JsonType& config_);

void setIndex(int index_);
void setUseCache(bool useCache_);
void setIndex(int index_){ _index_ = index_; }
void setUseCache(bool useCache_){ _useCache_ = useCache_; }

int getIndex() const;
bool useCache() const;
const std::string &getTitle() const;
const std::string &getOutputVariableName() const;
int getIndex() const { return _index_; }
bool useCache() const { return _useCache_; }
const std::string &getName() const { return _name_; }
const std::string &getOutputVariableName() const { return _outputVariableName_; }
const std::vector<std::string>& fetchRequestedVars() const;

double eval(const PhysicsEvent& event_);
Expand All @@ -44,7 +44,7 @@ class EventVarTransform : public JsonBaseClass {
virtual double evalTransformation(const PhysicsEvent& event_, std::vector<double>& inputBuffer_) const;

// config
std::string _title_;
std::string _name_;
std::string _messageOnError_;
std::string _outputVariableName_;
std::vector<std::string> _inputFormulaStrList_;
Expand Down
5 changes: 2 additions & 3 deletions src/DatasetManager/include/EventVarTransformLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

#include "EventVarTransform.h"

class EventVarTransformLib : public EventVarTransform{
class EventVarTransformLib : public EventVarTransform {

public:
EventVarTransformLib() = default;
explicit EventVarTransformLib(const nlohmann::json& config_){ this->readConfig(config_); }
explicit EventVarTransformLib(const JsonType& config_){ this->readConfig(config_); }

void reload();

Expand All @@ -22,7 +22,6 @@ class EventVarTransformLib : public EventVarTransform{
void loadLibrary();
void initInputFormulas();


double evalTransformation(const PhysicsEvent& event_, std::vector<double>& inputBuffer_) const override;

private:
Expand Down
14 changes: 7 additions & 7 deletions src/DatasetManager/src/DataDispenser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void DataDispenser::readConfigImpl(){
if( GenericToolbox::Json::doKeyExist( _config_, "fromHistContent" ) ) {
LogWarning << "Dataset \"" << _parameters_.name << "\" will be defined with histogram data." << std::endl;

_parameters_.fromHistContent = GenericToolbox::Json::fetchValue<nlohmann::json>( _config_, "fromHistContent" );
_parameters_.fromHistContent = GenericToolbox::Json::fetchValue<JsonType>( _config_, "fromHistContent" );
ConfigUtils::forwardConfig( _parameters_.fromHistContent );
return;
}
Expand All @@ -60,7 +60,7 @@ void DataDispenser::readConfigImpl(){
_parameters_.debugNbMaxEventsToLoad = GenericToolbox::Json::fetchValue(_config_, "debugNbMaxEventsToLoad", _parameters_.debugNbMaxEventsToLoad);

_parameters_.variableDict.clear();
for( auto& entry : GenericToolbox::Json::fetchValue(_config_, {{"variableDict"}, {"overrideLeafDict"}}, nlohmann::json()) ){
for( auto& entry : GenericToolbox::Json::fetchValue(_config_, {{"variableDict"}, {"overrideLeafDict"}}, JsonType()) ){
auto varName = GenericToolbox::Json::fetchValue<std::string>(entry, {{"name"}, {"eventVar"}});
auto varExpr = GenericToolbox::Json::fetchValue<std::string>(entry, {{"expr"}, {"expression"}, {"leafVar"}});
_parameters_.variableDict[ varName ] = varExpr;
Expand Down Expand Up @@ -174,7 +174,7 @@ void DataDispenser::parseStringParameters() {
if( GenericToolbox::Json::doKeyExist(_config_, "variablesTransform") ){
// load transformations
int index{0};
for( auto& varTransform : GenericToolbox::Json::fetchValue<std::vector<nlohmann::json>>(_config_, "variablesTransform") ){
for( auto& varTransform : GenericToolbox::Json::fetchValue<std::vector<JsonType>>(_config_, "variablesTransform") ){
_cache_.eventVarTransformList.emplace_back( varTransform );
_cache_.eventVarTransformList.back().setIndex(index++);
_cache_.eventVarTransformList.back().initialize();
Expand Down Expand Up @@ -599,7 +599,7 @@ void DataDispenser::loadFromHistContent(){
LogThrowIf(fHist == nullptr, "Could not open file: " << filePath);

LogThrowIf( not GenericToolbox::Json::doKeyExist(_parameters_.fromHistContent, "sampleList"), "Could not find samplesList." );
auto sampleList = GenericToolbox::Json::fetchValue<nlohmann::json>(_parameters_.fromHistContent, "sampleList");
auto sampleList = GenericToolbox::Json::fetchValue<JsonType>(_parameters_.fromHistContent, "sampleList");
for( auto& sample : _cache_.samplesToFillList ){
LogScopeIndent;

Expand Down Expand Up @@ -878,14 +878,14 @@ void DataDispenser::fillFunction(int iThread_){
LogInfo << "EventVarTransformLib used for indexing: "
<< GenericToolbox::iterableToString(
varTransformForIndexingList,
[](const EventVarTransformLib* elm_){ return "\"" + elm_->getTitle() + "\"";}, false)
[](const EventVarTransformLib* elm_){ return "\"" + elm_->getName() + "\"";}, false)
<< std::endl;
}
if( not varTransformForStorageList.empty() ){
LogInfo << "EventVarTransformLib used for storage: "
<< GenericToolbox::iterableToString(
varTransformForStorageList,
[]( const EventVarTransformLib* elm_){ return "\"" + elm_->getTitle() + "\""; }, false)
[]( const EventVarTransformLib* elm_){ return "\"" + elm_->getName() + "\""; }, false)
<< std::endl;
}
}
Expand Down Expand Up @@ -931,7 +931,7 @@ void DataDispenser::fillFunction(int iThread_){
std::vector<std::string> transformsList;
for( auto* varTransformForIndexing : varTransformForIndexingList ){
if( varTransformForIndexing->getOutputVariableName() == var ){
transformsList.emplace_back(varTransformForIndexing->getTitle());
transformsList.emplace_back(varTransformForIndexing->getName());
}
}
table << GenericToolbox::parseVectorAsString(transformsList) << GenericToolbox::TablePrinter::NextColumn;
Expand Down
4 changes: 2 additions & 2 deletions src/DatasetManager/src/DatasetLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ void DatasetLoader::readConfigImpl() {
_showSelectedEventCount_ = GenericToolbox::Json::fetchValue(_config_, "showSelectedEventCount", _showSelectedEventCount_);

_mcDispenser_ = DataDispenser(this);
_mcDispenser_.readConfig(GenericToolbox::Json::fetchValue<nlohmann::json>(_config_, "mc"));
_mcDispenser_.readConfig(GenericToolbox::Json::fetchValue<JsonType>(_config_, "mc"));
_mcDispenser_.getParameters().name = "Asimov";
_mcDispenser_.getParameters().useMcContainer = true;

// Always loaded by default
_dataDispenserDict_.emplace("Asimov", DataDispenser(_mcDispenser_));

for( auto& dataEntry : GenericToolbox::Json::fetchValue(_config_, "data", nlohmann::json()) ){
for( auto& dataEntry : GenericToolbox::Json::fetchValue(_config_, "data", JsonType()) ){
std::string name = GenericToolbox::Json::fetchValue(dataEntry, "name", "data");
LogThrowIf( GenericToolbox::doesKeyIsInMap(name, _dataDispenserDict_),
"\"" << name << "\" already taken, please use another name." )
Expand Down
14 changes: 3 additions & 11 deletions src/DatasetManager/src/EventVarTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,18 @@ LoggerInit([]{
});

void EventVarTransform::readConfigImpl(){
_title_ = GenericToolbox::Json::fetchValue(_config_, "title", _title_);
_name_ = GenericToolbox::Json::fetchValue(_config_, {{"name"}, {"title"}}, _name_);
_messageOnError_ = GenericToolbox::Json::fetchValue(_config_, "messageOnError", _messageOnError_);
_outputVariableName_ = GenericToolbox::Json::fetchValue(_config_, "outputVariableName", _outputVariableName_);
_inputFormulaStrList_ = GenericToolbox::Json::fetchValue(_config_, "inputList", _inputFormulaStrList_);
}
void EventVarTransform::initializeImpl(){
LogInfo << "Loading variable transformation: " << _title_ << std::endl;
LogInfo << "Loading variable transformation: " << _name_ << std::endl;
LogThrowIf(_outputVariableName_.empty(), "output variable name not set.");
}


EventVarTransform::EventVarTransform(const nlohmann::json& config_){ this->readConfig(config_); }

void EventVarTransform::setIndex(int index_){ _index_ = index_; }
void EventVarTransform::setUseCache(bool useCache_) { _useCache_ = useCache_; }

int EventVarTransform::getIndex() const { return _index_; }
bool EventVarTransform::useCache() const { return _useCache_; }
const std::string &EventVarTransform::getTitle() const { return _title_; }
const std::string &EventVarTransform::getOutputVariableName() const { return _outputVariableName_; }
EventVarTransform::EventVarTransform(const JsonType& config_){ this->readConfig(config_); }

const std::vector<std::string>& EventVarTransform::fetchRequestedVars() const {
if( _requestedLeavesForEvalCache_.empty() ){
Expand Down
2 changes: 1 addition & 1 deletion src/DatasetManager/src/EventVarTransformLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void EventVarTransformLib::readConfigImpl(){
_libraryFile_ = GenericToolbox::Json::fetchValue(_config_, "libraryFile", _libraryFile_);
}
void EventVarTransformLib::initializeImpl(){
LogInfo << "Loading variable transformation: " << _title_ << std::endl;
LogInfo << "Loading variable transformation: " << _name_ << std::endl;
LogThrowIf(_outputVariableName_.empty(), "output variable name not set.");

this->reload();
Expand Down
Loading

0 comments on commit 8494aca

Please sign in to comment.