CMS 3D CMS Logo

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 
00008 using namespace std;
00009 #include <iostream>
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   ALIint ii;
00057   for(ii = 0; ii < nMeas; ii++) {
00058     theFilein.getWordsInLine(wordlist);  
00059     if( wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") || wordlist[0] == ALIstring("DISTANCEMETER")  || wordlist[0] == ALIstring("DISTANCEMETER1DIM")  || wordlist[0] == ALIstring("COPS") ) {
00060       if( wordlist.size() != 2 ) {
00061         std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of " << wordlist.size() << std::endl;
00062         ALIUtils::dumpVS( wordlist, " " );
00063         exit(1);
00064       }
00065       std::vector< Measurement* >::const_iterator vmcite;
00066       for( vmcite = Model::MeasurementList().begin();  vmcite != Model::MeasurementList().end(); vmcite++ ) {
00067         //-------- Measurement found, fill data
00068         /*      ALIint last_slash =  (*vmcite)->name().rfind('/');
00069         ALIstring oname = (*vmcite)->name();
00070         if( last_slash != -1 ) {
00071           oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
00072           } 
00073         */
00074         ALIint fcolon = (*vmcite)->name().find(':');
00075         ALIstring oname = (*vmcite)->name();
00076         oname = oname.substr(fcolon+1,oname.length());
00077         //-    std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
00078         if( oname == wordlist[1] ) {
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 ( uint 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 }

Generated on Tue Jun 9 17:23:36 2009 for CMSSW by  doxygen 1.5.4