Commit 204c342e authored by Adrien Matta's avatar Adrien Matta
Browse files

* Adding Project base configuration

parent 5cc97866
Pipeline #117805 passed with stages
in 18 minutes and 48 seconds
......@@ -86,6 +86,7 @@ std::string NPL::InputBlock::ExtractValue(std::string line,std::string separator
void NPL::InputBlock::AddLine(std::string line){
m_Token.push_back(ToLower(StripSpaces(ExtractToken(line))));
m_Value.push_back(StripSpaces(ExtractValue(line)));
m_Lines.push_back(line);
}
////////////////////////////////////////////////////////////////////////////////
void NPL::InputBlock::Dump(){
......@@ -128,7 +129,7 @@ std::string NPL::InputBlock::GetValue(std::string Token){
}
////////////////////////////////////////////////////////////////////////////////
double NPL::InputBlock::GetDouble(std::string Token,std::string default_unit){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1; //NPOptionManager::getInstance()->GetVerboseLevel();
std::stringstream iss(GetValue(Token));
double val;
std::string unit;
......@@ -150,7 +151,7 @@ double NPL::InputBlock::GetDouble(std::string Token,std::string default_unit){
}
////////////////////////////////////////////////////////////////////////////////
int NPL::InputBlock::GetInt(std::string Token){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1;//NPOptionManager::getInstance()->GetVerboseLevel();
std::stringstream iss(GetValue(Token));
int val;
iss >> val ;
......@@ -164,7 +165,7 @@ int NPL::InputBlock::GetInt(std::string Token){
}
////////////////////////////////////////////////////////////////////////////////
std::string NPL::InputBlock::GetString(std::string Token){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1;//NPOptionManager::getInstance()->GetVerboseLevel();
if(verbose)
printf(" %s: %s\n",Token.c_str(),GetValue(Token).c_str());
// std::cout << " " << Token << ": " << GetValue(Token) << std::endl;
......@@ -173,7 +174,7 @@ std::string NPL::InputBlock::GetString(std::string Token){
}
////////////////////////////////////////////////////////////////////////////////
TVector3 NPL::InputBlock::GetTVector3(std::string Token,std::string default_unit){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1; //NPOptionManager::getInstance()->GetVerboseLevel();
std::stringstream iss(GetValue(Token));
double x,y,z;
......@@ -205,7 +206,7 @@ TVector3 NPL::InputBlock::GetTVector3(std::string Token,std::string default_uni
}
////////////////////////////////////////////////////////////////////////////////
std::vector<std::string> NPL::InputBlock::GetVectorString(std::string Token){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1 ; //NPOptionManager::getInstance()->GetVerboseLevel();
std::stringstream iss(GetValue(Token));
......@@ -231,7 +232,7 @@ std::vector<std::string> NPL::InputBlock::GetVectorString(std::string Token){
////////////////////////////////////////////////////////////////////////////////
std::vector<double> NPL::InputBlock::GetVectorDouble(std::string Token,std::string default_unit){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1 ; // NPOptionManager::getInstance()->GetVerboseLevel();
std::stringstream iss(GetValue(Token));
......@@ -271,7 +272,7 @@ std::vector<double> NPL::InputBlock::GetVectorDouble(std::string Token,std::stri
////////////////////////////////////////////////////////////////////////////////
std::vector<int> NPL::InputBlock::GetVectorInt(std::string Token){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1;// NPOptionManager::getInstance()->GetVerboseLevel();
std::stringstream iss(GetValue(Token));
std::vector<int> val;
......@@ -375,7 +376,7 @@ void NPL::InputParser::TreatAliases(){
NPL::SendErrorAndExit("NPL::InputParser", "Alias block syntax incorrect");
}
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
int verbose = 1; //NPOptionManager::getInstance()->GetVerboseLevel();
if(verbose)
std::cout << "Using Alias : @" << alias[i]->GetMainValue() << std::endl;
......
......@@ -53,6 +53,7 @@ namespace NPL{
std::string m_MainValue;
std::vector<std::string> m_Token;
std::vector<std::string> m_Value;
std::vector<std::string> m_Lines;
public:
void AddLine(std::string line);
......@@ -83,6 +84,7 @@ namespace NPL{
std::vector<int> GetVectorInt(std::string Token);
std::vector<std::string> GetVectorString(std::string Token);
std::vector<NPL::InputBlock*> GetSubBlock(std::string Token);
std::vector<std::string> GetLines(){return m_Lines;};
public:
void Dump();
......
......@@ -22,6 +22,7 @@
#include "NPOptionManager.h"
#include "NPLibVersion.h"
#include "NPInputParser.h"
#include <fstream>
#include <sstream>
#include <cstdlib>
......@@ -44,15 +45,51 @@ NPOptionManager* NPOptionManager::getInstance(std::string arg){
return instance ;
}
////////////////////////////////////////////////////////////////////////////////
void NPOptionManager::ReadProjectConfigFile(){
// check if the file exist
std::ifstream ProjectFile;
ProjectFile.open("./project.config");
if(ProjectFile.is_open()){
std::cout << "///// Loading Project Configuration: " << std::endl;
ProjectFile.close();
NPL::InputParser parser("./project.config");
std::vector<NPL::InputBlock*> blocks = parser.GetAllBlocksWithToken("Project");
unsigned int size = blocks.size();
for(unsigned int i = 0 ; i < size ; i++){
if(blocks[i]->HasToken("AnalysisOutput"))
m_AnalysisOutputPath = blocks[i]->GetString("AnalysisOutput");
if(blocks[i]->HasToken("SimulationOutput"))
m_SimulationOutputPath = blocks[i]->GetString("SimulationOutput");
if(blocks[i]->HasToken("EnergyLoss"))
m_EnergyLossPath = blocks[i]->GetString("EnergyLoss");
}
}
// else use the standard config
else{
std::string Path = getenv("NPTOOL");
m_AnalysisOutputPath=Path+"/Outputs/Analysis/";
m_SimulationOutputPath=Path+"/Outputs/Simulation/";
m_EnergyLossPath=Path+"/Inputs/EnergyLoss/";
}
}
////////////////////////////////////////////////////////////////////////////////
void NPOptionManager::ReadTheInputArgument(int argc, char** argv){
if(argc==1)
DisplayHelp();
// Default Setting
fDefaultReactionFileName = "defaultReaction.reaction";
fDefaultDetectorFileName = "defaultDetector.detector";
fDefaultOutputFileName = "myResult.root";
fDefaultOutputFileName = "SimulatedTree.root";
fDefaultOutputTreeName = "NPTool_Tree";
fDefaultRunToReadFileName = "defaultRunToTreat.txt";
fDefaultCalibrationFileName = "defaultCalibration.txt";
......@@ -211,6 +248,8 @@ void NPOptionManager::DisplayVersion(){
}
////////////////////////////////////////////////////////////////////////////////
NPOptionManager::NPOptionManager(int argc, char** argv){
// Start by reading the project configuration
ReadProjectConfigFile();
ReadTheInputArgument(argc,argv);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -60,7 +60,9 @@ class NPOptionManager{
private:
// Read the input argument
void ReadTheInputArgument(int argc = 0, char** argv = NULL);
// Look for and Read the project config file if existing
void ReadProjectConfigFile();
private:
// The static instance of the NPOptionManager class:
static NPOptionManager* instance;
......@@ -111,13 +113,16 @@ class NPOptionManager{
int GetRandomSeed() {return fRandomSeed;}
std::string GetSharedLibExtension() {return fSharedLibExtension;}
std::string GetLastFile();
std::string GetAnalysisOutputPath(){return m_AnalysisOutputPath;};
std::string GetSimulationOutputPath(){return m_SimulationOutputPath;};
std::string GetEnergyLossPath(){return m_EnergyLossPath;};
// Setters
void SetReactionFile(const std::string& name) {fReactionFileName = name;CheckEventGenerator();}
void SetDetectorFile(const std::string& name) {fDetectorFileName = name;CheckDetectorConfiguration();}
void SetRunToReadFile(const std::string& name) {fRunToReadFileName = name;}
void SetVerboseLevel(int VerboseLevel) {fVerboseLevel = VerboseLevel;}
public: // user definition
bool HasDefinition(std::string def) {return(fDefinition.find(def)!=fDefinition.end());}
......@@ -158,6 +163,10 @@ class NPOptionManager{
std::string fG4MacroPath; // Path to a geant4 macro to execute at start of nps
bool fG4BatchMode; // Execute geant4 in batch mode, running the given macro
std::set<std::string> fDefinition; // a set of user defined definition
std::string m_AnalysisOutputPath;// output path of analysed tree
std::string m_SimulationOutputPath;// output path of simulated tree
std::string m_EnergyLossPath;// input/output path of energy loss table
};
#endif
......@@ -53,12 +53,27 @@ void RootOutput::Destroy(){
RootOutput::RootOutput(std::string fileNameBase, std::string treeNameBase){
TDirectory* currentPath= gDirectory;
// The file extension is added to the file name:
std::string GlobalPath = getenv("NPTOOL");
bool analysis=false;
bool simulation=false;
if(fileNameBase.find("Analysis/")!=std::string::npos){
analysis = true;
fileNameBase.erase(0,8);
}
else if(fileNameBase.find("Simulation/")!=std::string::npos){
simulation= true;
fileNameBase.erase(0,10);
}
// The ROOT file is created
if(!NPOptionManager::getInstance()->GetPROOF()){
std::string fileName = GlobalPath + "/Outputs/";
std::string fileName;
if(analysis)
fileName = NPOptionManager::getInstance()->GetAnalysisOutputPath();
else if(simulation)
fileName = NPOptionManager::getInstance()->GetSimulationOutputPath();
else
fileName="./";
if (fileNameBase.find("root")!=std::string::npos) fileName += fileNameBase;
else fileName += fileNameBase + ".root";
......
......@@ -39,6 +39,7 @@
using namespace std;
#include "NPEnergyLoss.h"
#include "NPOptionManager.h"
#include "TAxis.h"
// NPL
......@@ -66,8 +67,7 @@ EnergyLoss::EnergyLoss(string Path , string Source, int NumberOfSlice=100 , int
fNumberOfSlice = NumberOfSlice ;
fNumberOfMass = NumberOfMass ;
string globalPath = getenv("NPTOOL");
string StandardPath = globalPath + "/Inputs/EnergyLoss/" + Path;
string StandardPath = NPOptionManager::getInstance()->GetEnergyLossPath()+"/"+Path;
cout << endl;
cout << "/////////// Energy loss ///////////" << endl ;
......
......@@ -20,6 +20,8 @@
* Comment: *
* *
*****************************************************************************/
//NPL
#include "NPOptionManager.h"
// NPS
#include "MaterialManager.hh"
......@@ -1209,12 +1211,12 @@ void MaterialManager::WriteDEDXTable(G4ParticleDefinition* Particle,
return;
for (it = m_Material.begin(); it != m_Material.end(); it++) {
// Opening hte output file
G4String GlobalPath = getenv("NPTOOL");
G4String GlobalPath =NPOptionManager::getInstance()->GetEnergyLossPath();
G4String Name = it->second->GetName();
// Remove NPS name
Name.erase(0, 4);
G4String Path = GlobalPath + "/Inputs/EnergyLoss/"
+ Particle->GetParticleName() + "_" + Name + ".G4table";
G4String Path = GlobalPath +"/"+ Particle->GetParticleName() + "_" + Name + ".G4table";
ofstream File;
File.open(Path);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment