Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:28

0001 #include "Alignment/CocoaModel/interface/CocoaDaqReaderText.h"
0002 #include "Alignment/CocoaModel/interface/Measurement.h"
0003 #include "Alignment/CocoaModel/interface/Model.h"
0004 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0005 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0006 
0007 using namespace std;
0008 #include <iostream>
0009 #include <cstdlib>
0010 
0011 //----------------------------------------------------------------------
0012 CocoaDaqReaderText::CocoaDaqReaderText(const std::string& fileName) {
0013   if (ALIUtils::debug >= 5)
0014     std::cout << " CocoaDaqReaderText::CocoaDaqReaderText from file " << fileName << std::endl;
0015 
0016   CocoaDaqReader::SetDaqReader(this);
0017 
0018   theFilein = ALIFileIn::getInstance(fileName);
0019 }
0020 
0021 //----------------------------------------------------------------------
0022 CocoaDaqReaderText::~CocoaDaqReaderText() {}
0023 
0024 //----------------------------------------------------------------------
0025 bool CocoaDaqReaderText::ReadNextEvent() {
0026   std::vector<ALIstring> wordlist;
0027   //---------- read date
0028   //  ALIint retfil = filein.getWordsInLine(wordlist);
0029   // std::cout << "@@@@@@@@@@@@@@@ RETFIL " << retfil << std::endl;
0030   //if( retfil == 0 ) {
0031   if (theFilein.getWordsInLine(wordlist) == 0) {
0032     if (ALIUtils::debug >= 4)
0033       std::cout << "@@@@ No more measurements left" << std::endl;
0034     return false;
0035   }
0036 
0037   ////--- Transform to time_t format and save it
0038   //  struct tm tim;
0039   //t Model::setMeasurementsTime( tim );
0040 
0041   //set date and time of current measurement
0042   if (wordlist[0] == "DATE:") {
0043     Measurement::setCurrentDate(wordlist);
0044   }
0045 
0046   //---------- loop measurements
0047   ALIint nMeas = Model::MeasurementList().size();
0048   if (ALIUtils::debug >= 4) {
0049     std::cout << " Reading " << nMeas << " measurements from file " << theFilein.name() << " DATE: " << wordlist[1]
0050               << " " << wordlist[1] << std::endl;
0051   }
0052   for (ALIint im = 0; im < nMeas; im++) {
0053     theFilein.getWordsInLine(wordlist);
0054     if (wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") ||
0055         wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") ||
0056         wordlist[0] == ALIstring("COPS")) {
0057       if (wordlist.size() != 2) {
0058         std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of "
0059                   << wordlist.size() << std::endl;
0060         ALIUtils::dumpVS(wordlist, " ");
0061         exit(1);
0062       }
0063       std::vector<Measurement*>::const_iterator vmcite;
0064       for (vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite) {
0065         //---- Look for Measurement
0066         /*  ALIint last_slash =  (*vmcite)->name().rfind('/');
0067     ALIstring oname = (*vmcite)->name();
0068     if( last_slash != -1 ) {
0069       oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
0070       } 
0071     */
0072         ALIint fcolon = (*vmcite)->name().find(':');
0073         ALIstring oname = (*vmcite)->name();
0074         oname = oname.substr(fcolon + 1, oname.length());
0075         //-    std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
0076         if (oname == wordlist[1]) {
0077           //-------- Measurement found, fill data
0078           //-   std::cout << " measurement name found " << oname << std::endl;
0079           if ((*vmcite)->type() != wordlist[0]) {
0080             std::cerr << "!!! Reading measurement from file: type in file is " << wordlist[0] << " and should be "
0081                       << (*vmcite)->type() << std::endl;
0082             exit(1);
0083           }
0084           Measurement* meastemp = *vmcite;
0085 
0086           GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0087           ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
0088           //---------- Read the data
0089           for (unsigned int ii = 0; ii < meastemp->dim(); ii++) {
0090             theFilein.getWordsInLine(wordlist);
0091             ALIdouble sigma = 0.;
0092             if (!sigmaFF) {
0093               // keep the sigma, do not read it from file
0094               const ALIdouble* sigmav = meastemp->sigma();
0095               sigma = sigmav[ii];
0096             }
0097             //---- Check measurement value type is OK
0098             if (meastemp->valueType(ii) != wordlist[0]) {
0099               theFilein.ErrorInLine();
0100               std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0]
0101                         << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
0102               exit(1);
0103             }
0104             meastemp->fillData(ii, wordlist);
0105             if (!sigmaFF) {
0106               meastemp->setSigma(ii, sigma);
0107             }
0108           }
0109           meastemp->correctValueAndSigma();
0110           break;
0111         }
0112       }
0113       if (vmcite == Model::MeasurementList().end()) {
0114         for (vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite) {
0115           std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
0116         }
0117         std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is " << wordlist[1]
0118                   << std::endl;
0119         exit(1);
0120       }
0121     } else {
0122       std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
0123                 << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
0124       exit(1);
0125     }
0126   }
0127   //-  std::cout << " returning readmeasff" << std::endl;
0128 
0129   if (theFilein.eof()) {
0130     return false;
0131   } else {
0132     return true;
0133   }
0134 }
0135 
0136 //----------------------------------------------------------------------
0137 void CocoaDaqReaderText::BuildMeasurementsFromOptAlign(std::vector<OpticalAlignMeasurementInfo>& measList) {}