CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CocoaDaqReaderText.cc
Go to the documentation of this file.
6 
7 using namespace std;
8 #include <iostream>
9 #include <cstdlib>
10 
11 //----------------------------------------------------------------------
13  if (ALIUtils::debug >= 5)
14  std::cout << " CocoaDaqReaderText::CocoaDaqReaderText from file " << fileName << std::endl;
15 
17 
18  theFilein = ALIFileIn::getInstance(fileName);
19 }
20 
21 //----------------------------------------------------------------------
23 
24 //----------------------------------------------------------------------
26  std::vector<ALIstring> wordlist;
27  //---------- read date
28  // ALIint retfil = filein.getWordsInLine(wordlist);
29  // std::cout << "@@@@@@@@@@@@@@@ RETFIL " << retfil << std::endl;
30  //if( retfil == 0 ) {
31  if (theFilein.getWordsInLine(wordlist) == 0) {
32  if (ALIUtils::debug >= 4)
33  std::cout << "@@@@ No more measurements left" << std::endl;
34  return false;
35  }
36 
38  // struct tm tim;
39  //t Model::setMeasurementsTime( tim );
40 
41  //set date and time of current measurement
42  if (wordlist[0] == "DATE:") {
44  }
45 
46  //---------- loop measurements
47  ALIint nMeas = Model::MeasurementList().size();
48  if (ALIUtils::debug >= 4) {
49  std::cout << " Reading " << nMeas << " measurements from file " << theFilein.name() << " DATE: " << wordlist[1]
50  << " " << wordlist[1] << std::endl;
51  }
52  for (ALIint im = 0; im < nMeas; im++) {
53  theFilein.getWordsInLine(wordlist);
54  if (wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") ||
55  wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") ||
56  wordlist[0] == ALIstring("COPS")) {
57  if (wordlist.size() != 2) {
58  std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of "
59  << wordlist.size() << std::endl;
60  ALIUtils::dumpVS(wordlist, " ");
61  exit(1);
62  }
63  std::vector<Measurement*>::const_iterator vmcite;
64  for (vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite) {
65  //---- Look for Measurement
66  /* ALIint last_slash = (*vmcite)->name().rfind('/');
67  ALIstring oname = (*vmcite)->name();
68  if( last_slash != -1 ) {
69  oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
70  }
71  */
72  ALIint fcolon = (*vmcite)->name().find(':');
73  ALIstring oname = (*vmcite)->name();
74  oname = oname.substr(fcolon + 1, oname.length());
75  //- std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
76  if (oname == wordlist[1]) {
77  //-------- Measurement found, fill data
78  //- std::cout << " measurement name found " << oname << std::endl;
79  if ((*vmcite)->type() != wordlist[0]) {
80  std::cerr << "!!! Reading measurement from file: type in file is " << wordlist[0] << " and should be "
81  << (*vmcite)->type() << std::endl;
82  exit(1);
83  }
84  Measurement* meastemp = *vmcite;
85 
87  ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
88  //---------- Read the data
89  for (unsigned int ii = 0; ii < meastemp->dim(); ii++) {
90  theFilein.getWordsInLine(wordlist);
91  ALIdouble sigma = 0.;
92  if (!sigmaFF) {
93  // keep the sigma, do not read it from file
94  const ALIdouble* sigmav = meastemp->sigma();
95  sigma = sigmav[ii];
96  }
97  //---- Check measurement value type is OK
98  if (meastemp->valueType(ii) != wordlist[0]) {
99  theFilein.ErrorInLine();
100  std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0]
101  << " 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]
118  << std::endl;
119  exit(1);
120  }
121  } else {
122  std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
123  << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
124  exit(1);
125  }
126  }
127  //- std::cout << " returning readmeasff" << std::endl;
128 
129  if (theFilein.eof()) {
130  return false;
131  } else {
132  return true;
133  }
134 }
135 
136 //----------------------------------------------------------------------
137 void CocoaDaqReaderText::BuildMeasurementsFromOptAlign(std::vector<OpticalAlignMeasurementInfo>& measList) {}
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIFileIn & getInstance(const ALIstring &name)
Definition: ALIFileIn.cc:22
const ALIuint dim() const
Definition: Measurement.h:82
const ALIstring valueType(ALIuint ii) const
Definition: Measurement.h:116
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:34
static GlobalOptionMgr * getInstance()
int ii
Definition: cuy.py:589
~CocoaDaqReaderText() override
bool ALIbool
Definition: CocoaGlobals.h:19
void fillData(ALIuint coor, const std::vector< ALIstring > &wl)
Definition: Measurement.cc:192
CocoaDaqReaderText(const std::string &fileName)
void setSigma(ALIint coor, ALIdouble val)
Definition: Measurement.h:131
void BuildMeasurementsFromOptAlign(std::vector< OpticalAlignMeasurementInfo > &measList) override
const ALIdouble * sigma() const
Definition: Measurement.h:112
bool ReadNextEvent() override
static void SetDaqReader(CocoaDaqReader *reader)
string oname
Definition: heppy_report.py:57
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:465
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
std::string ALIstring
Definition: CocoaGlobals.h:9
string end
Definition: dataset.py:937
tuple cout
Definition: gather_cfg.py:144
virtual void correctValueAndSigma()
Definition: Measurement.h:66
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:88
static void setCurrentDate(const std::vector< ALIstring > &wl)
set the date of the current measurement
Definition: Measurement.cc:605