source: PSPA/Interface_Web/trunk/pspaWT/sources/controler/src/elementBeam.cc @ 288

Last change on this file since 288 was 288, checked in by garnier, 11 years ago

ajout de tooltip et nettoyage de code

File size: 4.5 KB
Line 
1#include "elementBeam.h"
2#include "beam2Moments.h"
3#include "mixedTools.h"
4
5elementBeam::elementBeam() :  abstractElement() {
6    setDefaultValues();
7    setDefaults();
8    elementName_ = nomdElements("beam");
9    nbParam_ = elementName_.getElementNbParameters();
10    parametersString_ = new string[nbParam_+1];
11    //  transportOk_ = true;
12}
13
14elementBeam::~elementBeam() {;}
15
16void elementBeam::setDefaultValues() {
17    defaultLabel_ = "beam";
18    xDef_ = 0.0;
19    xpDef_ = 0.0;
20    yDef_ = 0.0;
21    ypDef_ = 0.0;
22    dlDef_ = 0.0;
23    delDef_ = 0.0;
24    p0Def_ = 0.0;
25}
26
27void elementBeam::setDefaults() {
28    label_ = defaultLabel_;
29    x_ = xDef_;
30    xp_ = xpDef_;
31    y_ = yDef_;
32    yp_ = ypDef_;
33    dl_ = dlDef_;
34    del_ = delDef_;
35    p0_ = p0Def_;
36}
37
38trivaluedBool elementBeam::is_accepted_by_software(nomDeLogiciel soft) const {
39    if ( soft == nomDeLogiciel::transport ) return ok;
40    else return error;
41}
42
43string* elementBeam::getParametersString() const {
44    int compteur = -1;
45    parametersString_[++compteur] = mixedTools::intToString(nbParam_);
46    parametersString_[++compteur] = label_;
47    parametersString_[++compteur] = mixedTools::doubleToString(x_);
48    parametersString_[++compteur] = mixedTools::doubleToString(xp_);
49    parametersString_[++compteur] = mixedTools::doubleToString(y_);
50    parametersString_[++compteur] = mixedTools::doubleToString(yp_);
51    parametersString_[++compteur] = mixedTools::doubleToString(dl_);
52    parametersString_[++compteur] = mixedTools::doubleToString(del_);
53    parametersString_[++compteur] = mixedTools::doubleToString(p0_);
54    if ( compteur != nbParam_ ) {
55        cerr << " elementBeam::getParametersString() : ERROR nr pf parameters doesnt match " << endl;
56        return NULL;
57    }
58    return parametersString_;
59}
60
61void elementBeam::setParametersString(string* param) {
62    if ( param == NULL )
63    {
64        cerr << "  elementBeam::setParametersString parameters empty parameter set";
65        return;
66    }
67    int compteur = -1;
68    int nbparam = atoi(param[++compteur].c_str());
69    if ( nbparam != nbParam_ )
70    {
71        cerr << "  elementBeam::setParametersString parameters do not match for a BEAM";
72        return;
73    }
74   
75    label_ = param[++compteur];
76    x_ = atof(param[++compteur].c_str());
77    xp_ = atof(param[++compteur].c_str());
78    y_ = atof(param[++compteur].c_str());
79    yp_ = atof(param[++compteur].c_str());
80    dl_ = atof(param[++compteur].c_str());
81    del_ = atof(param[++compteur].c_str());
82    p0_ = atof(param[++compteur].c_str());
83}
84
85string elementBeam::parmelaOutputFlow() const
86{
87    ostringstream sortie;
88    cout << " BEAM sortie parmela non programmee " << endl;
89    return sortie.str();
90}
91
92string elementBeam::transportOutputFlow() const {
93    ostringstream sortie;
94    beam2Moments moments(x_, xp_, y_, yp_, dl_, del_);
95    cout << " elementBeam::transportOutputFlow(), p0 = " << p0_ << endl;
96    sortie << label_ << ":" << moments.writeToTransportInput(p0_);
97    return sortie.str();
98}
99
100string elementBeam::FileOutputFlow() const {
101    ostringstream sortie;
102    // sortie << elementName_.getElementType() << endl;
103    sortie << elementName_.getElementLabel() << endl;
104    sortie  << label_ << endl;
105    sortie << x_ << "  " << xp_ << " " <<  y_  << " " <<  yp_  << endl;
106    sortie << dl_ << "  " << del_ << " " <<  p0_  << endl;
107    cout << " elementBeam::FileOutputFlow, p0 = " << p0_ << endl;
108    return sortie.str();
109}
110
111void elementBeam::elementBeam::FileInput(ifstream& ifs) {
112    ifs >> label_;
113    ifs >> x_ >> xp_ >>  y_ >> yp_;
114    ifs >> dl_ >> del_ >> p0_;
115    cout << " elementBeam::FileFileInput, p0 = " << p0_ << endl;
116    lenghtElem_ = getLenghtOfElement();
117    cout << " elementBeam::FileInput calcule longueur = " << lenghtElem_ << endl;
118}
119
120
121string elementBeam::print() {
122    string txt = "";
123    txt += label_;
124    txt += "\n 1/2 horizontal beam extend rms (cm) : ";
125    txt += mixedTools::doubleToString(x_);
126    txt += "\n 1/2 horizontal beam divergence rms (mrad) : ";
127    txt += mixedTools::doubleToString(xp_);
128    txt += "\n1/2 vertical beam extend rms (cm) : ";
129    txt += mixedTools::doubleToString(y_);
130    txt += "\n1/2 horizontal beam divergence rms (mrad) : ";
131    txt += mixedTools::doubleToString(yp_);
132    txt += "\n1/2 longitudinal beam extend rms (cm) : ";
133    txt += mixedTools::doubleToString(dl_);
134    txt += "\n1/2 momentum spread rms (mrad) : ";
135    txt += mixedTools::doubleToString(del_);
136    txt += "\nmomentum of the central trajectory (GeV/c) : ";
137    txt += mixedTools::doubleToString(p0_);
138   
139    return txt;
140}
Note: See TracBrowser for help on using the repository browser.