File indexing completed on 2024-04-06 11:56:01
0001 #include "Alignment/CocoaModel/interface/FittedEntriesReader.h"
0002 #include "Alignment/CocoaModel/interface/Model.h"
0003 #include "Alignment/CocoaModel/interface/Entry.h"
0004 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0005 #include "Alignment/CocoaModel/interface/ALIRmDataFromFile.h"
0006 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0007
0008
0009 FittedEntriesReader::FittedEntriesReader(const ALIstring& filename) {
0010 theFileName = filename;
0011 theFile = ALIFileIn::getInstance(filename);
0012 std::vector<ALIstring> wl;
0013 theFile.getWordsInLine(wl);
0014 if (wl[0] == ALIstring("DIMENSIONS:")) {
0015 theLengthDim = ALIUtils::CalculateLengthDimensionFactorFromString(wl[3]);
0016 theLengthErrorDim = ALIUtils::CalculateLengthDimensionFactorFromString(wl[5]);
0017 theAngleDim = ALIUtils::CalculateAngleDimensionFactorFromString(wl[8]);
0018 theAngleErrorDim = ALIUtils::CalculateAngleDimensionFactorFromString(wl[10]);
0019 } else {
0020 ALIUtils::dumpVS(wl, "!!! FATAL ERROR FittedEntriesReader: first line is not dimensions ");
0021 std::exception();
0022 }
0023 }
0024
0025
0026 ALIbool FittedEntriesReader::readFittedEntriesFromFile() {
0027 if (ALIUtils::debug >= 5)
0028 std::cout << " readFittedEntriesFromFile " << theFileName << std::endl;
0029 std::map<OpticalObject*, ALIRmDataFromFile> affAngles;
0030
0031 std::vector<ALIstring> wl;
0032 theFile.getWordsInLine(wl);
0033 unsigned int siz = wl.size();
0034 for (size_t ii = 1; ii < siz; ii += 3) {
0035 ALIstring optOentryName = substitutePointBySlash(wl[ii]);
0036 Entry* entry = Model::getEntryByName(optOentryName);
0037 if (ALIUtils::debug >= 5)
0038 std::cout << entry->name() << " readFittedEntriesFromFile " << entry->value() << " "
0039 << ALIUtils::getFloat(wl[ii + 1]) << std::endl;
0040 if (entry->name().substr(0, 6) != "angles") {
0041 entry->displaceOriginalOriginal(entry->value() - ALIUtils::getFloat(wl[ii + 1]) * theLengthDim);
0042 } else {
0043 OpticalObject* opto = entry->OptOCurrent();
0044 if (affAngles.find(opto) == affAngles.end()) {
0045 affAngles[opto] = ALIRmDataFromFile();
0046 }
0047 std::map<OpticalObject*, ALIRmDataFromFile>::iterator ite = affAngles.find(opto);
0048 (*ite).second.setAngle(optOentryName.substr(optOentryName.size() - 1, 1),
0049 ALIUtils::getFloat(wl[ii + 1]) * theAngleDim);
0050 if (ALIUtils::debug >= 5)
0051 std::cout << " setting angle from file " << ALIUtils::getFloat(wl[ii + 1]) * theAngleDim << " " << wl[ii + 1]
0052 << " " << theAngleDim << std::endl;
0053 }
0054 entry->setSigma(ALIUtils::getFloat(wl[ii + 2]) * theAngleDim);
0055
0056 }
0057
0058 ALIstring coordi("XYZ");
0059 std::map<OpticalObject*, ALIRmDataFromFile>::const_iterator ite;
0060 for (ite = affAngles.begin(); ite != affAngles.end(); ++ite) {
0061 ALIRmDataFromFile dff = (*ite).second;
0062 OpticalObject* opto = (*ite).first;
0063 for (size_t ii = 0; ii < 3; ii++) {
0064 int ifound = dff.dataFilled().find(coordi[ii]);
0065 if (ALIUtils::debug >= 5)
0066 std::cout << ii << " dataFilled " << ifound << std::endl;
0067 if (ifound == -1) {
0068 ALIdouble entval = opto->getEntryRMangle(coordi.substr(ii, 1));
0069 dff.setAngle(coordi.substr(ii, 1), entval);
0070 }
0071 }
0072 dff.constructRm();
0073 opto->setGlobalRMOriginalOriginal(dff.rm());
0074 }
0075
0076 return true;
0077 }
0078
0079
0080 ALIstring FittedEntriesReader::substitutePointBySlash(const ALIstring& nameWithPoints) const {
0081 ALIstring nameWithSlash = nameWithPoints;
0082
0083 size_t siz = nameWithPoints.length();
0084
0085 for (size_t ii = 0; ii < siz; ii++) {
0086 if (nameWithSlash[ii] == '.')
0087 nameWithSlash[ii] = '/';
0088 }
0089 nameWithSlash = "s/" + nameWithSlash;
0090 if (ALIUtils::debug >= 5)
0091 std::cout << " substitutePointBySlash " << nameWithSlash << " " << std::endl;
0092
0093 return nameWithSlash;
0094 }