source: PSPA/Interface_Web/trunk/pspaWT/sources/controler/src/softwareTest.cc @ 360

Last change on this file since 360 was 333, checked in by lemeur, 11 years ago

addition graphique (en cours)

File size: 3.6 KB
Line 
1#include "softwareTest.h"
2#include "abstractElement.h"
3#include "dataManager.h"
4#include "mathematicalConstants.h"
5#include "PhysicalConstants.h"
6
7
8softwareTest::softwareTest() : abstractSoftware()
9{
10  ;
11}
12
13
14
15
16softwareTest::softwareTest(string inputFileName, globalParameters* globals, dataManager* dt) : abstractSoftware( inputFileName, globals, dt)
17{
18  ;
19}
20
21bool softwareTest::createInputFile( particleBeam* beamBefore, unsigned int numeroDeb, unsigned int numeroFin, string workingDir)
22{
23    dataManager_->consoleMessage(" softwareTest::createInputFile  " );
24
25    beamToParin(workingDir, beamBefore );
26
27
28
29  return true;
30}
31
32bool  softwareTest::execute( unsigned int numeroDeb,unsigned int numeroFin,string workingDir) {
33    dataManager_->consoleMessage(" softwareTest::execute  " );
34  return true;
35}
36
37bool  softwareTest::buildBeamAfterElements(unsigned int numeroDeb,unsigned int numeroFin, vector<particleBeam>& beams, string workingDir) {
38  dataManager_->consoleMessage(" softwareTest::buildBeamAfterElements  " );
39  bool result = true;
40  unsigned k;
41  for ( k= numeroDeb; k <= numeroFin; k++)
42    {
43      beams.push_back(particleBeam());
44      vector<double> centroid = vector<double>(6,0.0);
45      bareParticle refPart;
46      vector<bareParticle> particles;
47           
48 
49      if (!beamFromParin(workingDir,particles ) )
50        {
51          dataManager_->consoleMessage(" softwareTest::buildBeamAfterElements : reading parin  failed " );
52          result = false;
53          break;
54        }
55      else {
56        bareParticle refPart (particles.at(0));
57        beams.back().setWithParticles(centroid, refPart,particles); 
58      }
59    }
60  return result;
61}
62
63// sauvegarde d'un 'particleBeam' sur un fichier parmela, en guise d'INPUT
64// pour l'instant de nom standard 'parin.input0'
65bool softwareTest::beamToParin(string workingDir, particleBeam* beam ) {
66  if ( !beam->particleRepresentationOk() ) {
67    dataManager_->consoleMessage("softwareParmela::beamToParmela : beam not in particles form : not yet programmed");
68    cout << " softwareParmela::beamToParmela : beam not in particles form : not yet programmed " << endl;
69    return false;
70  }
71  ofstream outfile;
72  string name = workingDir + "parin.input0";
73  outfile.open(name.c_str(), ios::out);
74  if (!outfile) {
75    dataManager_->consoleMessage(" softwareTest::beamToParin : error opening in stream ");
76    cerr << " softwareParmela::beamToParmela : error opening output stream " << name << endl;
77    return false;
78  }
79
80  const vector<bareParticle>& partic = beam->getParticleVector();
81  unsigned k;
82  double weight = 1.0;
83  double xx,yy,zz;
84  double begamx, begamy, begamz;
85  for ( k=0; k < partic.size(); k++) {
86    partic.at(k).getPosition().getComponents(xx,yy,zz);
87    partic.at(k).getBetaGamma().getComponents(begamx, begamy, begamz);
88    outfile << xx << " " << begamx << " " <<  yy << " " << begamy << " " << zz << " " << begamz  << " " << weight << endl;
89  }
90  outfile.close();
91  return true;
92}
93
94bool softwareTest::beamFromParin(string workingDir, vector<bareParticle>& particles ) {
95  ifstream infile;
96  string name = workingDir + "parin.input0";
97  infile.open(name.c_str(), ios::in);
98  if (!infile) {
99    dataManager_->consoleMessage(" softwareParmela::beamToParmela : error opening output stream ");
100    cerr << " softwareParmela::beamToParmela : error opening output stream " << name << endl;
101    return false;
102  }
103
104  particles.clear();
105  double weight;
106  double xx,yy,zz;
107  double begamx, begamy, begamz;
108  TRIDVECTOR  pos;
109  TRIDVECTOR betagamma;
110  while ( infile >> xx >> begamx >>  yy >>  begamy >> zz >> begamz  >> weight) {
111    pos.setComponents(xx,yy,zz);
112    betagamma.setComponents(begamx, begamy, begamz);
113    particles.push_back(bareParticle(pos,betagamma));
114  }
115  infile.close();
116  return true;
117}
Note: See TracBrowser for help on using the repository browser.