00001
00002
00003
00004
00005
00006
00007
00008 #include "Alignment/CocoaModel/interface/Model.h"
00009
00010 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
00011 #include "Alignment/CocoaUtilities/interface/GlobalOptionMgr.h"
00012 #include "Alignment/CocoaModel/interface/OpticalObject.h"
00013 #include "Alignment/CocoaModel/interface/Measurement.h"
00014 #include "Alignment/CocoaModel/interface/MeasurementSensor2D.h"
00015 #include "Alignment/CocoaModel/interface/MeasurementDistancemeter.h"
00016 #include "Alignment/CocoaModel/interface/MeasurementDistancemeter3dim.h"
00017 #include "Alignment/CocoaModel/interface/MeasurementTiltmeter.h"
00018 #include "Alignment/CocoaModel/interface/MeasurementCOPS.h"
00019 #include "Alignment/CocoaModel/interface/MeasurementDiffEntry.h"
00020 #include "Alignment/CocoaModel/interface/CocoaDaqReaderText.h"
00021
00022
00023 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00024 #include "Alignment/CocoaModel/interface/EntryAngle.h"
00025 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
00026 #include "Alignment/CocoaModel/interface/ErrorCorrelationMgr.h"
00027
00028 #include "Alignment/CocoaModel/interface/EntryMgr.h"
00029 #include "Alignment/CocoaModel/interface/EntryData.h"
00030 #include "Alignment/CocoaModel/interface/FittedEntriesReader.h"
00031
00032 #include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h"
00033 #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h"
00034
00035 #include <stdlib.h>
00036 #include <ctype.h>
00037
00038 #include <assert.h>
00039 #include <time.h>
00040
00041 #include <algorithm>
00042
00043 #ifdef OS_OSPACE_STD_NAMESPACE
00044 using namespace os_std;
00045 #endif
00046
00047
00048
00049
00050
00051 Model* Model::theInstance = 0;
00052
00053 std::vector< std::vector<ALIstring> > Model::theOptODictionary;
00054
00055
00056
00057 std::vector< OpticalObject* > Model::theOptOList;
00058 std::vector<Entry*> Model::theEntryVector;
00059 std::vector<Measurement*> Model::theMeasurementVector;
00060 std::vector<ALIdouble> Model::theParamFittedSigmaVector;
00061 std::map<ALIstring, ALIdouble, std::less<ALIstring> > Model::theParamFittedValueDisplacementMap;
00062 std::vector<OpticalObject*> Model::theOptOsToCopyList;
00063 std::vector<OpticalObject*>::const_iterator Model::theOptOsToCopyListIterator;
00064 ALIint Model::CMSLinkIteration = 0;
00065 ALIint Model::Ncmslinkrange = 0;
00066 std::vector<ALIdouble> Model::CMSLinkRangeDetValue;
00067 ALIstring Model::theSDFName = "SystemDescription.txt";
00068 ALIstring Model::theMeasFName = "Measurements.txt";
00069 ALIstring Model::theReportFName = "report.out";
00070 ALIstring Model::theMatricesFName = "matrices.out";
00071
00072
00073 cocoaStatus Model::theCocoaStatus = COCOA_Init;
00074 FittedEntriesReader* Model::theFittedEntriesReader = 0;
00075 std::vector<OpticalAlignInfo> Model::theOpticalAlignments;
00076
00077
00078
00079
00080 Model& Model::getInstance()
00081 {
00082 if(!theInstance) {
00083 theInstance = new Model;
00084 }
00085 return *theInstance;
00086 }
00087
00088
00089
00090
00091
00092 Model::Model()
00093 {
00094 GlobalOptionMgr::getInstance()->setDefaultGlobalOptions();
00095
00096 }
00097
00098
00099
00100
00101 void Model::readSystemDescription()
00102 {
00103 Model::setCocoaStatus( COCOA_Init );
00104
00105 ALIint data_reading = 0;
00106
00107
00108 ALIFileIn& filein = ALIFileIn::getInstance( Model::SDFName());
00109
00110
00111 std::vector<ALIstring> SectionTitle;
00112 SectionTitle.push_back(ALIstring("GLOBAL_OPTIONS"));
00113 SectionTitle.push_back(ALIstring("PARAMETERS"));
00114 SectionTitle.push_back(ALIstring("SYSTEM_TREE_DESCRIPTION"));
00115 SectionTitle.push_back(ALIstring("SYSTEM_TREE_DATA"));
00116 SectionTitle.push_back(ALIstring("MEASUREMENTS"));
00117 SectionTitle.push_back(ALIstring("REPORT.OUT"));
00118 std::vector<ALIstring>::iterator SectionTitleIterator;
00119
00120
00121 std::vector<ALIstring> wordlist;
00122 ALIint InSectionNo = -1;
00123 ALIint currentSectionNo = -1;
00124 while (!filein.eof()) {
00125
00126 if( !filein.getWordsInLine(wordlist) ) break;
00127 assert( wordlist.size() != 0 );
00128
00129
00130 if( ALIUtils::debug > 99) {
00131 ALIUtils::dumpVS( wordlist, " ", std::cout );
00132 }
00133
00134
00135
00136
00137 SectionTitleIterator = find(SectionTitle.begin(), SectionTitle.end(), *wordlist.begin());
00138 if( SectionTitleIterator != SectionTitle.end() ) {
00139
00140 currentSectionNo = SectionTitleIterator - SectionTitle.begin();
00141 if ( currentSectionNo != InSectionNo + 1 ) {
00142 if( currentSectionNo != sectReportOut ) {
00143 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00144 std::cerr << "BAD ORDER OF SECTIONS, reading section "
00145 << *SectionTitleIterator << std::endl
00146 << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
00147 << " --------- Please see documentation ---------- " << std::endl;
00148 exit(1);
00149 }
00150 } else {
00151 if( currentSectionNo != sectReportOut ) {
00152 InSectionNo++;
00153 }
00154 }
00155 if( currentSectionNo == sectMeasurements ) {
00156 SetValueDisplacementsFromReportOut();
00157 }
00158
00159 if( ALIUtils::debug >= 4) std::cout << std::endl << "START OF SECTION: " << currentSectionNo << " " << *SectionTitleIterator << std::endl;
00160
00161
00162
00163 } else if( currentSectionNo == sectGlobalOptions ) {
00164
00165
00166
00167 if( wordlist.size() == 2 ) {
00168
00169 int isnumber = ALIUtils::IsNumber( wordlist[1] );
00170 if (!isnumber && wordlist[0] != ALIstring("external_meas")) {
00171 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00172 std::cerr << ": EXPECTING A NUMBER, FOUND: " << wordlist[1] << std::endl;
00173 exit(2);
00174 }
00175
00176 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00177 gomgr->setGlobalOption( wordlist[0], ALIUtils::getFloat(wordlist[1]), ALIFileIn::getInstance(Model::SDFName()) );
00178
00179
00180
00181 if( ALIUtils::debug >= 1) {
00182 ALIUtils::dumpVS( wordlist, "GLOBAL_OPTION: ", std::cout );
00183 }
00184
00185 } else {
00186 std::cout << "error < 1" << std::endl;
00187 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00188 std::cerr << ": IN GLOBAL_OPTIONS section TWO-WORD LINES ARE EXPECTED " << std::endl;
00189 exit(2);
00190 }
00191
00192
00193 ALIUtils::SetLengthDimensionFactors();
00194 ALIUtils::SetAngleDimensionFactors();
00195 ALIUtils::SetOutputLengthDimensionFactors();
00196 ALIUtils::SetOutputAngleDimensionFactors();
00197
00198
00199
00200 } else if( currentSectionNo == sectParameters ||
00201 currentSectionNo == -1 ) {
00202
00203
00204
00205 if( wordlist.size() == 2 ) {
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 ParameterMgr* parmgr = ParameterMgr::getInstance();
00218 parmgr->addParameter( wordlist[0], wordlist[1] );
00219
00220 } else if( wordlist.size() == 3 ) {
00221 if( wordlist[1] != "seed" ) {
00222 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00223 std::cerr << ": For a three-word parameter line, second has to be 'seed', it is " << wordlist[1] << std::endl;
00224 exit(1);
00225 }
00226
00227 if( wordlist[0] == "gauss" || wordlist[0] == "flat" ){
00228 ParameterMgr::getInstance()->setRandomSeed( ALIUtils::getInt( wordlist[2] ));
00229 } else {
00230 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00231 std::cerr << ": For a three-word parameter line, first has to be 'gauss' or 'flat', it is " << wordlist[0] << std::endl;
00232 exit(1);
00233 }
00234 } else if( wordlist.size() == 4 ) {
00235 if( wordlist[0] == "gauss" ) {
00236 ParameterMgr::getInstance()->addRandomGaussParameter( wordlist[1], wordlist[2], wordlist[3] );
00237 } else if( wordlist[0] == "flat" ) {
00238 ParameterMgr::getInstance()->addRandomFlatParameter( wordlist[1], wordlist[2], wordlist[3] );
00239 } else {
00240 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00241 std::cerr << ": For a four-word parameter line, first has to be 'gauss' or 'flat', it is " << wordlist[0] << std::endl;
00242 exit(1);
00243 }
00244 } else {
00245 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00246 std::cerr << ": IN PARAMETERS section TWO-WORD-LINES ARE EXPECTED " << std::endl;
00247 ALIUtils::dumpVS( wordlist , " " );
00248 exit(2);
00249 }
00250
00251
00252 if( ALIUtils::debug >= 1) {
00253 ALIUtils::dumpVS( wordlist, "PARAMETERS: ", std::cout );
00254 }
00255
00256
00257
00258 } else if( currentSectionNo == sectSystemTreeDescription ) {
00259
00260
00261
00262 std::vector<ALIstring> wordlist2 = wordlist;
00263 std::vector<ALIstring>::iterator vsite;
00264 ALIint wsiz = wordlist.size();
00265 for ( ALIint ii = 0; ii < wsiz; ii++) {
00266 wordlist.pop_back();
00267 }
00268
00269 for ( vsite=wordlist2.begin(); vsite!=wordlist2.end(); vsite++ ) {
00270 if( ALIUtils::IsNumber( *vsite ) ) {
00271 int nOpticalObjects = atoi( (*vsite).c_str() );
00272
00273 if( nOpticalObjects == 1 ) {
00274 if( ALIUtils::debug >= 0) std::cerr << "WARNING: in line " << ALIFileIn::getInstance( Model::SDFName() ).nline()
00275 << " number of repeated OpticalObjects = 1. Please avoid the numbering " << std::endl;
00276
00277 } else {
00278
00279 if( vsite+1 == wordlist.end() || ALIUtils::IsNumber(*(vsite+1)) ) {
00280 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00281 std::cerr << "NUMBER SHOULD BE FOLLOWED BY an OpticalObject type" << std::endl;
00282 exit(2);
00283 }
00284
00285
00286
00287
00288 for ( ALIint ii=0; ii<nOpticalObjects-1; ii++ ) {
00289
00290 wordlist.push_back( *(vsite+1) );
00291 }
00292 }
00293 } else {
00294
00295 wordlist.push_back( *vsite );
00296 }
00297 }
00298
00299
00300 if ( ALIUtils::debug >= 1 ) {
00301 ALIUtils::dumpVS( wordlist, "SYSTEM TREE DESCRIPTION: before ordering, OBJECT: ", std::cout );
00302 }
00303
00304
00305
00306 if ( wordlist[0] == ALIstring("object") ) {
00307
00308 std::vector< std::vector<ALIstring> >::iterator vvsite;
00309 for ( vvsite = theOptODictionary.begin(); vvsite != theOptODictionary.end(); vvsite++) {
00310
00311
00312 if( *( (*vvsite).begin() ) == wordlist[1] ) {
00313 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00314 std::cerr << "SYSTEM_TREE_DESCRIPTION: REPEATED object " << *((*vvsite).begin()) << " ( NOT ALLOWED NEITHER WITH EQUAL NOR WITH DIFFERENT COMPONENTS)" << std::endl;
00315 exit(1);
00316 }
00317 }
00318
00319 std::vector<ALIstring> vstemp;
00320 copy( wordlist.begin()+1, wordlist.end(),back_inserter( vstemp ) );
00321 Model::OptODictionary().push_back(vstemp);
00322 } else {
00323
00324 if(OptODictionary().size() == 0) {
00325 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00326 std::cerr << "SYSTEM_TREE_DESCRIPTION section: FIRST LINE SHOULD START WITH 'object'" << std::endl;
00327 exit(2);
00328 }
00329 copy(wordlist.begin(), wordlist.end(),
00330 back_inserter( *(OptODictionary().end()-1) ) );
00331 }
00332
00333
00334
00335 } else if( currentSectionNo == sectSystemTreeData ) {
00336
00337 if ( !data_reading ) {
00338
00339
00340 std::vector< std::vector<ALIstring> > OptODictionary2;
00341 reorderOptODictionary( "system", OptODictionary2);
00342 if(OptODictionary2.size() == 0) {
00343 std::cerr << "SYSTEM_TREE_DESCRIPTION section: no object 'system' found " << std::endl;
00344 exit(9);
00345 }
00346
00347
00348 std::vector< std::vector<ALIstring> >::const_iterator vvscite, vvscite2;
00349
00350 for( vvscite = theOptODictionary.begin(); vvscite != theOptODictionary.end(); vvscite++) {
00351 ALIbool ofound = 0;
00352 for( vvscite2 = OptODictionary2.begin(); vvscite2 != OptODictionary2.end(); vvscite2++) {
00353 if( *( (*vvscite).begin() ) == *( (*vvscite2).begin() ) ) {
00354 ofound = 1;
00355 break;
00356 }
00357 }
00358 if( !ofound ) {
00359 std::cerr << "!!!SYSTEM_TREE_DESCRIPTION section: object " << *( (*vvscite).begin()) << " is not hanging from object 'system' " << std::endl;
00360 for (vvscite=OptODictionary().begin();vvscite!=OptODictionary().end();vvscite++){
00361 std::vector<ALIstring> ptemp = *vvscite;
00362 ALIUtils::dumpVS( ptemp, "OBJECT ", std::cerr );
00363 }
00364 exit(9);
00365 }
00366 }
00367 theOptODictionary = OptODictionary2;
00368
00369 data_reading = 1;
00370
00371
00372 if ( ALIUtils::debug >= 3) {
00373 std::vector< std::vector<ALIstring> >::iterator itevs;
00374 for (itevs=OptODictionary().begin();itevs!=OptODictionary().end();itevs++){
00375 std::vector<ALIstring> ptemp = *itevs;
00376 ALIUtils::dumpVS( ptemp, " SYSTEM TREE DESCRIPTION: after ordering: OBJECT ", std::cout );
00377 }
00378 }
00379
00380
00381
00382 if(wordlist[0] != "system" ) {
00383 std::cerr << "SYSTEM_TREE_DATA section: object 'system' is not the first one " << std::endl;
00384 exit(9);
00385 }
00386
00387 OpticalObject* OptOsystem = new OpticalObject( 0, "system", wordlist[1], 0 );
00388 OptOsystem->construct();
00389
00390
00391 theOptOList.push_back( OptOsystem );
00392
00393 } else {
00394
00395 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00396 std::cerr << " STILL SOME LINES AFTER ALL SYSTEM TREE IS READ!!!"<< std::endl;
00397 exit(9);
00398 }
00399
00400
00401
00402 } else if( currentSectionNo == sectMeasurements ) {
00403
00404 Measurement* meastemp = 0;
00405 ALIstring measType = wordlist[0];
00406 ALIstring measName;
00407 if( wordlist.size() == 2 ) {
00408 measName = wordlist[1];
00409 wordlist.pop_back();
00410 } else {
00411 measName = "";
00412 }
00413 if ( measType == ALIstring("SENSOR2D") ) {
00414 meastemp = new MeasurementSensor2D( 2, measType, measName );
00415 meastemp->setConversionFactor( wordlist );
00416 meastemp->construct();
00417 } else if ( measType == ALIstring("DISTANCEMETER3DIM") ) {
00418 meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
00419 meastemp->setConversionFactor( wordlist );
00420 meastemp->construct();
00421 } else if ( measType == ALIstring("DISTANCEMETER") ||
00422 measType == ALIstring("DISTANCEMETER1DIM") ) {
00423 meastemp = new MeasurementDistancemeter( 1, measType, measName );
00424 meastemp->setConversionFactor( wordlist );
00425 meastemp->construct();
00426 } else if ( measType == ALIstring("TILTMETER") ) {
00427 meastemp = new MeasurementTiltmeter( 1, measType, measName );
00428 meastemp->setConversionFactor( wordlist );
00429 meastemp->construct();
00430 } else if ( measType == ALIstring("COPS") ) {
00431 meastemp = new MeasurementCOPS( 4, measType, measName );
00432 meastemp->setConversionFactor( wordlist );
00433 meastemp->construct();
00434 } else if ( measType == ALIstring("DIFFCENTRE") ) {
00435
00436 meastemp->construct();
00437 } else if ( measType == ALIstring("DIFFANGLE") ) {
00438
00439 meastemp->construct();
00440 } else if ( measType == ALIstring("DIFFENTRY") ) {
00441 meastemp = new MeasurementDiffEntry( 1, measType, measName );
00442 meastemp->construct();
00443 } else if ( measType == ALIstring("measurements_from_file") || measType == ALIstring("@measurements_from_file") ) {
00444 new CocoaDaqReaderText( wordlist[1] );
00445
00446
00447 if( wordlist.size() == 4) {
00448 Measurement::only1 = 1;
00449 Measurement::only1Date = wordlist[2];
00450 Measurement::only1Time = wordlist[3];
00451
00452 }
00453 } else if ( wordlist[0] == ALIstring("correlations_from_file") || wordlist[0] == ALIstring("@correlations_from_file") ) {
00454 ErrorCorrelationMgr::getInstance()->readFromReportFile( wordlist[1] );
00455 } else if ( wordlist[0] == ALIstring("copy_measurements") || wordlist[0] == ALIstring("@copy_measurements") ) {
00456 copyMeasurements( wordlist );
00457
00458
00459 } else if ( wordlist[0] == ALIstring("fittedEntries_from_file") ) {
00460 theFittedEntriesReader = new FittedEntriesReader( wordlist[1] );
00461 if ( ALIUtils::debug >= 2) std::cout << " setting fittedEntries_from_file " << wordlist[0] << " == " << wordlist[1] << std::endl;
00462 } else {
00463 std::cerr << "Measurement:" << std::endl;
00464 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00465 std::cerr << "!!! type of measurement not allowed: " << wordlist[0]
00466 << std::endl;
00467 std::cerr << " Allowed types: SENSOR2D, DISTANCEMETER, DISTANCEMETER1DIM, TILTMETER, COPS, DIFFENTRY " << std::endl;
00468 exit(2);
00469 }
00470
00471
00472
00473 } else if( currentSectionNo == sectReportOut ) {
00474
00475 if ( InSectionNo+1 != sectParameters ) {
00476 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00477 std::cerr << "BAD ORDER OF SECTIONS, reading section "
00478 << *SectionTitleIterator << std::endl
00479 << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
00480 << " --------- Please see documentation ---------- " << std::endl;
00481 exit(1);
00482 }
00483
00484 EntryMgr::getInstance()->readEntryFromReportOut( wordlist );
00485 }
00486 }
00487
00488
00489
00490
00491
00492 if ( ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ Building Measurements links to OptOs" << std::endl;
00493 Model::buildMeasurementsLinksToOptOs();
00494
00495 if ( ALIUtils::debug >= 1) {
00496 std::cout << "---------- SYSTEM SUCCESFULLY READ ----------" << std::endl << std::endl;
00497 }
00498 filein.close();
00499
00500 return;
00501
00502 }
00503
00504
00505
00506
00507
00508
00509 void Model::reorderOptODictionary(const ALIstring& ssearch, std::vector< std::vector<ALIstring> >& OptODictionary2 ){
00510
00511
00512 std::vector< std::vector<ALIstring> >::iterator vvsite;
00513 std::vector< ALIstring >::iterator vsite;
00514
00515
00516 for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
00517 if( *( (*vvsite).begin() ) == ssearch ) {
00518
00519 OptODictionary2.push_back(*vvsite);
00520
00521
00522
00523
00524
00525
00526 for( vsite = (*vvsite).begin()+1; vsite != (*vvsite).end(); ++vsite ) {
00527 reorderOptODictionary( *vsite, OptODictionary2 );
00528 }
00529 break;
00530 }
00531 }
00532
00533
00534
00535
00536
00537
00538
00539 }
00540
00541
00542
00543
00544 void Model::buildMeasurementsLinksToOptOs(){
00545
00546
00547 std::vector< Measurement* >::const_iterator vmcite;
00548 for ( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++) {
00549
00550
00551
00552
00553
00554
00555 }
00556
00557 }
00558
00559
00560
00561
00562
00563 ALIint Model::getParameterValue( const ALIstring& sstr, ALIdouble& val )
00564 {
00565 ParameterMgr* parmgr = ParameterMgr::getInstance();
00566 ALIint iret = parmgr->getParameterValue( sstr, val );
00567
00568 return iret;
00569
00570 }
00571
00572
00573
00574
00575
00576 OpticalObject* Model::getOptOByName( const ALIstring& opto_name )
00577 {
00578
00579 std::vector< OpticalObject* >::const_iterator vocite;
00580 for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00581 if( (*vocite)->name() == opto_name ) break;
00582 }
00583
00584 if ( vocite == OptOList().end() ) {
00585
00586 std::cerr << " LIST OF OpticalObjects " << std::endl;
00587 for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00588 std::cerr << (*vocite)->name() << std::endl;
00589 }
00590 std::cerr << "!!EXITING at getOptOByName: Optical Object " << opto_name << " doesn't exist!!" << std::endl;
00591 exit(4);
00592
00593 } else {
00594
00595 if( ALIUtils::debug>999) {
00596 std::cout << opto_name.c_str() << "SSOptOitem" << (*vocite) << (*vocite)->name() << "len" << OptOList().size() << std::endl;
00597 }
00598 return (*vocite);
00599 }
00600
00601 }
00602
00603
00604
00605
00606
00607
00608 OpticalObject* Model::getOptOByType( const ALIstring& opto_type )
00609 {
00610
00611 std::vector< OpticalObject* >::const_iterator vocite;
00612 for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00613
00614 if( (*vocite)->type() == opto_type ) break;
00615 }
00616
00617 if ( vocite == OptOList().end() ) {
00618
00619 std::cerr << "!!EXITING at getOptOByType: Optical Object " << opto_type << " doesn't exist!!" << std::endl;
00620 exit(4);
00621 } else {
00622
00623 return (*vocite);
00624 }
00625
00626 }
00627
00628
00629
00630
00631 Entry* Model::getEntryByName( const ALIstring& opto_name, const ALIstring& entry_name )
00632 {
00633
00634 std::vector<Entry*>::const_iterator vecite;
00635 for( vecite = EntryList().begin(); vecite != EntryList().end(); vecite++) {
00636 if( ALIUtils::debug >= 4 ) std::cout << "getEntryByName: " <<(*vecite)->OptOCurrent()->name()
00637 << " E " << (*vecite)->name() << " Searching: " << opto_name << " E " << entry_name << std::endl;
00638
00639 if( (*vecite)->OptOCurrent()->name() == opto_name &&
00640 (*vecite)->name() == entry_name ) {
00641 return *vecite;
00642 }
00643 }
00644
00645 std::cerr << "!!!EXITING at getEntryByName: Entry name not found:" << opto_name << " " << entry_name << std::endl;
00646 exit(1);
00647 }
00648
00649
00650
00651 Measurement* Model::getMeasurementByName( const ALIstring& meas_name, ALIbool exists )
00652 {
00653
00654 std::vector< Measurement* >::const_iterator vmcite;
00655 for( vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); vmcite++ ) {
00656 if( (*vmcite)->name() == meas_name ) break;
00657 }
00658
00659 if ( vmcite != theMeasurementVector.end() ) {
00660
00661 return (*vmcite);
00662 }else {
00663 if( exists ) {
00664
00665 std::cerr << " LIST OF Measurements " << std::endl;
00666 for( vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); vmcite++ ) {
00667 std::cerr << (*vmcite)->name() << std::endl;
00668 }
00669 std::cerr << "!!EXITING at getMeasurementByName: Measurement " << meas_name << " doesn't exist!!" << std::endl;
00670 abort();
00671
00672 } else {
00673 return 0;
00674 }
00675
00676 }
00677
00678
00679 }
00680
00681
00682
00683
00684
00685
00686
00687
00688 ALIbool Model::getComponentOptOTypes( const ALIstring& opto_type, std::vector<ALIstring>& vcomponents )
00689 {
00690
00691 std::vector<ALIstring>::iterator vsite;
00692 for (vsite = vcomponents.begin(); vsite != vcomponents.end(); vsite++) {
00693 vcomponents.pop_back();
00694 }
00695
00696
00697 ALIint ALIstring_found = 0;
00698 std::vector< std::vector<ALIstring> >::iterator vvsite;
00699 for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
00700 if( *( (*vvsite).begin() ) == opto_type ) {
00701 ALIstring_found = 1;
00702
00703 vcomponents = *vvsite;
00704 vcomponents.erase( vcomponents.begin() );
00705 break;
00706 }
00707 }
00708
00709 if ( ALIstring_found ) {
00710 return 1;
00711 } else {
00712 return 0;
00713 }
00714 }
00715
00716
00717
00718
00719
00720
00721 ALIbool Model::getComponentOptOs( const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents)
00722 {
00723
00724 std::vector<OpticalObject*>::iterator voite;
00725 for (voite = vcomponents.begin(); voite != vcomponents.end(); voite++) {
00726 vcomponents.pop_back();
00727 }
00728
00729
00730 OpticalObject* opto = getOptOByName( opto_name );
00731
00732 if ( ALIUtils::debug >= 99) std::cout << opto_name << "getComponentOptOs: opto " << opto << opto->name() << std::endl;
00733 std::vector<OpticalObject*>::const_iterator vocite;
00734
00735 if ( ALIUtils::debug >= 99) std::cout << "optolist size " << OptOList().size() << std::endl;
00736 ALIbool opto_found = 0;
00737 for (vocite = OptOList().begin(); vocite != OptOList().end(); vocite++) {
00738 if( (*vocite)->parent() != 0 ) {
00739
00740 if( (*vocite)->parent()->name() == opto_name ) {
00741 opto_found = 1;
00742 vcomponents.push_back( (*vocite) );
00743 }
00744 }
00745 }
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758 return opto_found;
00759
00760 }
00761
00762
00764
00765
00766
00767 ALIbool Model::createCopyComponentList( const ALIstring& typ )
00768 {
00769
00770 if(ALIUtils::debug >= 3) std::cout << "createCopyComponentList " << typ << std::endl;
00771 OpticalObject* start_opto = getOptOByType( typ );
00772
00773
00774 theOptOsToCopyList.erase( theOptOsToCopyList.begin(), theOptOsToCopyList.end() );
00775
00776
00777 fillCopyComponentList( start_opto );
00778
00779
00780 theOptOsToCopyListIterator = theOptOsToCopyList.begin();
00781 return 1;
00782 }
00783
00784
00785
00786
00787
00788 ALIbool Model::fillCopyComponentList( const OpticalObject* opto )
00789 {
00790 if(ALIUtils::debug >= 3) std::cout << "entering fillCopyComponentList(): OptO" << opto->name() << std::endl;
00791
00792 std::vector<OpticalObject*> vopto;
00793 ALIbool opto_found = getComponentOptOs( opto->name(), vopto);
00794 if( !opto_found ) {
00795 if(ALIUtils::debug >= 5) std::cout << "fillCopyComponentList: NO COMPONENTS TO COPY IN THIS OptO" << opto->name() << std::endl ;
00796 }
00797
00798
00799 std::vector<OpticalObject*>::const_iterator vocite;
00800 for( vocite = vopto.begin(); vocite != vopto.end(); vocite++ ){
00801 theOptOsToCopyList.push_back( *vocite );
00802 if(ALIUtils::debug >= 5) std::cout << "fillCopyOptOList " << (*vocite)->type() << " " << (*vocite)->name() << std::endl;
00803
00804 fillCopyComponentList( *vocite );
00805 }
00806 return opto_found;
00807 }
00808
00809
00810
00811
00812
00813
00814 OpticalObject* Model::nextOptOToCopy()
00815 {
00816 if(ALIUtils::debug >= 5) std::cout << "entering nextOptOToCopy() " << std::endl;
00817 theOptOsToCopyListIterator++;
00818
00819 return *(theOptOsToCopyListIterator-1);
00820 }
00821
00822
00824
00825
00826
00827 void Model::CMSLinkFit( ALIint cmslink)
00828 {
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878 }
00879
00880
00881
00882
00883
00884
00885 void Model::CMSLinkCleanModel()
00886 {
00887 deleteOptO("s");
00888
00889 ALIuint odsize = theOptODictionary.size();
00890 for( ALIuint ii = 0; ii < odsize; ii++) {
00891 theOptODictionary.pop_back();
00892 }
00893
00894 }
00895
00896
00897
00898
00899
00900 void Model::CMSLinkDeleteOptOs( )
00901 {
00902 ALIint cmslink_iter = Model::CMSLinkIteration;
00903 ALIdouble cmslink_method;
00904
00905 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00906 assert(gomgr->getGlobalOptionValue("cms_link_method", cmslink_method));
00907 ALIdouble cmslink_halfplanes;
00908 assert(gomgr->getGlobalOptionValue("cms_link_halfplanes", cmslink_halfplanes));
00909 if(ALIUtils::debug >= 2) std::cout << "CMSLinkDeleteOptOs: cms_link_halfplanes " << cmslink_halfplanes << cmslink_iter << std::endl;
00910
00911 if( cmslink_iter == 1){
00912
00913
00914
00915 deleteOptO("s/mabsL");
00916
00917 if (cmslink_method == 1){
00918 deleteOptO("s/tracker/det_trkDL");
00919 deleteOptO("s/tracker/det_trkDR");
00920 }
00921
00922 if( cmslink_halfplanes == 2) {
00923
00924 deleteOptO("s/mabsR");
00925 }
00926
00927 } else if( cmslink_iter == 2) {
00928
00929
00930 deleteOptO("s/mabsL");
00931 deleteOptO("s/tracker/CST/wheel_trkL/peri/mirror");
00932 deleteOptO("s/tracker/CST/wheel_trkL/det_trkU");
00933
00934
00935
00936 if( cmslink_halfplanes <= 1) {
00937 deleteOptO("s/tracker/CST/wheel_trkR");
00938 } else if( cmslink_halfplanes == 2) {
00939
00940 deleteOptO("s/mabsR");
00941 deleteOptO("s/tracker/CST/wheel_trkR/peri/mirror");
00942 deleteOptO("s/tracker/CST/wheel_trkR/det_trkU");
00943 }
00944
00945 } else if( cmslink_iter == 3) {
00946
00947
00948 deleteOptO("s/tracker");
00949
00950 if( cmslink_halfplanes == 2) {
00951
00952 }
00953
00954 } else {
00955
00956 }
00957
00958 }
00959
00960
00961
00962
00963
00964 void Model::CMSLinkSaveParamFittedSigma( ALIint cms_link )
00965 {
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023 }
01024
01025
01026
01027
01028
01029 void Model::CMSLinkSaveParamFittedValueDisplacement( ALIint cms_link )
01030 {
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050 }
01051
01052
01053
01054
01055
01056 void Model::CMSLinkRecoverParamFittedSigma( ALIint cms_link )
01057 {
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111 }
01112
01113
01114
01115
01116
01117 void Model::CMSLinkRecoverParamFittedValueDisplacement( ALIint cms_link )
01118 {
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139 }
01140
01141
01142
01143
01144
01145 void Model::deleteOptO( const ALIstring& opto_name )
01146 {
01147 OpticalObject* opto = getOptOByName( opto_name );
01148 deleteOptO( opto );
01149 }
01150
01151
01152
01153
01154
01155 void Model::deleteOptO( OpticalObject* opto )
01156 {
01157 if(ALIUtils::debug >= 5 ) std::cout << "DELETING OptO" << opto->name() << std::endl;
01158
01159
01160 std::vector<Entry*>::const_iterator vecite;
01161 std::vector<Entry*>::iterator veite2;
01162 if ( ALIUtils::debug >= 9) std::cout << "SIZE" << theEntryVector.size() <<std::endl;
01163 for( vecite = opto->CoordinateEntryList().begin(); vecite != opto->CoordinateEntryList().end(); vecite++) {
01164
01165 veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
01166
01167 delete ( (*veite2) );
01168 theEntryVector.erase( veite2 );
01169 }
01170
01171 for( vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); vecite++) {
01172
01173 veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
01174
01175 delete ( (*veite2) );
01176 theEntryVector.erase( veite2 );
01177 }
01178
01179
01180 for( vecite = theEntryVector.begin(); vecite != theEntryVector.end(); vecite++ ) {
01181
01182 }
01183
01184
01185 std::vector<Measurement*> MeasToBeDeleted;
01186 std::vector<Measurement*>::const_iterator vmite;
01187 std::vector<OpticalObject*>::const_iterator vocite;
01188 for( vmite = MeasurementList().begin(); vmite != MeasurementList().end(); vmite++ ) {
01189 if(ALIUtils::debug >= 5) std::cout << "Deleting Measurement" << (*vmite)->name() << std::endl;
01190
01191 for( vocite = (*vmite)->OptOList().begin(); vocite != (*vmite)->OptOList().end(); vocite++) {
01192 if( (*vocite) == opto ) {
01193
01194 MeasToBeDeleted.push_back( *vmite );
01195
01196 break;
01197 }
01198 }
01199 }
01200
01201
01202 std::vector<Measurement*>::const_iterator vmcite;
01203 std::vector<Measurement*>::iterator vmite2;
01204 if ( ALIUtils::debug >= 9) std::cout << "SIZEMEAS" << MeasToBeDeleted.size() <<std::endl;
01205 for( vmcite = MeasToBeDeleted.begin(); vmcite != MeasToBeDeleted.end(); vmcite++) {
01206 vmite2 = find( theMeasurementVector.begin(), theMeasurementVector.end(), (*vmcite) );
01207
01208 delete ( (*vmite2) );
01209 theMeasurementVector.erase( vmite2 );
01210 }
01211
01212
01213
01214
01215 std::vector<OpticalObject*> vopto;
01216
01217 for( vocite = vopto.begin(); vocite != vopto.end(); vocite++ ) {
01218 deleteOptO( *vocite );
01219 }
01220
01221
01222
01223
01224
01225
01226 std::vector< OpticalObject* >::iterator dvoite =
01227 find( theOptOList.begin(), theOptOList.end(),
01228 std::vector< OpticalObject* >::value_type( opto) );
01229
01230 theOptOList.erase( dvoite );
01231 delete opto;
01232
01233 }
01234
01235
01236
01237
01238
01239 void Model::saveParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name)
01240 {
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254 }
01255
01256
01257
01258
01259
01260 void Model::saveParamFittedCorrelation( const ALIstring& opto_name1, const ALIstring& entry_name1, const ALIstring& opto_name2, const ALIstring& entry_name2)
01261 {
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287
01288
01289
01290 }
01291
01292
01293
01294
01295
01296 void Model::recoverParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position )
01297 {
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311 }
01312
01313
01314
01315
01316
01317 ALIdouble Model::getParamFittedSigmaVectorItem( const ALIuint position )
01318 {
01319 if( position >= theParamFittedSigmaVector.size() ) {
01320 std::cerr << "!!EXITING at getParamFittedSigma: position" << position <<
01321 " bigger than dimension of theParamFittedSigmaVector " << theParamFittedSigmaVector.size() << std::endl;
01322 exit(3);
01323 }
01324 std::vector<ALIdouble>::const_iterator vdcite = theParamFittedSigmaVector.begin() + position;
01325 return (*vdcite);
01326
01327 }
01328
01329
01330
01331
01332
01333
01334 ALIbool Model::readMeasurementsFromFile(ALIstring only1Date, ALIstring only1Time )
01335 {
01336 if(ALIUtils::debug >= 5) std::cout << " readMeasurementsFromFile " << Measurement::measurementsFileName() << std::endl;
01337 if( Measurement::measurementsFileName() == "") return 1;
01338
01339 ALIFileIn& filein = ALIFileIn::getInstance( Measurement::measurementsFileName() );
01340 std::vector<ALIstring> wordlist;
01341
01342
01343
01344
01345 if( filein.getWordsInLine(wordlist) == 0 ) {
01346 if(ALIUtils::debug>=4 ) std::cout << "@@@@ No more measurements left" << std::endl;
01347 return 0;
01348 }
01349
01351
01352
01353
01354
01355 if( Measurement::only1 ) {
01356 for(;;) {
01357 if( wordlist[0] == "DATE:" && wordlist[1] == Measurement::only1Date && wordlist[2] == Measurement::only1Time ) break;
01358 filein.getWordsInLine(wordlist);
01359 if(filein.eof() ) {
01360 std::cerr << "!! EXITING date not found in measurements file" << Measurement::only1Date << " " << Measurement::only1Time << std::endl;
01361 exit(1);
01362 }
01363 }
01364 }
01365
01366
01367 if( wordlist[0] == "DATE:" ) {
01368 Measurement::setCurrentDate( wordlist );
01369 }
01370
01371
01372 ALIint nMeas = Model::MeasurementList().size();
01373 if(ALIUtils::debug >= 4) {
01374 std::cout << " Reading " << nMeas << " measurements from file " << Measurement::measurementsFileName()
01375 << " DATE: " << wordlist[1] << " " << wordlist[1] << std::endl;
01376 }
01377 ALIint ii;
01378 for(ii = 0; ii < nMeas; ii++) {
01379 filein.getWordsInLine(wordlist);
01380 if( wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") || wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") || wordlist[0] == ALIstring("COPS") ) {
01381 if( wordlist.size() != 2 ) {
01382 std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of " << wordlist.size() << std::endl;
01383 ALIUtils::dumpVS( wordlist, " " );
01384 exit(1);
01385 }
01386 std::vector< Measurement* >::const_iterator vmcite;
01387 for( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++ ) {
01388
01389
01390
01391
01392
01393
01394
01395 ALIint fcolon = (*vmcite)->name().find(':');
01396 ALIstring oname = (*vmcite)->name();
01397 oname = oname.substr(fcolon+1,oname.length());
01398
01399 if( oname == wordlist[1] ) {
01400
01401 if( (*vmcite)->type() != wordlist[0] ) {
01402 std::cerr << "!!! Reading measurement from file: type in file is "
01403 << wordlist[0] << " and should be " << (*vmcite)->type() << std::endl;
01404 exit(1);
01405 }
01406 Measurement* meastemp = *vmcite;
01407
01408 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
01409 ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
01410
01411 for ( uint ii=0; ii < meastemp->dim(); ii++){
01412 filein.getWordsInLine( wordlist );
01413 ALIdouble sigma = 0.;
01414 if( !sigmaFF ) {
01415
01416 const ALIdouble* sigmav = meastemp->sigma();
01417 sigma = sigmav[ii];
01418 }
01419
01420 if( meastemp->valueType(ii) != wordlist[0] ) {
01421 filein.ErrorInLine();
01422 std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0] << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
01423 exit(1);
01424 }
01425 meastemp->fillData( ii, wordlist );
01426 if( !sigmaFF ) {
01427 meastemp->setSigma( ii, sigma );
01428 }
01429 }
01430 meastemp->correctValueAndSigma();
01431 break;
01432 }
01433 }
01434 if( vmcite == MeasurementList().end() ) {
01435 for( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++ ) {
01436 std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
01437 }
01438 std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is " << wordlist[1] << std::endl;
01439 exit(1);
01440 }
01441 } else {
01442 std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
01443 << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
01444 exit(1);
01445 }
01446 }
01447
01448
01449 return 1;
01450 }
01451
01452
01453
01454
01455
01456 void Model::copyMeasurements( const std::vector<ALIstring>& wl )
01457 {
01458
01459
01460
01461
01462
01463
01464 std::string subsstr1 = wl[1].substr( 0, wl[1].find("/") );
01465 std::string subsstr2 = wl[1].substr( wl[1].find("/")+1, wl[1].rfind("/") - wl[1].find("/")-1 );
01466 std::string querystr = wl[1].substr( wl[1].rfind("/")+1, wl[1].length() );
01467
01468 std::cout << " Model::copyMeasurements " << " subsstr1 " << subsstr1 << " subsstr2 " << subsstr2 << " querystr " << querystr << std::endl;
01469
01470 std::vector< Measurement* > measToCopy;
01471 std::vector< Measurement* >::iterator mite;
01472 for( mite = theMeasurementVector.begin(); mite != theMeasurementVector.end(); mite++) {
01473 Measurement* meas = (*mite);
01474
01475 if( meas->name().find( querystr ) != -1 ) {
01476 measToCopy.push_back( meas );
01477 }
01478 }
01479
01480
01481 Measurement* meastemp = 0;
01482 for( mite = measToCopy.begin(); mite != measToCopy.end(); mite++) {
01483 Measurement* meas = (*mite);
01484 std::vector<ALIstring> wlt;
01485 wlt.push_back( meas->type() );
01486
01487
01488 std::string newName = ALIUtils::changeName( meas->name(), subsstr1, subsstr2 );
01489 std::cout << " newName " << newName << std::endl;
01490 wlt.push_back( newName );
01491
01492 ALIstring measType = wlt[0];
01493 ALIstring measName;
01494 if( wlt.size() == 2 ) {
01495 measName = wlt[1];
01496 } else {
01497 measName = "";
01498 }
01499 if ( meas->type() == ALIstring("SENSOR2D") ) {
01500 meastemp = new MeasurementSensor2D( 2, measType, measName );
01501
01502
01503 } else if ( meas->type() == ALIstring("DISTANCEMETER") ||
01504 meas->type() == ALIstring("DISTANCEMETER1DIM") ) {
01505 meastemp = new MeasurementDistancemeter( 1, measType, measName );
01506 } else if ( meas->type() == ALIstring("TILTMETER") ) {
01507 meastemp = new MeasurementTiltmeter( 1, measType, measName );
01508 } else if ( meas->type() == ALIstring("DIFFCENTRE") ) {
01509
01510 } else if ( meas->type() == ALIstring("DIFFANGLE") ) {
01511
01512 } else if ( meas->type() == ALIstring("DIFFENTRY") ) {
01513 meastemp = new MeasurementDiffEntry( 1, measType, measName );
01514 } else if ( meas->type() == ALIstring("COPS") ) {
01515 meastemp = new MeasurementCOPS( 4, measType, measName );
01516 }
01517
01518
01519 meastemp->copyMeas(meas, subsstr1, subsstr2);
01520
01521 break;
01522 }
01523
01524 }
01525
01526
01527
01528 void Model::SetValueDisplacementsFromReportOut()
01529 {
01530 if( ALIUtils::debug >= 3 ) std::cout << " Model::SetValueDisplacementsFromReportOut() " << std::endl;
01531
01532 EntryMgr* entryMgr = EntryMgr::getInstance();
01533
01534 if( entryMgr->numberOfEntries() != 0 ){
01535 EntryData* entryData;
01536
01537 std::vector<Entry*>::const_iterator vecite;
01538 for ( vecite = Model::EntryList().begin();
01539 vecite != Model::EntryList().end(); vecite++ ) {
01540
01541 entryData = entryMgr->findEntryByLongName( (*vecite)->OptOCurrent()->longName(), (*vecite)->name() );
01542 if( ALIUtils::debug >= 3 ) std::cout << "SetValueDisplacementsFromReportOut "<< (*vecite)->OptOCurrent()->longName() << " " << (*vecite)->name() << " " << entryData->valueDisplacement() << std::endl;
01543 (*vecite)->addFittedDisplacementToValue( entryData->valueDisplacement() );
01544 }
01545 }
01546
01547 }
01548
01549
01550
01551 std::string Model::printCocoaStatus(const cocoaStatus cs)
01552 {
01553 std::string str ="";
01554
01555 if( cs == COCOA_Init ) {
01556 str = "COCOA_Init ";
01557 }else if( cs == COCOA_ReadingModel) {
01558 str = "COCOA_ReadingModel";
01559 }else if( cs == COCOA_InitFit) {
01560 str = "COCOA_InitFit";
01561 }else if( cs == COCOA_FitOK) {
01562 str = "COCOA_FitOK";
01563 }else if( cs == COCOA_FitImproving) {
01564 str = "COCOA_FitImproving";
01565 }else if( cs == COCOA_FitCannotImprove) {
01566 str = "COCOA_FitCannotImprove";
01567 }else if( cs == COCOA_FitChi2Worsened) {
01568 str = "COCOA_FitChi2Worsened";
01569 }else if( cs == COCOA_FitMatrixNonInversable) {
01570 str = "COCOA_FitMatrixNonInversable";
01571 }
01572
01573 return str;
01574 }
01575
01576
01577
01578 void Model::BuildSystemDescriptionFromOA( OpticalAlignments& optAlig )
01579 {
01580 theOpticalAlignments = optAlig.opticalAlignments();
01581
01582 OpticalAlignInfo oai_system = FindOptAlignInfoByType( "system" );
01583
01584 OpticalObject* OptOsystem = new OpticalObject( 0, "system", oai_system.name_, 0 );
01585
01586 OptOsystem->constructFromOptAligInfo( oai_system );
01587
01588
01589
01590 theOptOList.push_back( OptOsystem );
01591 }
01592
01593
01594
01595 OpticalAlignInfo Model::FindOptAlignInfoByType( const ALIstring& type )
01596 {
01597 OpticalAlignInfo oai;
01598
01599 ALIbool bFound = 0;
01600 std::vector<OpticalAlignInfo>::iterator ite;
01601 for( ite = theOpticalAlignments.begin(); ite != theOpticalAlignments.end(); ite++ ){
01602
01603 if( (*ite).type_ == type ) {
01604 if( !bFound ){
01605 oai = *ite;
01606 bFound = 1;
01607 } else {
01608 std::cerr << "!! WARNING: Model::FindOptAlignInfoByType more than one objects of type " << type << std::endl;
01609 std::cerr << " returning object " << oai.name_ << std::endl
01610 << " skipping object " << (*ite).name_ << std::endl;
01611 }
01612 }
01613 }
01614 if( !bFound ) {
01615 std::cerr << "!! ERROR: Model::FindOptAlignInfoByType object not found, of type " << type << std::endl;
01616 std::exception();
01617 }
01618
01619 return oai;
01620 }
01621
01622
01623
01624 void Model::BuildMeasurementsFromOA( OpticalAlignMeasurements& measList )
01625 {
01626 std::vector<OpticalAlignMeasurementInfo>::iterator mite;
01627
01628 if( ALIUtils::debug >= 5 ) std::cout << " BuildMeasurementsFromOA " << std::endl;
01629 std::vector<OpticalAlignMeasurementInfo> measInfos = measList.oaMeasurements_;
01630 for( mite = measInfos.begin(); mite != measInfos.end(); mite++ ) {
01631 std::string measType = (*mite).type_;
01632 std::string measName = (*mite).name_;
01633 std::cout << " BuildMeasurementsFromOA measType " << measType << " measName " << measName << std::endl;
01634
01635 Measurement* meastemp = 0;
01636 if ( measType == ALIstring("SENSOR2D") ) {
01637 meastemp = new MeasurementSensor2D( 2, measType, measName );
01638 } else if ( measType == ALIstring("DISTANCEMETER3DIM") ) {
01639 meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
01640 } else if ( measType == ALIstring("DISTANCEMETER") ||
01641 measType == ALIstring("DISTANCEMETER1DIM") ) {
01642 meastemp = new MeasurementDistancemeter( 1, measType, measName );
01643 } else if ( measType == ALIstring("TILTMETER") ) {
01644 meastemp = new MeasurementTiltmeter( 1, measType, measName );
01645 } else if ( measType == ALIstring("COPS") ) {
01646 meastemp = new MeasurementCOPS( 4, measType, measName );
01647 } else if ( measType == ALIstring("DIFFCENTRE") ) {
01648
01649 } else if ( measType == ALIstring("DIFFANGLE") ) {
01650
01651 } else if ( measType == ALIstring("DIFFENTRY") ) {
01652 meastemp = new MeasurementDiffEntry( 1, measType, measName );
01653 } else {
01654 std::cerr << " !!! Model::BuildMeasurementsFromOA : measType not found " << measType << std::endl;
01655 std::exception();
01656 }
01657 meastemp->constructFromOA( *mite );
01658
01659 }
01660 }