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