Commit 177583f6 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

initialisation du dépôt

parent 08eb3e57
#ifndef AMLTOOLS_SEEN
#define AMLTOOLS_SEEN
#include <iostream>
#include <string>
#include "UAP/UAPNode.hpp"
using namespace std;
class AMLtools
{
public:
static bool readAMLParameterAttribut(UAPNode* parametersNode, string parameterName, string attributName, double& resultat) {
if ( !parametersNode ) return false;
UAPNode* parametre = parametersNode->getChildByName(parameterName);
if ( !parametre ) return false;
UAPAttribute* att = parametre->getAttribute(attributName);
if ( att ) {
att->getDouble( resultat);
return true;
} else return false;
}
static bool readAMLParameterAttribut(UAPNode* parametersNode, string parameterName, string attributName, int& resultat) {
if ( !parametersNode ) return false;
UAPNode* parametre = parametersNode->getChildByName(parameterName);
if ( !parametre ) return false;
UAPAttribute* att = parametre->getAttribute(attributName);
if ( att ) {
att->getInt( resultat);
return true;
} else return false;
}
static bool readAMLParameterAttribut(UAPNode* parametersNode, string parameterName, string attributName, string& resultat)
{
if ( !parametersNode ) return false;
UAPNode* parametre = parametersNode->getChildByName(parameterName);
if ( !parametre ) return false;
UAPAttribute* att = parametre->getAttribute(attributName);
if ( att ) {
resultat = att->getValue();
return true;
} else
return false;
}
static NodeVecIter find(NodeVecIter first,NodeVecIter last, const Str& val)
{
while(first != last) {
if( (*first)->getAttributeString("name") == val ) {
return first;
}
++first;
}
return last;
}
};
#endif
// Read an INI file into easy-to-access name/value pairs.
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
// Go to the project home page for more info:
//
// https://github.com/benhoyt/inih
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include "ini.h"
#include "INIReader.h"
using std::string;
INIReader::INIReader(const string& filename)
{
_error = ini_parse(filename.c_str(), ValueHandler, this);
}
int INIReader::ParseError() const
{
return _error;
}
string INIReader::Get(const string& section, const string& name, const string& default_value) const
{
string key = MakeKey(section, name);
// Use _values.find() here instead of _values.at() to support pre C++11 compilers
return _values.count(key) ? _values.find(key)->second : default_value;
}
long INIReader::GetInteger(const string& section, const string& name, long default_value) const
{
string valstr = Get(section, name, "");
const char* value = valstr.c_str();
char* end;
// This parses "1234" (decimal) and also "0x4D2" (hex)
long n = strtol(value, &end, 0);
return end > value ? n : default_value;
}
double INIReader::GetReal(const string& section, const string& name, double default_value) const
{
string valstr = Get(section, name, "");
const char* value = valstr.c_str();
char* end;
double n = strtod(value, &end);
return end > value ? n : default_value;
}
bool INIReader::GetBoolean(const string& section, const string& name, bool default_value) const
{
string valstr = Get(section, name, "");
// Convert to lower case to make string comparisons case-insensitive
std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower);
if (valstr == "true" || valstr == "yes" || valstr == "on" || valstr == "1")
return true;
else if (valstr == "false" || valstr == "no" || valstr == "off" || valstr == "0")
return false;
else
return default_value;
}
string INIReader::MakeKey(const string& section, const string& name)
{
string key = section + "=" + name;
// Convert to lower case to make section/name lookups case-insensitive
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return key;
}
int INIReader::ValueHandler(void* user, const char* section, const char* name,
const char* value)
{
INIReader* reader = (INIReader*)user;
string key = MakeKey(section, name);
if (reader->_values[key].size() > 0)
reader->_values[key] += "\n";
reader->_values[key] += value;
return 1;
}
// Read an INI file into easy-to-access name/value pairs.
// inih and INIReader are released under the New BSD license (see LICENSE.txt).
// Go to the project home page for more info:
//
// https://github.com/benhoyt/inih
#ifndef __INIREADER_H__
#define __INIREADER_H__
#include <map>
#include <string>
// Read an INI file into easy-to-access name/value pairs. (Note that I've gone
// for simplicity here rather than speed, but it should be pretty decent.)
class INIReader
{
public:
// Construct INIReader and parse given filename. See ini.h for more info
// about the parsing.
INIReader(const std::string& filename);
// Return the result of ini_parse(), i.e., 0 on success, line number of
// first error on parse error, or -1 on file open error.
int ParseError() const;
// Get a string value from INI file, returning default_value if not found.
std::string Get(const std::string& section, const std::string& name,
const std::string& default_value) const;
// Get an integer (long) value from INI file, returning default_value if
// not found or not a valid integer (decimal "1234", "-1234", or hex "0x4d2").
long GetInteger(const std::string& section, const std::string& name, long default_value) const;
// Get a real (floating point double) value from INI file, returning
// default_value if not found or not a valid floating point value
// according to strtod().
double GetReal(const std::string& section, const std::string& name, double default_value) const;
// Get a boolean value from INI file, returning default_value if not found or if
// not a valid true/false value. Valid true values are "true", "yes", "on", "1",
// and valid false values are "false", "no", "off", "0" (not case sensitive).
bool GetBoolean(const std::string& section, const std::string& name, bool default_value) const;
private:
int _error;
std::map<std::string, std::string> _values;
static std::string MakeKey(const std::string& section, const std::string& name);
static int ValueHandler(void* user, const char* section, const char* name,
const char* value);
};
#endif // __INIREADER_H__
#ifndef PHYSICALCONSTANTS_SEEN
#define PHYSICALCONSTANTS_SEEN
#define ZGRAND 1.0e8
#define ZDISTCATH 1. // cm ! distance maximale à la cathode (supposee en z=0) pour
// prendre en compte la charge image, dans la charge d'espace
#define ELECTRONCHARGE 1.60217653e-19
#define ELECTRONANOCOULOMB 1.60217653e-10
#define ELECTRONRADIUS 2.817940325e-13 // cm!
#define EREST_MeV 0.510998918
#define EREST_keV 0.510998918e+03
#define EREST_eV 0.510998918e+06
#define CLIGHT_E8 2.99792458
#define CLIGHT_m_per_ns 0.299792458
// facteurs de conversion des champs electriques (donnes en MV/cm)
// et magnetiques ( donnes en gauss), en cm^(-1)
#define MVPcmToCMm1 1.956951306 // 1/ERESTMeV
#define GAUSSToCMm1 5.8667924224e-4 // 1.0e-4 * CLIGHT_E8 / ERESTMeV
#define TESLAToCMm1 5.8667924224 // CLIGHT_E8 / ERESTMeV
#endif
#include <iostream>
#include "abstractElement.h"
abstractElement::abstractElement()
{
setDefaultValues();
setElement();
}
abstractElement::abstractElement(const abstractElement& e)
{
setDefaultValues();
setParametersFromElement( e );
idElement_= e.idElement_;
length_ = e.length_;
}
abstractElement::~abstractElement()
{
if (parametersString_ != NULL) delete[] parametersString_;
}
void abstractElement::setDefaultValues()
{
defaultSpecificName_= string("XXYXXX");
defaultId_= string();
defaultLength_= 0.0;
}
void abstractElement::setElement()
{
nbParam_ = 2;
sectorPrefix_ = string();
componentName_= defaultSpecificName_;
idElement_= defaultId_;
length_ = defaultLength_;
}
string abstractElement::getLabel() const
{
return getFullName();
}
string abstractElement::getIdOfElement() const
{
return idElement_;
}
double abstractElement::getLengthOfElement() const
{
return length_;
}
UAPNode* abstractElement::setAMLelementHeader(UAPNode *nde)
{
UAPNode *ele= nde->addChild( "element" );
ele->addAttribute("name",getFullName());
ele->addChild("description")->addAttribute("type",genericName_);
return ele;
}
bool abstractElement::checkAMLelementGenericName(UAPNode *nde)
{
if ( !nde ) return false;
string name;
AMLtools::readAMLParameterAttribut(nde,"description","type",name);
if ( name != genericName_ ) {
cout << "abstractElement::checkAMLelementGenericName ERREUR d'element : " << name << " ? attendu : " << genericName_ << endl;
return false;
}
splitFullName( nde->getAttribute("name")->getValue() );
return true;
}
#ifndef ABSTRACTELEMENTDEFINITION_SEEN
#define ABSTRACTELEMENTDEFINITION_SEEN
#include <string>
#include <vector>
#include "sectorComponent.h"
#include "abstractSoftware.h"
#include "UAP/UAPNode.hpp"
#include "AMLtools.h"
using namespace std;
class abstractElement : public sectorComponent
{
protected :
string defaultId_;
string idElement_;
double defaultLength_;
double length_;
void setDefaultValues();
void setElement();
//void setParametersFromElement(const abstractElement&);
inline void setParametersFromElement( const abstractElement& e)
{
genericName_ = e.genericName_;
sectorPrefix_ = e.sectorPrefix_;
componentName_= e.componentName_;
nbParam_= e.nbParam_;
parametersString_= new string[nbParam_+1];
for (unsigned k = 0; k < nbParam_ + 1; k++ )
{
parametersString_[k] = e.parametersString_[k];
}
}
unsigned getElementNbParameters() const {return nbParam_;}
UAPNode* setAMLelementHeader(UAPNode*);
bool checkAMLelementGenericName(UAPNode*);
public :
abstractElement();
abstractElement(const abstractElement&);
virtual ~abstractElement();
virtual abstractElement* clone() const = 0;
virtual vector<psvs> parametersToSoftware() const = 0;
virtual string print() = 0;
virtual abstractElement* getAbstractElement() {
return this;
}
virtual sectorComponent* cloneComponent() const {
return this->clone();
}
virtual vector<abstractElement*> expandedElements() {
vector<abstractElement*> resul;
resul.push_back(this);
return resul;
}
virtual string getLabel() const;
string getIdOfElement() const;
double getLengthOfElement() const;
};
#endif
#include <iostream>
#include <algorithm>
#include "abstractSoftware.h"
#include "dataManager.h"
#include "INIReader.h"
abstractSoftware::abstractSoftware()
{
INIReader reader("../../pspa_config.ini");
debug = reader.GetInteger("Debugging", "debug_mode", -1);
dataManager_ = NULL;
nameOfSoftware_ = new nomDeLogiciel("unknown");
compBlock_ = NULL;
simulationId_= "none";
userDir_ = string();
}
abstractSoftware::abstractSoftware(computingBlock *cmpb, dataManager *data)
{
INIReader reader("../../pspa_config.ini");
debug = reader.GetInteger("Debugging", "debug_mode", -1);
dataManager_ = data;
nameOfSoftware_ = new nomDeLogiciel("unknown");
compBlock_ = cmpb;
simulationId_= cmpb->getId();
userDir_ = dataManager_->getUserDir();
}
abstractSoftware::~abstractSoftware()
{
delete nameOfSoftware_;
}
bool abstractSoftware::launchJob(string commandLine,string& resul)
{
if (debug > 0) cout << "abstractSoftware::launchJob()\n";
bool ExecuteStatus = true;
//string userDir = dataManager_->getUserDir();
commandLine = "cd " + userDir_ + " && " + commandLine;
FILE* pp = popen(commandLine.c_str(), "r");
ostringstream sortie;
if (pp == NULL) {
sortie << "abstractSoftware::launchJob failed : " << commandLine << endl;
ExecuteStatus = false;
} else {
// on copie la sortie dans le fichier assigne
char buf[132];
while (fgets(buf,sizeof buf,pp))
{
sortie << buf;
}
pclose(pp);
}
resul = sortie.str();
return ExecuteStatus;
}
computingBlock* abstractSoftware::getComputingBlock()
{
return compBlock_;;
}
const nomDeLogiciel* abstractSoftware::getNomDeLogiciel() const
{
return nameOfSoftware_;
}
string abstractSoftware::getName() const
{
return nameOfSoftware_->getString();
}
string abstractSoftware::getSimulationId() const
{
return simulationId_;
}
string abstractSoftware::getFileName(string s,bool YesNo)
{
string fname= simulationId_ + "-" + s + ".txt";
if( YesNo ) {
char ch1= '"';
string str1= string(&ch1,1);
fname= str1+fname+str1;
}
// return xxx-s.txt or "xxx-s.txt"
return fname;
}
#ifndef ABSTRACTSOFTWARE_SEEN
#define ABSTRACTSOFTWARE_SEEN
//#include "sectorParameters.h"
#include "particleBeam.h"
#include "nomDeLogiciel.h"
#include "trivaluedBool.h"
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace std;
typedef std::pair<std::string,std::vector<std::string> > psvs;
typedef std::map<std::string,std::vector<std::string> > smap;
class dataManager;
class sectionToExecute;
class computingBlock;
class abstractSoftware
{
protected :
int debug; // FOR DEBUGGING
dataManager* dataManager_;
nomDeLogiciel* nameOfSoftware_;
string simulationId_;
string userDir_;
abstractSoftware();
bool launchJob(string,string&);
computingBlock* getComputingBlock();
string getSimulationId() const;
string getFileName(string,bool);
public :
abstractSoftware(computingBlock*,dataManager*);
virtual ~abstractSoftware();
const nomDeLogiciel* getNomDeLogiciel() const;
string getName() const;
virtual bool createInputFile(particleBeam*) = 0;
virtual bool execute() = 0;
virtual bool buildBeamAfterElements() = 0;
virtual json readOpticalParameters() = 0;
virtual string plotting( int ) = 0;
/** Color of the background of this sofware
Should be a valid Css name as FFEEDD
*/
virtual string getColor() = 0;
private :
computingBlock* compBlock_;
};
#endif
#include "bareParticle.h"
bareParticle::bareParticle(const TRIDVECTOR& pos , const TRIDVECTOR& bg)
{
position_ = pos;
betagamma_ = bg;
gamma_ = sqrt( 1.0 + betagamma_.norm2() );
}
bareParticle::bareParticle(bareParticle& bp)
{
position_ = bp.position_;
betagamma_ = bp.betagamma_;
gamma_ = bp.gamma_;
}
bareParticle::bareParticle(const bareParticle& bp)
{
position_ = bp.position_;
betagamma_ = bp.betagamma_;
gamma_ = bp.gamma_;
}
void bareParticle::resetDynamics(const bareParticle& bp)
{
position_ = bp.position_;
betagamma_ = bp.betagamma_;
gamma_ = bp.gamma_;
}
bareParticle& bareParticle::operator = (const bareParticle& bp)
{
position_ = bp.position_;
betagamma_ = bp.betagamma_;
gamma_ = bp.gamma_;
return *this;
}
const TRIDVECTOR& bareParticle::getReferenceToPosition() const
{
return position_;
}
TRIDVECTOR bareParticle::getPosition() const
{
return position_;
}
TRIDVECTOR& bareParticle::getReferenceToPosition()
{
return position_;
}
double bareParticle::getZ() const