Commit 58fd6992 authored by TOUZE Francois's avatar TOUZE Francois
Browse files

docker containers creation: step1

parent 04934a23
......@@ -2,15 +2,15 @@ package aml
macro aml_home "" \
Darwin "/Users/touze/Public/aml-uap.hg" \
Linux "/accelerator-ml-code"
Linux "/usr/local/accelerator-ml-code"
macro aml_cppflags "" \
Darwin " -I $(aml_home)" \
Linux " -I $(aml_home) -I/xerces-c-3.2.2/src/xercesc"
Linux " -I $(aml_home) -I/usr/local/include/xercesc"
macro aml_linkopts "" \
Darwin " -L${aml_home}/lib/ -lantlr -luap -L/usr/local/lib -lxerces-c"\
Linux " -L${aml_home}/lib/ -luap -lantlr -L/usr/local/lib -lxerces-c"
path_append DYLD_LIBRARY_PATH "/usr/local/lib"
path_append LD_LIBRARY_PATH "/usr/local/lib"
path_append LD_LIBRARY_PATH "/usr/local/lib"
package json
macro json_home "" \
Linux "/json" \
Linux "/usr/local/json" \
Darwin "/usr/local/Cellar/nlohmann_json/3.1.2"
macro json_cppflags "" \
Linux " -I/json/include" \
Linux " -I/usr/local/json/include" \
Darwin " -I/usr/local/include/nlohmann"
......@@ -22,3 +22,4 @@ application cppcode cppcode.cpp $(PSPAROOT)/src/Core/dataManager.cpp
macro_append ppal_dependencies " pspa "
path_append DYLD_LIBRARY_PATH "${PSPAROOT}/${CMTCONFIG}"
path_append LD_LIBRARY_PATH "${PSPAROOT}/${CMTCONFIG}"
how to wrap C++ with Cython.
Assuming you have Python, Cython, Git and a C++ compiler installed
$ python setup.py build_ext --inplace
#include <iostream>
#include "cppcode.h"
#include "componentFactory.h"
#include "elementBeam.h"
#include "elementBend.h"
#include "elementCathode.h"
#include "elementDrift.h"
#include "elementKicker.h"
#include "elementLinac.h"
#include "elementMarker.h"
#include "elementMpole.h"
#include "elementOpole.h"
#include "elementQpole.h"
#include "elementRfCavity.h"
#include "elementSolenoid.h"
#include "elementSpole.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
using namespace std;
pspa::pspa ()
{
nameOfCase_ = string();
dataManager_= NULL;
string userDir= string( getenv("PWD") );
string workingDir= string( getenv("PWD") );
dataManager_ = new dataManager(userDir,workingDir,nameOfCase_);
registerAllElements();
componentFactory::enregistrer( new sector( dataManager_ ) );
}
pspa::pspa (string basename)
{
nameOfCase_ = string();
string userDir= basename + "workZone/";
string workingDir= basename + "pspa.git/softwares/";
dataManager_ = new dataManager(userDir,workingDir,nameOfCase_);
registerAllElements();
componentFactory::enregistrer( new sector( dataManager_ ) );
}
pspa::pspa (string userDir,string workingDir)
{
nameOfCase_ = string();
dataManager_ = new dataManager(userDir,workingDir,nameOfCase_);
registerAllElements();
componentFactory::enregistrer( new sector( dataManager_ ) );
}
pspa::~pspa (void) {
//cout << "pspa destructor\n";
}
void pspa::splitter(string s)
{
nameOfCase_= s;
typeOfFile_= string();
string::size_type n1= nameOfCase_.rfind('.');
if ( n1 != string::npos ) {
typeOfFile_= nameOfCase_.substr( n1 );
string::size_type n2= nameOfCase_.length() - typeOfFile_.length();
nameOfCase_= nameOfCase_.substr(0, n2);
}
//cout << "splitter::nameOfCase : " << nameOfCase_ << endl;
//cout << "spiltter::typeOfFile : " << typeOfFile_ << endl;
}
string pspa::read(const char* argv)
{
//cout << "pspa read()\n";
string fileName( argv );
splitter( fileName );
dataManager_->setnameOfCase( nameOfCase_ );
bool status= true;
if( typeOfFile_ == ".aml" ) {
cout << "pspa::AML format input file\n";
status= dataManager_->parseAMLFile( fileName );
} else if( typeOfFile_ == ".madx" ) {
cout << "pspa::MAD-X format input file\n";
status= dataManager_->parseXFile( fileName );
} else if( typeOfFile_ == ".json" ) {
cout << "pspa::JSON format input file\n";
status= dataManager_->parseJSONFile( fileName );
} else if( typeOfFile_ == ".str" ) {
cout << "pspa::BETA format input file\n\n";
status = dataManager_->parseBETAFile( fileName );
} else {
cout << "pspa::Unknown file extension\n";
}
string s;
if (status) {
json j= dataManager_->toJSONFormat();
s= j.dump(-1, ' ', true);
}
return s;
}
bool pspa::execute(string obj)
{
if ( !dataManager_ ) return false;
auto j= json::parse( obj );
if (!dataManager_->fromSimulate( j )) {
cout << "dataManager::fromSimulate failed\n";
return false;
}
bool status= simulate();
if( status ) {
cout << "pspa::simulation: success\n";
dataManager_->settingPlot();
} else cout << "pspa::simulation: failure\n";
return status;
}
bool pspa::simulate()
{
bool coherent= dataManager_->areDataCoherent();
if( !coherent ) {
cout << "simulate:: error during the check of data consistency\n";
return false;
}
dataManager_->initializeExecution();
bool status= dataManager_->executeAll();
return status;
}
void pspa::setnameOfCase(string s)
{
if ( !dataManager_ ) return;
dataManager_->setnameOfCase( s );
}
void pspa::printCase (void)
{
cout << "nameOfCase is " << nameOfCase_ << endl;
}
void pspa::printJson (const char* obj)
{
cout << "json output is " << string( obj ) << '\n';
}
void pspa::registerAllElements()
{
componentFactory::enregistrer( new elementBeam() );
componentFactory::enregistrer( new elementBend() );
componentFactory::enregistrer( new elementCathode() );
componentFactory::enregistrer( new elementDrift() );
componentFactory::enregistrer( new elementKicker() );
componentFactory::enregistrer( new elementLinac() );
componentFactory::enregistrer( new elementMarker() );
componentFactory::enregistrer( new elementMpole() );
componentFactory::enregistrer( new elementOpole() );
componentFactory::enregistrer( new elementQpole() );
componentFactory::enregistrer( new elementRfCavity() );
componentFactory::enregistrer( new elementSolenoid() );
componentFactory::enregistrer( new elementSpole() );
}
#ifndef __CPPCODE_H__
#define __CPPCODE_H__
#include "dataManager.h"
class pspa
{
void registerAllElements();
void splitter( string );
dataManager *dataManager_;
string nameOfCase_;
string typeOfFile_;
public:
pspa ();
pspa ( string );
pspa ( string, string );
~pspa ();
string read( const char* );
bool simulate();
bool execute( string );
void setnameOfCase( string );
void printCase ( void );
void printJson ( const char* );
};
#endif //__CPPCODE_H__
from libcpp cimport bool
from libcpp.string cimport string
cdef extern from "pspaclass.cpp":
pass
# Declare the class with cdef
cdef extern from "pspaclass.h":
cdef cppclass pspa:
pspa () except +
pspa ( string ) except +
pspa ( string, string ) except +
string read ( const char* );
bool simulate ();
bool execute ( string );
void setnameOfCase ( string );
void printJson ( const char* )
void printCase ()
\ No newline at end of file
This diff is collapsed.
# distutils: language = c++
from pspaclass cimport pspa
from libcpp.string cimport string
cdef class PyPspaClass:
cdef pspa* c_rect # Hold a C++ instance which we're wrapping
def __cinit__(self):
self.c_rect = new pspa()
def __cinit__(self, string s) :
self.c_rect = new pspa( s )
def __cinit__(self, string s1, string s2) :
self.c_rect = new pspa( s1, s2 )
def __dealloc__(self):
del self.c_rect
def read(self, const char* file):
return self.c_rect.read( file )
def simulate(self):
return self.c_rect.simulate()
def execute(self, string s):
return self.c_rect.execute( s )
def setnameOfCase(self, string s):
return self.c_rect.setnameOfCase( s )
def printCase(self):
return self.c_rect.printCase()
def printJson(self, const char* j):
return self.c_rect.printJson( j )
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
xtension = Extension(
name="pypspaclass",
sources=["pypspaclass.pyx",
"/home/pspa/backend/pspa/v0/src/Core/dataManager.cpp"],
libraries=["pspa","uap","antlr","xerces-c"],
include_dirs=["/home/pspa/backend/pspa/v0/src/Core",
"/home/pspa/backend/pspa/v0/src/KindOfElements",
"/usr/local/accelerator-ml-code",
"/usr/local/json/include"],
library_dirs=["/home/pspa/backend/pspa/v0/Linux-x86_64",
"/usr/local/accelerator-ml-code/lib",
"/usr/local/lib"]
)
setup(
name="pypspaclass",
ext_modules=cythonize([xtension])
)
certifi==2018.4.16
chardet==3.0.4
click==6.7
Cython==0.28.3
Flask==1.0.2
Flask-Cors==3.0.4
idna==2.6
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
requests==2.18.4
six==1.11.0
urllib3==1.22
Werkzeug==0.14.1
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