CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/Alignment/CocoaModel/src/CocoaDaqReaderText.cc

Go to the documentation of this file.
00001 #include "Alignment/CocoaModel/interface/CocoaDaqReaderText.h"
00002 #include "Alignment/CocoaModel/interface/Measurement.h"
00003 #include "Alignment/CocoaModel/interface/Model.h"
00004 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00005 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00006 
00007 using namespace std;
00008 #include <iostream>
00009 #include <cstdlib>
00010 
00011 //----------------------------------------------------------------------
00012 CocoaDaqReaderText::CocoaDaqReaderText(const std::string& fileName )
00013 {
00014 
00015  if(ALIUtils::debug >= 5) std::cout << " CocoaDaqReaderText::CocoaDaqReaderText from file " << fileName << std::endl;
00016 
00017   CocoaDaqReader::SetDaqReader( this );
00018 
00019   theFilein = ALIFileIn::getInstance( fileName );
00020 
00021 }
00022 
00023 //----------------------------------------------------------------------
00024 CocoaDaqReaderText::~CocoaDaqReaderText()
00025 {
00026 }
00027 
00028 //----------------------------------------------------------------------
00029 bool CocoaDaqReaderText::ReadNextEvent()
00030 {
00031   std::vector<ALIstring> wordlist;
00032   //---------- read date
00033   //  ALIint retfil = filein.getWordsInLine(wordlist);
00034   // std::cout << "@@@@@@@@@@@@@@@ RETFIL " << retfil << std::endl;
00035   //if( retfil == 0 ) {
00036   if( theFilein.getWordsInLine(wordlist) == 0 ) {
00037     if(ALIUtils::debug>=4 ) std::cout << "@@@@ No more measurements left" << std::endl;
00038     return 0; 
00039   }
00040 
00042   //  struct tm tim;
00043   //t Model::setMeasurementsTime( tim );
00044 
00045   //set date and time of current measurement
00046   if( wordlist[0] == "DATE:" ) {
00047     Measurement::setCurrentDate( wordlist ); 
00048   } 
00049 
00050   //---------- loop measurements
00051   ALIint nMeas = Model::MeasurementList().size();
00052   if(ALIUtils::debug >= 4) {
00053     std::cout << " Reading " << nMeas << " measurements from file " << theFilein.name() 
00054          << " DATE: " << wordlist[1] << " " << wordlist[1] << std::endl;
00055   }
00056   for( ALIint im = 0; im < nMeas; im++) {
00057     theFilein.getWordsInLine(wordlist);  
00058     if( wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") || wordlist[0] == ALIstring("DISTANCEMETER")  || wordlist[0] == ALIstring("DISTANCEMETER1DIM")  || wordlist[0] == ALIstring("COPS") ) {
00059       if( wordlist.size() != 2 ) {
00060         std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of " << wordlist.size() << std::endl;
00061         ALIUtils::dumpVS( wordlist, " " );
00062         exit(1);
00063       }
00064       std::vector< Measurement* >::const_iterator vmcite;
00065       for( vmcite = Model::MeasurementList().begin();  vmcite != Model::MeasurementList().end(); vmcite++ ) {
00066         //---- Look for Measurement
00067         /*      ALIint last_slash =  (*vmcite)->name().rfind('/');
00068         ALIstring oname = (*vmcite)->name();
00069         if( last_slash != -1 ) {
00070           oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
00071           } 
00072         */
00073         ALIint fcolon = (*vmcite)->name().find(':');
00074         ALIstring oname = (*vmcite)->name();
00075         oname = oname.substr(fcolon+1,oname.length());
00076         //-    std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
00077         if( oname == wordlist[1] ) {
00078         //-------- Measurement found, fill data
00079           //-   std::cout << " measurement name found " << oname << std::endl;
00080           if( (*vmcite)->type() != wordlist[0] ) {
00081             std::cerr << "!!! Reading measurement from file: type in file is " 
00082                  << wordlist[0] << " and should be " << (*vmcite)->type() << std::endl;
00083             exit(1);
00084           }
00085           Measurement* meastemp = *vmcite;
00086           
00087           GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00088           ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
00089           //---------- Read the data 
00090           for ( unsigned int ii=0; ii < meastemp->dim(); ii++){
00091             theFilein.getWordsInLine( wordlist );
00092             ALIdouble sigma = 0.;
00093             if( !sigmaFF ) { 
00094               // keep the sigma, do not read it from file 
00095               const ALIdouble* sigmav = meastemp->sigma();
00096               sigma = sigmav[ii];
00097             }
00098             //---- Check measurement value type is OK
00099             if( meastemp->valueType(ii) != wordlist[0] ) {
00100               theFilein.ErrorInLine();
00101               std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0] << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
00102               exit(1);
00103             }
00104             meastemp->fillData( ii, wordlist );
00105             if( !sigmaFF ) { 
00106               meastemp->setSigma( ii, sigma );
00107             }
00108           }
00109           meastemp->correctValueAndSigma();
00110           break;
00111         }
00112       }
00113       if( vmcite == Model::MeasurementList().end() ) {
00114         for( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); vmcite++ ) {
00115           std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
00116         }
00117         std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is "  << wordlist[1]  << std::endl;
00118         exit(1);
00119       }
00120     } else {
00121       std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
00122            << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
00123       exit(1);
00124     }
00125   }
00126   //-  std::cout << " returning readmeasff" << std::endl;
00127 
00128   if( theFilein.eof() ) {
00129     return 0;
00130   } else {
00131     return 1;
00132   }
00133 }
00134 
00135 //----------------------------------------------------------------------
00136 void CocoaDaqReaderText::BuildMeasurementsFromOptAlign( std::vector<OpticalAlignMeasurementInfo>& measList )
00137 {
00138 
00139 }