Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#include "Alignment/CocoaModel/interface/FittedEntriesReader.h"
#include "Alignment/CocoaModel/interface/Model.h"
#include "Alignment/CocoaModel/interface/Entry.h"
#include "Alignment/CocoaModel/interface/OpticalObject.h"
#include "Alignment/CocoaModel/interface/ALIRmDataFromFile.h"
#include "Alignment/CocoaUtilities/interface/ALIUtils.h"

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
FittedEntriesReader::FittedEntriesReader(const ALIstring& filename) {
  theFileName = filename;
  theFile = ALIFileIn::getInstance(filename);
  std::vector<ALIstring> wl;
  theFile.getWordsInLine(wl);
  if (wl[0] == ALIstring("DIMENSIONS:")) {
    theLengthDim = ALIUtils::CalculateLengthDimensionFactorFromString(wl[3]);
    theLengthErrorDim = ALIUtils::CalculateLengthDimensionFactorFromString(wl[5]);
    theAngleDim = ALIUtils::CalculateAngleDimensionFactorFromString(wl[8]);
    theAngleErrorDim = ALIUtils::CalculateAngleDimensionFactorFromString(wl[10]);
  } else {
    ALIUtils::dumpVS(wl, "!!! FATAL ERROR FittedEntriesReader: first line is not dimensions ");
    std::exception();
  }
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ALIbool FittedEntriesReader::readFittedEntriesFromFile() {
  if (ALIUtils::debug >= 5)
    std::cout << " readFittedEntriesFromFile " << theFileName << std::endl;
  std::map<OpticalObject*, ALIRmDataFromFile> affAngles;

  std::vector<ALIstring> wl;
  theFile.getWordsInLine(wl);
  unsigned int siz = wl.size();
  for (size_t ii = 1; ii < siz; ii += 3) {
    ALIstring optOentryName = substitutePointBySlash(wl[ii]);
    Entry* entry = Model::getEntryByName(optOentryName);
    if (ALIUtils::debug >= 5)
      std::cout << entry->name() << " readFittedEntriesFromFile " << entry->value() << " "
                << ALIUtils::getFloat(wl[ii + 1]) << std::endl;
    if (entry->name().substr(0, 6) != "angles") {
      entry->displaceOriginalOriginal(entry->value() - ALIUtils::getFloat(wl[ii + 1]) * theLengthDim);
    } else {
      OpticalObject* opto = entry->OptOCurrent();
      if (affAngles.find(opto) == affAngles.end()) {
        affAngles[opto] = ALIRmDataFromFile();
      }
      std::map<OpticalObject*, ALIRmDataFromFile>::iterator ite = affAngles.find(opto);
      (*ite).second.setAngle(optOentryName.substr(optOentryName.size() - 1, 1),
                             ALIUtils::getFloat(wl[ii + 1]) * theAngleDim);
      if (ALIUtils::debug >= 5)
        std::cout << " setting angle from file " << ALIUtils::getFloat(wl[ii + 1]) * theAngleDim << " " << wl[ii + 1]
                  << " " << theAngleDim << std::endl;
    }
    entry->setSigma(ALIUtils::getFloat(wl[ii + 2]) * theAngleDim);
    //  ar.lass6.laser.angles_X -159.7524 7.2208261
  }

  ALIstring coordi("XYZ");
  std::map<OpticalObject*, ALIRmDataFromFile>::const_iterator ite;
  for (ite = affAngles.begin(); ite != affAngles.end(); ++ite) {
    ALIRmDataFromFile dff = (*ite).second;
    OpticalObject* opto = (*ite).first;
    for (size_t ii = 0; ii < 3; ii++) {
      int ifound = dff.dataFilled().find(coordi[ii]);
      if (ALIUtils::debug >= 5)
        std::cout << ii << " dataFilled " << ifound << std::endl;
      if (ifound == -1) {  //angles not read from file are taken as the original value
        ALIdouble entval = opto->getEntryRMangle(coordi.substr(ii, 1));
        dff.setAngle(coordi.substr(ii, 1), entval);
      }
    }
    dff.constructRm();
    opto->setGlobalRMOriginalOriginal(dff.rm());
  }

  return true;  // to avoid warning
}

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
ALIstring FittedEntriesReader::substitutePointBySlash(const ALIstring& nameWithPoints) const {
  ALIstring nameWithSlash = nameWithPoints;

  size_t siz = nameWithPoints.length();

  for (size_t ii = 0; ii < siz; ii++) {
    if (nameWithSlash[ii] == '.')
      nameWithSlash[ii] = '/';
  }
  nameWithSlash = "s/" + nameWithSlash;
  if (ALIUtils::debug >= 5)
    std::cout << " substitutePointBySlash " << nameWithSlash << " " << std::endl;

  return nameWithSlash;
}