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