File indexing completed on 2024-04-06 11:56:02
0001
0002
0003
0004
0005
0006
0007
0008 #include "Alignment/CocoaModel/interface/Model.h"
0009
0010 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
0011 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
0012 #include "Alignment/CocoaModel/interface/OpticalObject.h"
0013 #include "Alignment/CocoaModel/interface/Measurement.h"
0014 #include "Alignment/CocoaModel/interface/MeasurementSensor2D.h"
0015 #include "Alignment/CocoaModel/interface/MeasurementDistancemeter.h"
0016 #include "Alignment/CocoaModel/interface/MeasurementDistancemeter3dim.h"
0017 #include "Alignment/CocoaModel/interface/MeasurementTiltmeter.h"
0018 #include "Alignment/CocoaModel/interface/MeasurementCOPS.h"
0019 #include "Alignment/CocoaModel/interface/MeasurementDiffEntry.h"
0020 #include "Alignment/CocoaModel/interface/CocoaDaqReaderText.h"
0021 #include "Alignment/CocoaModel/interface/CocoaDaqReaderRoot.h"
0022 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0023 #include "Alignment/CocoaModel/interface/EntryAngle.h"
0024 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
0025 #include "Alignment/CocoaModel/interface/ErrorCorrelationMgr.h"
0026
0027 #include "Alignment/CocoaModel/interface/EntryMgr.h"
0028 #include "Alignment/CocoaModel/interface/EntryData.h"
0029 #include "Alignment/CocoaModel/interface/FittedEntriesReader.h"
0030
0031 #include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h"
0032 #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h"
0033
0034 #include "FWCore/Utilities/interface/Exception.h"
0035
0036 #include <cstdlib>
0037 #include <cctype>
0038
0039 #include <cassert>
0040 #include <ctime>
0041
0042 #include <algorithm>
0043
0044 #ifdef OS_OSPACE_STD_NAMESPACE
0045 using namespace os_std;
0046 #endif
0047
0048
0049
0050
0051 Model* Model::theInstance = nullptr;
0052
0053 std::vector<std::vector<ALIstring> > Model::theOptODictionary;
0054
0055
0056
0057 std::vector<OpticalObject*> Model::theOptOList;
0058 std::vector<Entry*> Model::theEntryVector;
0059 std::vector<Measurement*> Model::theMeasurementVector;
0060 std::vector<ALIdouble> Model::theParamFittedSigmaVector;
0061 std::map<ALIstring, ALIdouble, std::less<ALIstring> > Model::theParamFittedValueDisplacementMap;
0062 std::vector<OpticalObject*> Model::theOptOsToCopyList;
0063 std::vector<OpticalObject*>::const_iterator Model::theOptOsToCopyListIterator;
0064 ALIint Model::CMSLinkIteration = 0;
0065 ALIint Model::Ncmslinkrange = 0;
0066 std::vector<ALIdouble> Model::CMSLinkRangeDetValue;
0067 ALIstring Model::theSDFName = "SystemDescription.txt";
0068 ALIstring Model::theMeasFName = "Measurements.txt";
0069 ALIstring Model::theReportFName = "report.out";
0070 ALIstring Model::theMatricesFName = "matrices.out";
0071
0072
0073 cocoaStatus Model::theCocoaStatus = COCOA_Init;
0074 FittedEntriesReader* Model::theFittedEntriesReader = nullptr;
0075 std::vector<OpticalAlignInfo> Model::theOpticalAlignments;
0076
0077
0078
0079
0080 Model& Model::getInstance() {
0081 if (!theInstance) {
0082 theInstance = new Model;
0083 }
0084 return *theInstance;
0085 }
0086
0087
0088
0089
0090 Model::Model() {
0091
0092 }
0093
0094
0095
0096
0097 void Model::readSystemDescription() {
0098 Model::setCocoaStatus(COCOA_Init);
0099
0100 ALIint data_reading = 0;
0101
0102
0103 ALIFileIn& filein = ALIFileIn::getInstance(Model::SDFName());
0104
0105
0106 std::vector<ALIstring> SectionTitle;
0107 SectionTitle.push_back(ALIstring("GLOBAL_OPTIONS"));
0108 SectionTitle.push_back(ALIstring("PARAMETERS"));
0109 SectionTitle.push_back(ALIstring("SYSTEM_TREE_DESCRIPTION"));
0110 SectionTitle.push_back(ALIstring("SYSTEM_TREE_DATA"));
0111 SectionTitle.push_back(ALIstring("MEASUREMENTS"));
0112 SectionTitle.push_back(ALIstring("REPORT.OUT"));
0113 std::vector<ALIstring>::iterator SectionTitleIterator;
0114
0115
0116 std::vector<ALIstring> wordlist;
0117 ALIint InSectionNo = -1;
0118 ALIint currentSectionNo = -1;
0119 while (!filein.eof()) {
0120 if (!filein.getWordsInLine(wordlist))
0121 break;
0122 assert(!wordlist.empty());
0123
0124
0125 if (ALIUtils::debug > 99) {
0126 ALIUtils::dumpVS(wordlist, " ", std::cout);
0127 }
0128
0129
0130
0131
0132 SectionTitleIterator = find(SectionTitle.begin(), SectionTitle.end(), *wordlist.begin());
0133 if (SectionTitleIterator != SectionTitle.end()) {
0134
0135 currentSectionNo = SectionTitleIterator - SectionTitle.begin();
0136 if (currentSectionNo != InSectionNo + 1) {
0137 if (currentSectionNo != sectReportOut) {
0138 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0139 std::cerr << "BAD ORDER OF SECTIONS, reading section " << *SectionTitleIterator << std::endl
0140 << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
0141 << " --------- Please see documentation ---------- " << std::endl;
0142 exit(1);
0143 }
0144 } else {
0145 if (currentSectionNo != sectReportOut) {
0146 InSectionNo++;
0147 }
0148 }
0149 if (currentSectionNo == sectMeasurements) {
0150 SetValueDisplacementsFromReportOut();
0151 }
0152
0153 if (ALIUtils::debug >= 4)
0154 std::cout << std::endl << "START OF SECTION: " << currentSectionNo << " " << *SectionTitleIterator << std::endl;
0155
0156
0157
0158 } else if (currentSectionNo == sectGlobalOptions) {
0159
0160
0161
0162 if (wordlist.size() == 2) {
0163
0164 int isnumber = ALIUtils::IsNumber(wordlist[1]);
0165 if (!isnumber && wordlist[0] != ALIstring("external_meas")) {
0166 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0167 std::cerr << ": EXPECTING A NUMBER, FOUND: " << wordlist[1] << std::endl;
0168 exit(2);
0169 }
0170
0171 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0172 gomgr->setGlobalOption(wordlist[0], ALIUtils::getFloat(wordlist[1]), ALIFileIn::getInstance(Model::SDFName()));
0173
0174
0175
0176 if (ALIUtils::debug >= 1) {
0177 ALIUtils::dumpVS(wordlist, "GLOBAL_OPTION: ", std::cout);
0178 }
0179
0180 } else {
0181 std::cout << "error < 1" << std::endl;
0182 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0183 std::cerr << ": IN GLOBAL_OPTIONS section TWO-WORD LINES ARE EXPECTED " << std::endl;
0184 exit(2);
0185 }
0186
0187
0188 ALIUtils::SetLengthDimensionFactors();
0189 ALIUtils::SetAngleDimensionFactors();
0190 ALIUtils::SetOutputLengthDimensionFactors();
0191 ALIUtils::SetOutputAngleDimensionFactors();
0192
0193
0194
0195 } else if (currentSectionNo == sectParameters ||
0196 currentSectionNo ==
0197 -1) {
0198
0199
0200
0201 if (wordlist.size() == 2) {
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 ParameterMgr* parmgr = ParameterMgr::getInstance();
0214 parmgr->addParameter(wordlist[0], wordlist[1]);
0215
0216 } else if (wordlist.size() == 3) {
0217 if (wordlist[1] != "seed") {
0218 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0219 std::cerr << ": For a three-word parameter line, second has to be 'seed', it is " << wordlist[1]
0220 << std::endl;
0221 exit(1);
0222 }
0223
0224 if (wordlist[0] == "gauss" || wordlist[0] == "flat") {
0225 ParameterMgr::getInstance()->setRandomSeed(ALIUtils::getInt(wordlist[2]));
0226 } else {
0227 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0228 std::cerr << ": For a three-word parameter line, first has to be 'gauss' or 'flat', it is " << wordlist[0]
0229 << std::endl;
0230 exit(1);
0231 }
0232 } else if (wordlist.size() == 4) {
0233 if (wordlist[0] == "gauss") {
0234 ParameterMgr::getInstance()->addRandomGaussParameter(wordlist[1], wordlist[2], wordlist[3]);
0235 } else if (wordlist[0] == "flat") {
0236 ParameterMgr::getInstance()->addRandomFlatParameter(wordlist[1], wordlist[2], wordlist[3]);
0237 } else {
0238 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0239 std::cerr << ": For a four-word parameter line, first has to be 'gauss' or 'flat', it is " << wordlist[0]
0240 << std::endl;
0241 exit(1);
0242 }
0243 } else {
0244 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0245 std::cerr << ": IN PARAMETERS section TWO-WORD-LINES ARE EXPECTED " << std::endl;
0246 ALIUtils::dumpVS(wordlist, " ");
0247 exit(2);
0248 }
0249
0250
0251 if (ALIUtils::debug >= 1) {
0252 ALIUtils::dumpVS(wordlist, "PARAMETERS: ", std::cout);
0253 }
0254
0255
0256
0257 } else if (currentSectionNo == sectSystemTreeDescription) {
0258
0259
0260 std::vector<ALIstring> wordlist2 = wordlist;
0261 std::vector<ALIstring>::iterator vsite;
0262 ALIint wsiz = wordlist.size();
0263 for (ALIint ii = 0; ii < wsiz; ii++) {
0264 wordlist.pop_back();
0265 }
0266
0267 for (vsite = wordlist2.begin(); vsite != wordlist2.end(); ++vsite) {
0268 if (ALIUtils::IsNumber(*vsite)) {
0269 int nOpticalObjects = atoi((*vsite).c_str());
0270
0271 if (nOpticalObjects == 1) {
0272 if (ALIUtils::debug >= 0)
0273 std::cerr << "WARNING: in line " << ALIFileIn::getInstance(Model::SDFName()).nline()
0274 << " number of repeated OpticalObjects = 1. Please avoid the numbering " << std::endl;
0275
0276 } else {
0277
0278 if (vsite + 1 == wordlist.end() || ALIUtils::IsNumber(*(vsite + 1))) {
0279 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0280 std::cerr << "NUMBER SHOULD BE FOLLOWED BY an OpticalObject type" << std::endl;
0281 exit(2);
0282 }
0283
0284
0285
0286
0287 for (ALIint ii = 0; ii < nOpticalObjects - 1; ii++) {
0288
0289 wordlist.push_back(*(vsite + 1));
0290 }
0291 }
0292 } else {
0293
0294 wordlist.push_back(*vsite);
0295 }
0296 }
0297
0298
0299 if (ALIUtils::debug >= 1) {
0300 ALIUtils::dumpVS(wordlist, "SYSTEM TREE DESCRIPTION: before ordering, OBJECT: ", std::cout);
0301 }
0302
0303
0304
0305 if (wordlist[0] == ALIstring("object")) {
0306
0307 std::vector<std::vector<ALIstring> >::iterator vvsite;
0308 for (vvsite = theOptODictionary.begin(); vvsite != theOptODictionary.end(); ++vvsite) {
0309
0310
0311 if (*((*vvsite).begin()) == wordlist[1]) {
0312 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0313 std::cerr << "SYSTEM_TREE_DESCRIPTION: REPEATED object " << *((*vvsite).begin())
0314 << " ( NOT ALLOWED NEITHER WITH EQUAL NOR WITH DIFFERENT COMPONENTS)" << std::endl;
0315 exit(1);
0316 }
0317 }
0318
0319 std::vector<ALIstring> vstemp;
0320 copy(wordlist.begin() + 1, wordlist.end(), back_inserter(vstemp));
0321 Model::OptODictionary().push_back(vstemp);
0322 } else {
0323
0324 if (OptODictionary().empty()) {
0325 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0326 std::cerr << "SYSTEM_TREE_DESCRIPTION section: FIRST LINE SHOULD START WITH 'object'" << std::endl;
0327 exit(2);
0328 }
0329 copy(wordlist.begin(), wordlist.end(), back_inserter(*(OptODictionary().end() - 1)));
0330 }
0331
0332
0333
0334 } else if (currentSectionNo == sectSystemTreeData) {
0335
0336 if (!data_reading) {
0337
0338
0339 std::vector<std::vector<ALIstring> > OptODictionary2;
0340 reorderOptODictionary("system", OptODictionary2);
0341 if (OptODictionary2.empty()) {
0342 std::cerr << "SYSTEM_TREE_DESCRIPTION section: no object 'system' found " << std::endl;
0343 exit(9);
0344 }
0345
0346
0347 std::vector<std::vector<ALIstring> >::const_iterator vvscite, vvscite2;
0348
0349 for (vvscite = theOptODictionary.begin(); vvscite != theOptODictionary.end(); ++vvscite) {
0350 ALIbool ofound = false;
0351 for (vvscite2 = OptODictionary2.begin(); vvscite2 != OptODictionary2.end(); ++vvscite2) {
0352 if (*((*vvscite).begin()) == *((*vvscite2).begin())) {
0353 ofound = true;
0354 break;
0355 }
0356 }
0357 if (!ofound) {
0358 std::cerr << "!!!SYSTEM_TREE_DESCRIPTION section: object " << *((*vvscite).begin())
0359 << " is not hanging from object 'system' " << std::endl;
0360 for (vvscite = OptODictionary().begin(); vvscite != OptODictionary().end(); ++vvscite) {
0361 const std::vector<ALIstring>& ptemp = *vvscite;
0362 ALIUtils::dumpVS(ptemp, "OBJECT ", std::cerr);
0363 }
0364 exit(9);
0365 }
0366 }
0367 theOptODictionary = OptODictionary2;
0368
0369 data_reading = 1;
0370
0371
0372 if (ALIUtils::debug >= 3) {
0373 std::vector<std::vector<ALIstring> >::iterator itevs;
0374 for (itevs = OptODictionary().begin(); itevs != OptODictionary().end(); ++itevs) {
0375 std::vector<ALIstring> ptemp = *itevs;
0376 ALIUtils::dumpVS(ptemp, " SYSTEM TREE DESCRIPTION: after ordering: OBJECT ", std::cout);
0377 }
0378 }
0379
0380
0381
0382 if (wordlist[0] != "system") {
0383 std::cerr << "SYSTEM_TREE_DATA section: object 'system' is not the first one " << std::endl;
0384 exit(9);
0385 }
0386
0387 OpticalObject* OptOsystem = new OpticalObject(nullptr, "system", wordlist[1], false);
0388 OptOsystem->construct();
0389
0390
0391 theOptOList.push_back(OptOsystem);
0392
0393 } else {
0394
0395 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0396 std::cerr << " STILL SOME LINES AFTER ALL SYSTEM TREE IS READ!!!" << std::endl;
0397 exit(9);
0398 }
0399
0400
0401
0402 } else if (currentSectionNo == sectMeasurements) {
0403
0404 Measurement* meastemp = nullptr;
0405 ALIstring measType = wordlist[0];
0406 ALIstring measName;
0407 if (wordlist.size() == 2) {
0408 measName = wordlist[1];
0409 wordlist.pop_back();
0410 } else {
0411 measName = "";
0412 }
0413 if (measType == ALIstring("SENSOR2D")) {
0414 meastemp = new MeasurementSensor2D(2, measType, measName);
0415 meastemp->setConversionFactor(wordlist);
0416 meastemp->construct();
0417 } else if (measType == ALIstring("DISTANCEMETER3DIM")) {
0418 meastemp = new MeasurementDistancemeter3dim(1, measType, measName);
0419 meastemp->setConversionFactor(wordlist);
0420 meastemp->construct();
0421 } else if (measType == ALIstring("DISTANCEMETER") || measType == ALIstring("DISTANCEMETER1DIM")) {
0422 meastemp = new MeasurementDistancemeter(1, measType, measName);
0423 meastemp->setConversionFactor(wordlist);
0424 meastemp->construct();
0425 } else if (measType == ALIstring("TILTMETER")) {
0426 meastemp = new MeasurementTiltmeter(1, measType, measName);
0427 meastemp->setConversionFactor(wordlist);
0428 meastemp->construct();
0429 } else if (measType == ALIstring("COPS")) {
0430 meastemp = new MeasurementCOPS(4, measType, measName);
0431 meastemp->setConversionFactor(wordlist);
0432 meastemp->construct();
0433 } else if (measType == ALIstring("DIFFENTRY")) {
0434 meastemp = new MeasurementDiffEntry(1, measType, measName);
0435 meastemp->construct();
0436 } else if (measType == ALIstring("measurements_from_file") || measType == ALIstring("@measurements_from_file")) {
0437 new CocoaDaqReaderText(wordlist[1]);
0438
0439
0440 if (wordlist.size() == 4) {
0441 Measurement::only1 = true;
0442 Measurement::only1Date = wordlist[2];
0443 Measurement::only1Time = wordlist[3];
0444
0445 }
0446 } else if (measType == ALIstring("measurements_from_file_ROOT") ||
0447 measType == ALIstring("@measurements_from_file")) {
0448 new CocoaDaqReaderRoot(wordlist[1]);
0449 } else if (wordlist[0] == ALIstring("correlations_from_file") ||
0450 wordlist[0] == ALIstring("@correlations_from_file")) {
0451 ErrorCorrelationMgr::getInstance()->readFromReportFile(wordlist[1]);
0452 } else if (wordlist[0] == ALIstring("copy_measurements") || wordlist[0] == ALIstring("@copy_measurements")) {
0453 copyMeasurements(wordlist);
0454
0455
0456 } else if (wordlist[0] == ALIstring("fittedEntries_from_file")) {
0457 theFittedEntriesReader = new FittedEntriesReader(wordlist[1]);
0458 if (ALIUtils::debug >= 2)
0459 std::cout << " setting fittedEntries_from_file " << wordlist[0] << " == " << wordlist[1] << std::endl;
0460 } else {
0461 std::cerr << "Measurement:" << std::endl;
0462 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0463 std::cerr << "!!! type of measurement not allowed: " << wordlist[0] << std::endl;
0464 std::cerr << " Allowed types: SENSOR2D, DISTANCEMETER, DISTANCEMETER1DIM, TILTMETER, COPS, DIFFENTRY "
0465 << std::endl;
0466 exit(2);
0467 }
0468
0469
0470
0471 } else if (currentSectionNo == sectReportOut) {
0472
0473 if (InSectionNo + 1 != sectParameters) {
0474 ALIFileIn::getInstance(Model::SDFName()).ErrorInLine();
0475 std::cerr << "BAD ORDER OF SECTIONS, reading section " << *SectionTitleIterator << std::endl
0476 << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
0477 << " --------- Please see documentation ---------- " << std::endl;
0478 exit(1);
0479 }
0480
0481 EntryMgr::getInstance()->readEntryFromReportOut(wordlist);
0482 }
0483 }
0484
0485
0486
0487
0488 if (ALIUtils::debug >= 2)
0489 std::cout << std::endl << "@@@@ Building Measurements links to OptOs" << std::endl;
0490 Model::buildMeasurementsLinksToOptOs();
0491
0492 if (ALIUtils::debug >= 1) {
0493 std::cout << "---------- SYSTEM SUCCESFULLY READ ----------" << std::endl << std::endl;
0494 }
0495 filein.close();
0496
0497 return;
0498 }
0499
0500
0501
0502
0503
0504 void Model::reorderOptODictionary(const ALIstring& ssearch, std::vector<std::vector<ALIstring> >& OptODictionary2) {
0505
0506 std::vector<std::vector<ALIstring> >::iterator vvsite;
0507 std::vector<ALIstring>::iterator vsite;
0508
0509
0510 for (vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
0511 if (*((*vvsite).begin()) == ssearch) {
0512
0513 OptODictionary2.push_back(*vvsite);
0514
0515
0516
0517
0518
0519
0520 for (vsite = (*vvsite).begin() + 1; vsite != (*vvsite).end(); ++vsite) {
0521 reorderOptODictionary(*vsite, OptODictionary2);
0522 }
0523 break;
0524 }
0525 }
0526
0527
0528
0529
0530
0531
0532 }
0533
0534
0535
0536
0537 void Model::buildMeasurementsLinksToOptOs() {
0538
0539 std::vector<Measurement*>::const_iterator vmcite;
0540 for (vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); ++vmcite) {
0541
0542
0543
0544
0545
0546 }
0547 }
0548
0549
0550
0551
0552 ALIint Model::getParameterValue(const ALIstring& sstr, ALIdouble& val) {
0553 ParameterMgr* parmgr = ParameterMgr::getInstance();
0554 ALIint iret = parmgr->getParameterValue(sstr, val);
0555
0556 return iret;
0557 }
0558
0559
0560
0561
0562 OpticalObject* Model::getOptOByName(const ALIstring& opto_name) {
0563
0564 std::vector<OpticalObject*>::const_iterator vocite;
0565 for (vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
0566 if ((*vocite)->name() == opto_name)
0567 break;
0568 }
0569
0570 if (vocite == OptOList().end()) {
0571
0572 std::cerr << " LIST OF OpticalObjects " << std::endl;
0573 for (vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
0574 std::cerr << (*vocite)->name() << std::endl;
0575 }
0576 std::cerr << "!!EXITING at getOptOByName: Optical Object " << opto_name << " doesn't exist!!" << std::endl;
0577 exit(4);
0578
0579 } else {
0580
0581 if (ALIUtils::debug > 999) {
0582 std::cout << opto_name.c_str() << "SSOptOitem" << (*vocite) << (*vocite)->name() << "len" << OptOList().size()
0583 << std::endl;
0584 }
0585 return (*vocite);
0586 }
0587 }
0588
0589
0590
0591
0592
0593 OpticalObject* Model::getOptOByType(const ALIstring& opto_type) {
0594
0595 std::vector<OpticalObject*>::const_iterator vocite;
0596 for (vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
0597
0598 if ((*vocite)->type() == opto_type)
0599 break;
0600 }
0601
0602 if (vocite == OptOList().end()) {
0603
0604 std::cerr << "!!EXITING at getOptOByType: Optical Object " << opto_type << " doesn't exist!!" << std::endl;
0605 exit(4);
0606 } else {
0607
0608 return (*vocite);
0609 }
0610 }
0611
0612
0613
0614
0615 Entry* Model::getEntryByName(const ALIstring& opto_name, const ALIstring& entry_name) {
0616
0617 std::vector<Entry*>::const_iterator vecite;
0618 for (vecite = EntryList().begin(); vecite != EntryList().end(); ++vecite) {
0619 if (ALIUtils::debug >= 4)
0620 std::cout << "getEntryByName: " << (*vecite)->OptOCurrent()->name() << " E " << (*vecite)->name()
0621 << " Searching: " << opto_name << " E " << entry_name << std::endl;
0622
0623 if ((*vecite)->OptOCurrent()->name() == opto_name && (*vecite)->name() == entry_name) {
0624 return *vecite;
0625 }
0626 }
0627
0628 std::cerr << "!!!EXITING at getEntryByName: Entry name not found:" << opto_name << " " << entry_name << std::endl;
0629 exit(1);
0630 }
0631
0632
0633 Measurement* Model::getMeasurementByName(const ALIstring& meas_name, ALIbool exists) {
0634
0635 std::vector<Measurement*>::const_iterator vmcite;
0636 for (vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); ++vmcite) {
0637 if ((*vmcite)->name() == meas_name)
0638 break;
0639 }
0640
0641 if (vmcite != theMeasurementVector.end()) {
0642
0643 return (*vmcite);
0644 } else {
0645 if (exists) {
0646
0647 std::cerr << " LIST OF Measurements " << std::endl;
0648 for (vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); ++vmcite) {
0649 std::cerr << (*vmcite)->name() << std::endl;
0650 }
0651 std::cerr << "!!EXITING at getMeasurementByName: Measurement " << meas_name << " doesn't exist!!" << std::endl;
0652 abort();
0653
0654 } else {
0655 return nullptr;
0656 }
0657 }
0658 }
0659
0660
0661
0662
0663
0664
0665
0666 ALIbool Model::getComponentOptOTypes(const ALIstring& opto_type, std::vector<ALIstring>& vcomponents) {
0667
0668 std::vector<ALIstring>::iterator vsite;
0669 for (vsite = vcomponents.begin(); vsite != vcomponents.end(); ++vsite) {
0670 vcomponents.pop_back();
0671 }
0672
0673
0674 ALIint ALIstring_found = 0;
0675 std::vector<std::vector<ALIstring> >::iterator vvsite;
0676 for (vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
0677 if (*((*vvsite).begin()) == opto_type) {
0678 ALIstring_found = 1;
0679
0680 vcomponents = *vvsite;
0681 vcomponents.erase(vcomponents.begin());
0682 break;
0683 }
0684 }
0685
0686 if (ALIstring_found) {
0687 return true;
0688 } else {
0689 return false;
0690 }
0691 }
0692
0693
0694
0695
0696
0697 ALIbool Model::getComponentOptOs(const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents) {
0698
0699 std::vector<OpticalObject*>::iterator voite;
0700 for (voite = vcomponents.begin(); voite != vcomponents.end(); ++voite) {
0701 vcomponents.pop_back();
0702 }
0703
0704
0705 OpticalObject* opto = getOptOByName(opto_name);
0706
0707 if (ALIUtils::debug >= 99)
0708 std::cout << opto_name << "getComponentOptOs: opto " << opto << opto->name() << std::endl;
0709 std::vector<OpticalObject*>::const_iterator vocite;
0710
0711 if (ALIUtils::debug >= 99)
0712 std::cout << "optolist size " << OptOList().size() << std::endl;
0713 ALIbool opto_found = false;
0714 for (vocite = OptOList().begin(); vocite != OptOList().end(); ++vocite) {
0715 if ((*vocite)->parent() != nullptr) {
0716
0717 if ((*vocite)->parent()->name() == opto_name) {
0718 opto_found = true;
0719 vcomponents.push_back((*vocite));
0720 }
0721 }
0722 }
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735 return opto_found;
0736 }
0737
0738
0739
0740
0741
0742 ALIbool Model::createCopyComponentList(const ALIstring& typ) {
0743
0744 if (ALIUtils::debug >= 3)
0745 std::cout << "createCopyComponentList " << typ << std::endl;
0746 OpticalObject* start_opto = getOptOByType(typ);
0747
0748
0749 theOptOsToCopyList.erase(theOptOsToCopyList.begin(), theOptOsToCopyList.end());
0750
0751
0752 fillCopyComponentList(start_opto);
0753
0754
0755 theOptOsToCopyListIterator = theOptOsToCopyList.begin();
0756 return true;
0757 }
0758
0759
0760
0761
0762 ALIbool Model::fillCopyComponentList(const OpticalObject* opto) {
0763 if (ALIUtils::debug >= 3)
0764 std::cout << "entering fillCopyComponentList(): OptO" << opto->name() << std::endl;
0765
0766 std::vector<OpticalObject*> vopto;
0767 ALIbool opto_found = getComponentOptOs(opto->name(), vopto);
0768 if (!opto_found) {
0769 if (ALIUtils::debug >= 5)
0770 std::cout << "fillCopyComponentList: NO COMPONENTS TO COPY IN THIS OptO" << opto->name() << std::endl;
0771 }
0772
0773
0774 std::vector<OpticalObject*>::const_iterator vocite;
0775 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
0776 theOptOsToCopyList.push_back(*vocite);
0777 if (ALIUtils::debug >= 5)
0778 std::cout << "fillCopyOptOList " << (*vocite)->type() << " " << (*vocite)->name() << std::endl;
0779
0780 fillCopyComponentList(*vocite);
0781 }
0782 return opto_found;
0783 }
0784
0785
0786
0787
0788 OpticalObject* Model::nextOptOToCopy() {
0789 if (ALIUtils::debug >= 5)
0790 std::cout << "entering nextOptOToCopy() " << std::endl;
0791 ++theOptOsToCopyListIterator;
0792
0793 return *(theOptOsToCopyListIterator - 1);
0794 }
0795
0796
0797
0798
0799
0800 void Model::CMSLinkFit(ALIint cmslink) {
0801
0802
0803
0804
0805
0806
0807
0808
0809
0810
0811
0812
0813
0814
0815
0816
0817
0818
0819
0820
0821
0822
0823
0824
0825
0826
0827
0828
0829
0830
0831
0832
0833
0834
0835
0836
0837
0838
0839
0840
0841
0842
0843
0844
0845
0846
0847
0848
0849
0850 }
0851
0852
0853
0854
0855
0856 void Model::CMSLinkCleanModel() {
0857 deleteOptO("s");
0858
0859 ALIuint odsize = theOptODictionary.size();
0860 for (ALIuint ii = 0; ii < odsize; ii++) {
0861 theOptODictionary.pop_back();
0862 }
0863 }
0864
0865
0866
0867
0868 void Model::CMSLinkDeleteOptOs() {
0869 ALIint cmslink_iter = Model::CMSLinkIteration;
0870 ALIdouble cmslink_method;
0871
0872 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
0873 assert(gomgr->getGlobalOptionValue("cms_link_method", cmslink_method));
0874 ALIdouble cmslink_halfplanes;
0875 assert(gomgr->getGlobalOptionValue("cms_link_halfplanes", cmslink_halfplanes));
0876 if (ALIUtils::debug >= 2)
0877 std::cout << "CMSLinkDeleteOptOs: cms_link_halfplanes " << cmslink_halfplanes << cmslink_iter << std::endl;
0878
0879 if (cmslink_iter == 1) {
0880
0881
0882
0883 deleteOptO("s/mabsL");
0884
0885 if (cmslink_method == 1) {
0886 deleteOptO("s/tracker/det_trkDL");
0887 deleteOptO("s/tracker/det_trkDR");
0888 }
0889
0890 if (cmslink_halfplanes == 2) {
0891
0892 deleteOptO("s/mabsR");
0893 }
0894
0895 } else if (cmslink_iter == 2) {
0896
0897
0898 deleteOptO("s/mabsL");
0899 deleteOptO("s/tracker/CST/wheel_trkL/peri/mirror");
0900 deleteOptO("s/tracker/CST/wheel_trkL/det_trkU");
0901
0902
0903
0904 if (cmslink_halfplanes <= 1) {
0905 deleteOptO("s/tracker/CST/wheel_trkR");
0906 } else if (cmslink_halfplanes == 2) {
0907
0908 deleteOptO("s/mabsR");
0909 deleteOptO("s/tracker/CST/wheel_trkR/peri/mirror");
0910 deleteOptO("s/tracker/CST/wheel_trkR/det_trkU");
0911 }
0912
0913 } else if (cmslink_iter == 3) {
0914
0915
0916 deleteOptO("s/tracker");
0917
0918 if (cmslink_halfplanes == 2) {
0919
0920 }
0921
0922 } else {
0923 }
0924 }
0925
0926
0927
0928
0929 void Model::CMSLinkSaveParamFittedSigma(ALIint cms_link) {
0930
0931
0932
0933
0934
0935
0936
0937
0938
0939
0940
0941
0942
0943
0944
0945
0946
0947
0948
0949
0950
0951
0952
0953
0954
0955
0956
0957
0958
0959
0960
0961
0962
0963
0964
0965
0966
0967
0968
0969
0970
0971
0972
0973
0974
0975
0976
0977
0978
0979
0980
0981
0982
0983
0984
0985
0986
0987 }
0988
0989
0990
0991
0992 void Model::CMSLinkSaveParamFittedValueDisplacement(ALIint cms_link) {
0993
0994
0995
0996
0997
0998
0999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012 }
1013
1014
1015
1016
1017 void Model::CMSLinkRecoverParamFittedSigma(ALIint cms_link) {
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071 }
1072
1073
1074
1075
1076 void Model::CMSLinkRecoverParamFittedValueDisplacement(ALIint cms_link) {
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097 }
1098
1099
1100
1101
1102 void Model::deleteOptO(const ALIstring& opto_name) {
1103 OpticalObject* opto = getOptOByName(opto_name);
1104 deleteOptO(opto);
1105 }
1106
1107
1108
1109
1110 void Model::deleteOptO(OpticalObject* opto) {
1111 if (ALIUtils::debug >= 5)
1112 std::cout << "DELETING OptO" << opto->name() << std::endl;
1113
1114
1115 std::vector<Entry*>::const_iterator vecite;
1116 std::vector<Entry*>::iterator veite2;
1117 if (ALIUtils::debug >= 9)
1118 std::cout << "SIZE" << theEntryVector.size() << std::endl;
1119 for (vecite = opto->CoordinateEntryList().begin(); vecite != opto->CoordinateEntryList().end(); ++vecite) {
1120
1121 veite2 = find(theEntryVector.begin(), theEntryVector.end(), (*vecite));
1122
1123 delete ((*veite2));
1124 theEntryVector.erase(veite2);
1125 }
1126
1127 for (vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); ++vecite) {
1128
1129 veite2 = find(theEntryVector.begin(), theEntryVector.end(), (*vecite));
1130
1131 delete ((*veite2));
1132 theEntryVector.erase(veite2);
1133 }
1134
1135 for (vecite = theEntryVector.begin(); vecite != theEntryVector.end(); ++vecite) {
1136
1137 }
1138
1139
1140 std::vector<Measurement*> MeasToBeDeleted;
1141 std::vector<Measurement*>::const_iterator vmite;
1142 std::vector<OpticalObject*>::const_iterator vocite;
1143 for (vmite = MeasurementList().begin(); vmite != MeasurementList().end(); ++vmite) {
1144 if (ALIUtils::debug >= 5)
1145 std::cout << "Deleting Measurement" << (*vmite)->name() << std::endl;
1146
1147 for (vocite = (*vmite)->OptOList().begin(); vocite != (*vmite)->OptOList().end(); ++vocite) {
1148 if ((*vocite) == opto) {
1149
1150 MeasToBeDeleted.push_back(*vmite);
1151
1152 break;
1153 }
1154 }
1155 }
1156
1157
1158 std::vector<Measurement*>::const_iterator vmcite;
1159 std::vector<Measurement*>::iterator vmite2;
1160 if (ALIUtils::debug >= 9)
1161 std::cout << "SIZEMEAS" << MeasToBeDeleted.size() << std::endl;
1162 for (vmcite = MeasToBeDeleted.begin(); vmcite != MeasToBeDeleted.end(); ++vmcite) {
1163 vmite2 = find(theMeasurementVector.begin(), theMeasurementVector.end(), (*vmcite));
1164
1165 delete ((*vmite2));
1166 theMeasurementVector.erase(vmite2);
1167 }
1168
1169
1170
1171 std::vector<OpticalObject*> vopto;
1172
1173 for (vocite = vopto.begin(); vocite != vopto.end(); ++vocite) {
1174 deleteOptO(*vocite);
1175 }
1176
1177
1178
1179
1180
1181
1182 std::vector<OpticalObject*>::iterator dvoite =
1183 find(theOptOList.begin(), theOptOList.end(), std::vector<OpticalObject*>::value_type(opto));
1184
1185 theOptOList.erase(dvoite);
1186 delete opto;
1187 }
1188
1189
1190
1191
1192 void Model::saveParamFittedSigma(const ALIstring& opto_name, const ALIstring& entry_name) {
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206 }
1207
1208
1209
1210
1211 void Model::saveParamFittedCorrelation(const ALIstring& opto_name1,
1212 const ALIstring& entry_name1,
1213 const ALIstring& opto_name2,
1214 const ALIstring& entry_name2) {
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243 }
1244
1245
1246
1247
1248 void Model::recoverParamFittedSigma(const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position) {
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262 }
1263
1264
1265
1266
1267 ALIdouble Model::getParamFittedSigmaVectorItem(const ALIuint position) {
1268 if (position >= theParamFittedSigmaVector.size()) {
1269 std::cerr << "!!EXITING at getParamFittedSigma: position" << position
1270 << " bigger than dimension of theParamFittedSigmaVector " << theParamFittedSigmaVector.size()
1271 << std::endl;
1272 exit(3);
1273 }
1274 std::vector<ALIdouble>::const_iterator vdcite = theParamFittedSigmaVector.begin() + position;
1275 return (*vdcite);
1276 }
1277
1278
1279
1280
1281 ALIbool Model::readMeasurementsFromFile(ALIstring only1Date, ALIstring only1Time) {
1282 if (ALIUtils::debug >= 5)
1283 std::cout << " readMeasurementsFromFile " << Measurement::measurementsFileName() << std::endl;
1284 if (Measurement::measurementsFileName().empty())
1285 return true;
1286
1287 ALIFileIn& filein = ALIFileIn::getInstance(Measurement::measurementsFileName());
1288 std::vector<ALIstring> wordlist;
1289
1290
1291
1292
1293 if (filein.getWordsInLine(wordlist) == 0) {
1294 if (ALIUtils::debug >= 4)
1295 std::cout << "@@@@ No more measurements left" << std::endl;
1296 return false;
1297 }
1298
1299
1300
1301
1302
1303
1304 if (Measurement::only1) {
1305 for (;;) {
1306 if (wordlist[0] == "DATE:" && wordlist[1] == Measurement::only1Date && wordlist[2] == Measurement::only1Time)
1307 break;
1308 filein.getWordsInLine(wordlist);
1309 if (filein.eof()) {
1310 std::cerr << "!! EXITING date not found in measurements file" << Measurement::only1Date << " "
1311 << Measurement::only1Time << std::endl;
1312 exit(1);
1313 }
1314 }
1315 }
1316
1317
1318 if (wordlist[0] == "DATE:") {
1319 Measurement::setCurrentDate(wordlist);
1320 }
1321
1322
1323 ALIint nMeas = Model::MeasurementList().size();
1324 if (ALIUtils::debug >= 4) {
1325 std::cout << " Reading " << nMeas << " measurements from file " << Measurement::measurementsFileName()
1326 << " DATE: " << wordlist[1] << " " << wordlist[1] << std::endl;
1327 }
1328 ALIint ii;
1329 for (ii = 0; ii < nMeas; ii++) {
1330 filein.getWordsInLine(wordlist);
1331 if (wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") ||
1332 wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") ||
1333 wordlist[0] == ALIstring("COPS")) {
1334 if (wordlist.size() != 2) {
1335 std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of "
1336 << wordlist.size() << std::endl;
1337 ALIUtils::dumpVS(wordlist, " ");
1338 exit(1);
1339 }
1340 std::vector<Measurement*>::const_iterator vmcite;
1341 for (vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); ++vmcite) {
1342
1343
1344
1345
1346
1347
1348
1349 ALIint fcolon = (*vmcite)->name().find(':');
1350 ALIstring oname = (*vmcite)->name();
1351 oname = oname.substr(fcolon + 1, oname.length());
1352
1353 if (oname == wordlist[1]) {
1354
1355 if ((*vmcite)->type() != wordlist[0]) {
1356 std::cerr << "!!! Reading measurement from file: type in file is " << wordlist[0] << " and should be "
1357 << (*vmcite)->type() << std::endl;
1358 exit(1);
1359 }
1360 Measurement* meastemp = *vmcite;
1361
1362 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
1363 ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
1364
1365 for (ALIuint ii = 0; ii < meastemp->dim(); ii++) {
1366 filein.getWordsInLine(wordlist);
1367 ALIdouble sigma = 0.;
1368 if (!sigmaFF) {
1369
1370 const ALIdouble* sigmav = meastemp->sigma();
1371 sigma = sigmav[ii];
1372 }
1373
1374 if (meastemp->valueType(ii) != wordlist[0]) {
1375 filein.ErrorInLine();
1376 std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0]
1377 << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
1378 exit(1);
1379 }
1380 meastemp->fillData(ii, wordlist);
1381 if (!sigmaFF) {
1382 meastemp->setSigma(ii, sigma);
1383 }
1384 }
1385 meastemp->correctValueAndSigma();
1386 break;
1387 }
1388 }
1389 if (vmcite == MeasurementList().end()) {
1390 for (vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); ++vmcite) {
1391 std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
1392 }
1393 std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is " << wordlist[1]
1394 << std::endl;
1395 exit(1);
1396 }
1397 } else {
1398 std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
1399 << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
1400 exit(1);
1401 }
1402 }
1403
1404
1405 return true;
1406 }
1407
1408
1409
1410
1411 void Model::copyMeasurements(const std::vector<ALIstring>& wl) {
1412
1413
1414
1415
1416 std::string subsstr1 = wl[1].substr(0, wl[1].find('/'));
1417 std::string subsstr2 = wl[1].substr(wl[1].find('/') + 1, wl[1].rfind('/') - wl[1].find('/') - 1);
1418 std::string querystr = wl[1].substr(wl[1].rfind('/') + 1, wl[1].length());
1419
1420 std::cout << " Model::copyMeasurements "
1421 << " subsstr1 " << subsstr1 << " subsstr2 " << subsstr2 << " querystr " << querystr << std::endl;
1422
1423 std::vector<Measurement*> measToCopy;
1424 std::vector<Measurement*>::iterator mite;
1425 for (mite = theMeasurementVector.begin(); mite != theMeasurementVector.end(); ++mite) {
1426 Measurement* meas = (*mite);
1427
1428 if (meas->name().find(querystr) != std::string::npos) {
1429 measToCopy.push_back(meas);
1430 }
1431 }
1432
1433
1434 Measurement* meastemp = nullptr;
1435 for (mite = measToCopy.begin(); mite != measToCopy.end(); ++mite) {
1436 Measurement* meas = (*mite);
1437 std::vector<ALIstring> wlt;
1438 wlt.push_back(meas->type());
1439
1440
1441 std::string newName = ALIUtils::changeName(meas->name(), subsstr1, subsstr2);
1442 std::cout << " newName " << newName << std::endl;
1443 wlt.push_back(newName);
1444
1445 ALIstring measType = wlt[0];
1446 ALIstring measName;
1447 if (wlt.size() == 2) {
1448 measName = wlt[1];
1449 } else {
1450 measName = "";
1451 }
1452 if (meas->type() == ALIstring("SENSOR2D")) {
1453 meastemp = new MeasurementSensor2D(2, measType, measName);
1454
1455
1456 } else if (meas->type() == ALIstring("DISTANCEMETER") || meas->type() == ALIstring("DISTANCEMETER1DIM")) {
1457 meastemp = new MeasurementDistancemeter(1, measType, measName);
1458 } else if (meas->type() == ALIstring("TILTMETER")) {
1459 meastemp = new MeasurementTiltmeter(1, measType, measName);
1460
1461
1462
1463
1464 } else if (meas->type() == ALIstring("DIFFENTRY")) {
1465 meastemp = new MeasurementDiffEntry(1, measType, measName);
1466 } else if (meas->type() == ALIstring("COPS")) {
1467 meastemp = new MeasurementCOPS(4, measType, measName);
1468 } else {
1469 throw cms::Exception("LogicError") << "@SUB=Model::copyMeasurements\n"
1470 << "unknown measurement type: " << meas->type();
1471 }
1472
1473
1474 meastemp->copyMeas(meas, subsstr1, subsstr2);
1475
1476 break;
1477 }
1478 }
1479
1480
1481 void Model::SetValueDisplacementsFromReportOut() {
1482 if (ALIUtils::debug >= 3)
1483 std::cout << " Model::SetValueDisplacementsFromReportOut() " << std::endl;
1484
1485 EntryMgr* entryMgr = EntryMgr::getInstance();
1486
1487 if (entryMgr->numberOfEntries() != 0) {
1488 EntryData* entryData;
1489
1490 std::vector<Entry*>::const_iterator vecite;
1491 for (vecite = Model::EntryList().begin(); vecite != Model::EntryList().end(); ++vecite) {
1492
1493 entryData = entryMgr->findEntryByLongName((*vecite)->OptOCurrent()->longName(), (*vecite)->name());
1494 if (ALIUtils::debug >= 3)
1495 std::cout << "SetValueDisplacementsFromReportOut " << (*vecite)->OptOCurrent()->longName() << " "
1496 << (*vecite)->name() << " " << entryData->valueDisplacement() << std::endl;
1497 (*vecite)->addFittedDisplacementToValue(entryData->valueDisplacement());
1498 }
1499 }
1500 }
1501
1502
1503 std::string Model::printCocoaStatus(const cocoaStatus cs) {
1504 std::string str = "";
1505
1506 if (cs == COCOA_Init) {
1507 str = "COCOA_Init ";
1508 } else if (cs == COCOA_ReadingModel) {
1509 str = "COCOA_ReadingModel";
1510 } else if (cs == COCOA_InitFit) {
1511 str = "COCOA_InitFit";
1512 } else if (cs == COCOA_FitOK) {
1513 str = "COCOA_FitOK";
1514 } else if (cs == COCOA_FitImproving) {
1515 str = "COCOA_FitImproving";
1516 } else if (cs == COCOA_FitCannotImprove) {
1517 str = "COCOA_FitCannotImprove";
1518 } else if (cs == COCOA_FitChi2Worsened) {
1519 str = "COCOA_FitChi2Worsened";
1520 } else if (cs == COCOA_FitMatrixNonInversable) {
1521 str = "COCOA_FitMatrixNonInversable";
1522 }
1523
1524 return str;
1525 }
1526
1527
1528 void Model::BuildSystemDescriptionFromOA(OpticalAlignments& optAlig) {
1529 theOpticalAlignments = optAlig.opticalAlignments();
1530
1531 OpticalAlignInfo oai_system = FindOptAlignInfoByType("system");
1532
1533 OpticalObject* OptOsystem = new OpticalObject(nullptr, "system", oai_system.name_, false);
1534
1535 OptOsystem->constructFromOptAligInfo(oai_system);
1536
1537
1538
1539 theOptOList.push_back(OptOsystem);
1540 }
1541
1542
1543 OpticalAlignInfo Model::FindOptAlignInfoByType(const ALIstring& type) {
1544 OpticalAlignInfo oai;
1545
1546 ALIbool bFound = false;
1547 std::vector<OpticalAlignInfo>::iterator ite;
1548 for (ite = theOpticalAlignments.begin(); ite != theOpticalAlignments.end(); ++ite) {
1549
1550 if ((*ite).type_ == type) {
1551 if (!bFound) {
1552 oai = *ite;
1553 bFound = true;
1554 } else {
1555 std::cerr << "!! WARNING: Model::FindOptAlignInfoByType more than one objects of type " << type << std::endl;
1556 std::cerr << " returning object " << oai.name_ << std::endl << " skipping object " << (*ite).name_ << std::endl;
1557 }
1558 }
1559 }
1560 if (!bFound) {
1561 std::cerr << "!! ERROR: Model::FindOptAlignInfoByType object not found, of type " << type << std::endl;
1562 std::exception();
1563 }
1564
1565 return oai;
1566 }
1567
1568
1569 void Model::BuildMeasurementsFromOA(OpticalAlignMeasurements& measList) {
1570 std::vector<OpticalAlignMeasurementInfo>::iterator mite;
1571
1572 if (ALIUtils::debug >= 5)
1573 std::cout << " BuildMeasurementsFromOA " << std::endl;
1574 std::vector<OpticalAlignMeasurementInfo> measInfos = measList.oaMeasurements_;
1575 for (mite = measInfos.begin(); mite != measInfos.end(); ++mite) {
1576 std::string measType = (*mite).type_;
1577 std::string measName = (*mite).name_;
1578 if (ALIUtils::debug >= 4)
1579 std::cout << " BuildMeasurementsFromOA measType " << measType << " measName " << measName << std::endl;
1580
1581 Measurement* meastemp = nullptr;
1582 if (measType == ALIstring("SENSOR2D")) {
1583 meastemp = new MeasurementSensor2D(2, measType, measName);
1584 } else if (measType == ALIstring("DISTANCEMETER3DIM")) {
1585 meastemp = new MeasurementDistancemeter3dim(1, measType, measName);
1586 } else if (measType == ALIstring("DISTANCEMETER") || measType == ALIstring("DISTANCEMETER1DIM")) {
1587 meastemp = new MeasurementDistancemeter(1, measType, measName);
1588 } else if (measType == ALIstring("TILTMETER")) {
1589 meastemp = new MeasurementTiltmeter(1, measType, measName);
1590 } else if (measType == ALIstring("COPS")) {
1591 meastemp = new MeasurementCOPS(4, measType, measName);
1592
1593
1594
1595
1596 } else if (measType == ALIstring("DIFFENTRY")) {
1597 meastemp = new MeasurementDiffEntry(1, measType, measName);
1598 } else {
1599 std::cerr << " !!! Model::BuildMeasurementsFromOA : measType not found " << measType << std::endl;
1600 throw std::exception();
1601 }
1602 meastemp->constructFromOA(*mite);
1603 }
1604 }