CMS 3D CMS Logo

CocoaDaqReaderText.cc
Go to the documentation of this file.
6 
7 using namespace std;
8 #include <iostream>
9 #include <cstdlib>
10 
11 //----------------------------------------------------------------------
13 {
14 
15  if(ALIUtils::debug >= 5) std::cout << " CocoaDaqReaderText::CocoaDaqReaderText from file " << fileName << std::endl;
16 
18 
19  theFilein = ALIFileIn::getInstance( fileName );
20 
21 }
22 
23 //----------------------------------------------------------------------
25 {
26 }
27 
28 //----------------------------------------------------------------------
30 {
31  std::vector<ALIstring> wordlist;
32  //---------- read date
33  // ALIint retfil = filein.getWordsInLine(wordlist);
34  // std::cout << "@@@@@@@@@@@@@@@ RETFIL " << retfil << std::endl;
35  //if( retfil == 0 ) {
36  if( theFilein.getWordsInLine(wordlist) == 0 ) {
37  if(ALIUtils::debug>=4 ) std::cout << "@@@@ No more measurements left" << std::endl;
38  return false;
39  }
40 
42  // struct tm tim;
43  //t Model::setMeasurementsTime( tim );
44 
45  //set date and time of current measurement
46  if( wordlist[0] == "DATE:" ) {
47  Measurement::setCurrentDate( wordlist );
48  }
49 
50  //---------- loop measurements
51  ALIint nMeas = Model::MeasurementList().size();
52  if(ALIUtils::debug >= 4) {
53  std::cout << " Reading " << nMeas << " measurements from file " << theFilein.name()
54  << " DATE: " << wordlist[1] << " " << wordlist[1] << std::endl;
55  }
56  for( ALIint im = 0; im < nMeas; im++) {
57  theFilein.getWordsInLine(wordlist);
58  if( wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") || wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") || wordlist[0] == ALIstring("COPS") ) {
59  if( wordlist.size() != 2 ) {
60  std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of " << wordlist.size() << std::endl;
61  ALIUtils::dumpVS( wordlist, " " );
62  exit(1);
63  }
64  std::vector< Measurement* >::const_iterator vmcite;
65  for( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite ) {
66  //---- Look for Measurement
67  /* ALIint last_slash = (*vmcite)->name().rfind('/');
68  ALIstring oname = (*vmcite)->name();
69  if( last_slash != -1 ) {
70  oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
71  }
72  */
73  ALIint fcolon = (*vmcite)->name().find(':');
74  ALIstring oname = (*vmcite)->name();
75  oname = oname.substr(fcolon+1,oname.length());
76  //- std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
77  if( oname == wordlist[1] ) {
78  //-------- Measurement found, fill data
79  //- std::cout << " measurement name found " << oname << std::endl;
80  if( (*vmcite)->type() != wordlist[0] ) {
81  std::cerr << "!!! Reading measurement from file: type in file is "
82  << wordlist[0] << " and should be " << (*vmcite)->type() << std::endl;
83  exit(1);
84  }
85  Measurement* meastemp = *vmcite;
86 
88  ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
89  //---------- Read the data
90  for ( unsigned int ii=0; ii < meastemp->dim(); ii++){
91  theFilein.getWordsInLine( wordlist );
92  ALIdouble sigma = 0.;
93  if( !sigmaFF ) {
94  // keep the sigma, do not read it from file
95  const ALIdouble* sigmav = meastemp->sigma();
96  sigma = sigmav[ii];
97  }
98  //---- Check measurement value type is OK
99  if( meastemp->valueType(ii) != wordlist[0] ) {
100  theFilein.ErrorInLine();
101  std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0] << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
102  exit(1);
103  }
104  meastemp->fillData( ii, wordlist );
105  if( !sigmaFF ) {
106  meastemp->setSigma( ii, sigma );
107  }
108  }
109  meastemp->correctValueAndSigma();
110  break;
111  }
112  }
113  if( vmcite == Model::MeasurementList().end() ) {
114  for( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite ) {
115  std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
116  }
117  std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is " << wordlist[1] << std::endl;
118  exit(1);
119  }
120  } else {
121  std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
122  << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
123  exit(1);
124  }
125  }
126  //- std::cout << " returning readmeasff" << std::endl;
127 
128  if( theFilein.eof() ) {
129  return false;
130  } else {
131  return true;
132  }
133 }
134 
135 //----------------------------------------------------------------------
136 void CocoaDaqReaderText::BuildMeasurementsFromOptAlign( std::vector<OpticalAlignMeasurementInfo>& measList )
137 {
138 
139 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:23
const ALIuint dim() const
Definition: Measurement.h:82
const ALIstring valueType(ALIuint ii) const
Definition: Measurement.h:140
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
~CocoaDaqReaderText() override
bool ALIbool
Definition: CocoaGlobals.h:19
void fillData(ALIuint coor, const std::vector< ALIstring > &wl)
Definition: Measurement.cc:201
CocoaDaqReaderText(const std::string &fileName)
void setSigma(ALIint coor, ALIdouble val)
Definition: Measurement.h:171
void BuildMeasurementsFromOptAlign(std::vector< OpticalAlignMeasurementInfo > &measList) override
const ALIdouble * sigma() const
Definition: Measurement.h:132
bool ReadNextEvent() override
#define end
Definition: vmac.h:39
ii
Definition: cuy.py:590
static void SetDaqReader(CocoaDaqReader *reader)
static void dumpVS(const std::vector< ALIstring > &wl, const std::string &msg, std::ostream &outs=std::cout)
dumps a vector of strings with a message to outs
Definition: ALIUtils.cc:501
#define begin
Definition: vmac.h:32
std::string ALIstring
Definition: CocoaGlobals.h:9
virtual void correctValueAndSigma()
Definition: Measurement.h:67
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
static void setCurrentDate(const std::vector< ALIstring > &wl)
set the date of the current measurement
Definition: Measurement.cc:632