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 #include "Alignment/CocoaModel/interface/CocoaDaqReaderRoot.h"
00022
00023
00024 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00025 #include "Alignment/CocoaModel/interface/EntryAngle.h"
00026 #include "Alignment/CocoaModel/interface/ParameterMgr.h"
00027 #include "Alignment/CocoaModel/interface/ErrorCorrelationMgr.h"
00028
00029 #include "Alignment/CocoaModel/interface/EntryMgr.h"
00030 #include "Alignment/CocoaModel/interface/EntryData.h"
00031 #include "Alignment/CocoaModel/interface/FittedEntriesReader.h"
00032
00033 #include "CondFormats/OptAlignObjects/interface/OpticalAlignments.h"
00034 #include "CondFormats/OptAlignObjects/interface/OpticalAlignMeasurements.h"
00035
00036 #include <stdlib.h>
00037 #include <ctype.h>
00038
00039 #include <assert.h>
00040 #include <time.h>
00041
00042 #include <algorithm>
00043
00044 #ifdef OS_OSPACE_STD_NAMESPACE
00045 using namespace os_std;
00046 #endif
00047
00048
00049
00050
00051
00052 Model* Model::theInstance = 0;
00053
00054 std::vector< std::vector<ALIstring> > Model::theOptODictionary;
00055
00056
00057
00058 std::vector< OpticalObject* > Model::theOptOList;
00059 std::vector<Entry*> Model::theEntryVector;
00060 std::vector<Measurement*> Model::theMeasurementVector;
00061 std::vector<ALIdouble> Model::theParamFittedSigmaVector;
00062 std::map<ALIstring, ALIdouble, std::less<ALIstring> > Model::theParamFittedValueDisplacementMap;
00063 std::vector<OpticalObject*> Model::theOptOsToCopyList;
00064 std::vector<OpticalObject*>::const_iterator Model::theOptOsToCopyListIterator;
00065 ALIint Model::CMSLinkIteration = 0;
00066 ALIint Model::Ncmslinkrange = 0;
00067 std::vector<ALIdouble> Model::CMSLinkRangeDetValue;
00068 ALIstring Model::theSDFName = "SystemDescription.txt";
00069 ALIstring Model::theMeasFName = "Measurements.txt";
00070 ALIstring Model::theReportFName = "report.out";
00071 ALIstring Model::theMatricesFName = "matrices.out";
00072
00073
00074 cocoaStatus Model::theCocoaStatus = COCOA_Init;
00075 FittedEntriesReader* Model::theFittedEntriesReader = 0;
00076 std::vector<OpticalAlignInfo> Model::theOpticalAlignments;
00077
00078
00079
00080
00081 Model& Model::getInstance()
00082 {
00083 if(!theInstance) {
00084 theInstance = new Model;
00085 }
00086 return *theInstance;
00087 }
00088
00089
00090
00091
00092
00093 Model::Model()
00094 {
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 ( measType == ALIstring("measurements_from_file_ROOT") || measType == ALIstring("@measurements_from_file") ) {
00454 new CocoaDaqReaderRoot( wordlist[1] );
00455 } else if ( wordlist[0] == ALIstring("correlations_from_file") || wordlist[0] == ALIstring("@correlations_from_file") ) {
00456 ErrorCorrelationMgr::getInstance()->readFromReportFile( wordlist[1] );
00457 } else if ( wordlist[0] == ALIstring("copy_measurements") || wordlist[0] == ALIstring("@copy_measurements") ) {
00458 copyMeasurements( wordlist );
00459
00460
00461 } else if ( wordlist[0] == ALIstring("fittedEntries_from_file") ) {
00462 theFittedEntriesReader = new FittedEntriesReader( wordlist[1] );
00463 if ( ALIUtils::debug >= 2) std::cout << " setting fittedEntries_from_file " << wordlist[0] << " == " << wordlist[1] << std::endl;
00464 } else {
00465 std::cerr << "Measurement:" << std::endl;
00466 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00467 std::cerr << "!!! type of measurement not allowed: " << wordlist[0]
00468 << std::endl;
00469 std::cerr << " Allowed types: SENSOR2D, DISTANCEMETER, DISTANCEMETER1DIM, TILTMETER, COPS, DIFFENTRY " << std::endl;
00470 exit(2);
00471 }
00472
00473
00474
00475 } else if( currentSectionNo == sectReportOut ) {
00476
00477 if ( InSectionNo+1 != sectParameters ) {
00478 ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00479 std::cerr << "BAD ORDER OF SECTIONS, reading section "
00480 << *SectionTitleIterator << std::endl
00481 << " currentSectionNo = " << currentSectionNo << " InSectionNo = " << InSectionNo << std::endl
00482 << " --------- Please see documentation ---------- " << std::endl;
00483 exit(1);
00484 }
00485
00486 EntryMgr::getInstance()->readEntryFromReportOut( wordlist );
00487 }
00488 }
00489
00490
00491
00492
00493
00494 if ( ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ Building Measurements links to OptOs" << std::endl;
00495 Model::buildMeasurementsLinksToOptOs();
00496
00497 if ( ALIUtils::debug >= 1) {
00498 std::cout << "---------- SYSTEM SUCCESFULLY READ ----------" << std::endl << std::endl;
00499 }
00500 filein.close();
00501
00502 return;
00503
00504 }
00505
00506
00507
00508
00509
00510
00511 void Model::reorderOptODictionary(const ALIstring& ssearch, std::vector< std::vector<ALIstring> >& OptODictionary2 ){
00512
00513
00514 std::vector< std::vector<ALIstring> >::iterator vvsite;
00515 std::vector< ALIstring >::iterator vsite;
00516
00517
00518 for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
00519 if( *( (*vvsite).begin() ) == ssearch ) {
00520
00521 OptODictionary2.push_back(*vvsite);
00522
00523
00524
00525
00526
00527
00528 for( vsite = (*vvsite).begin()+1; vsite != (*vvsite).end(); ++vsite ) {
00529 reorderOptODictionary( *vsite, OptODictionary2 );
00530 }
00531 break;
00532 }
00533 }
00534
00535
00536
00537
00538
00539
00540
00541 }
00542
00543
00544
00545
00546 void Model::buildMeasurementsLinksToOptOs(){
00547
00548
00549 std::vector< Measurement* >::const_iterator vmcite;
00550 for ( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++) {
00551
00552
00553
00554
00555
00556
00557 }
00558
00559 }
00560
00561
00562
00563
00564
00565 ALIint Model::getParameterValue( const ALIstring& sstr, ALIdouble& val )
00566 {
00567 ParameterMgr* parmgr = ParameterMgr::getInstance();
00568 ALIint iret = parmgr->getParameterValue( sstr, val );
00569
00570 return iret;
00571
00572 }
00573
00574
00575
00576
00577
00578 OpticalObject* Model::getOptOByName( const ALIstring& opto_name )
00579 {
00580
00581 std::vector< OpticalObject* >::const_iterator vocite;
00582 for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00583 if( (*vocite)->name() == opto_name ) break;
00584 }
00585
00586 if ( vocite == OptOList().end() ) {
00587
00588 std::cerr << " LIST OF OpticalObjects " << std::endl;
00589 for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00590 std::cerr << (*vocite)->name() << std::endl;
00591 }
00592 std::cerr << "!!EXITING at getOptOByName: Optical Object " << opto_name << " doesn't exist!!" << std::endl;
00593 exit(4);
00594
00595 } else {
00596
00597 if( ALIUtils::debug>999) {
00598 std::cout << opto_name.c_str() << "SSOptOitem" << (*vocite) << (*vocite)->name() << "len" << OptOList().size() << std::endl;
00599 }
00600 return (*vocite);
00601 }
00602
00603 }
00604
00605
00606
00607
00608
00609
00610 OpticalObject* Model::getOptOByType( const ALIstring& opto_type )
00611 {
00612
00613 std::vector< OpticalObject* >::const_iterator vocite;
00614 for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00615
00616 if( (*vocite)->type() == opto_type ) break;
00617 }
00618
00619 if ( vocite == OptOList().end() ) {
00620
00621 std::cerr << "!!EXITING at getOptOByType: Optical Object " << opto_type << " doesn't exist!!" << std::endl;
00622 exit(4);
00623 } else {
00624
00625 return (*vocite);
00626 }
00627
00628 }
00629
00630
00631
00632
00633 Entry* Model::getEntryByName( const ALIstring& opto_name, const ALIstring& entry_name )
00634 {
00635
00636 std::vector<Entry*>::const_iterator vecite;
00637 for( vecite = EntryList().begin(); vecite != EntryList().end(); vecite++) {
00638 if( ALIUtils::debug >= 4 ) std::cout << "getEntryByName: " <<(*vecite)->OptOCurrent()->name()
00639 << " E " << (*vecite)->name() << " Searching: " << opto_name << " E " << entry_name << std::endl;
00640
00641 if( (*vecite)->OptOCurrent()->name() == opto_name &&
00642 (*vecite)->name() == entry_name ) {
00643 return *vecite;
00644 }
00645 }
00646
00647 std::cerr << "!!!EXITING at getEntryByName: Entry name not found:" << opto_name << " " << entry_name << std::endl;
00648 exit(1);
00649 }
00650
00651
00652
00653 Measurement* Model::getMeasurementByName( const ALIstring& meas_name, ALIbool exists )
00654 {
00655
00656 std::vector< Measurement* >::const_iterator vmcite;
00657 for( vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); vmcite++ ) {
00658 if( (*vmcite)->name() == meas_name ) break;
00659 }
00660
00661 if ( vmcite != theMeasurementVector.end() ) {
00662
00663 return (*vmcite);
00664 }else {
00665 if( exists ) {
00666
00667 std::cerr << " LIST OF Measurements " << std::endl;
00668 for( vmcite = theMeasurementVector.begin(); vmcite != theMeasurementVector.end(); vmcite++ ) {
00669 std::cerr << (*vmcite)->name() << std::endl;
00670 }
00671 std::cerr << "!!EXITING at getMeasurementByName: Measurement " << meas_name << " doesn't exist!!" << std::endl;
00672 abort();
00673
00674 } else {
00675 return 0;
00676 }
00677
00678 }
00679
00680
00681 }
00682
00683
00684
00685
00686
00687
00688
00689
00690 ALIbool Model::getComponentOptOTypes( const ALIstring& opto_type, std::vector<ALIstring>& vcomponents )
00691 {
00692
00693 std::vector<ALIstring>::iterator vsite;
00694 for (vsite = vcomponents.begin(); vsite != vcomponents.end(); vsite++) {
00695 vcomponents.pop_back();
00696 }
00697
00698
00699 ALIint ALIstring_found = 0;
00700 std::vector< std::vector<ALIstring> >::iterator vvsite;
00701 for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
00702 if( *( (*vvsite).begin() ) == opto_type ) {
00703 ALIstring_found = 1;
00704
00705 vcomponents = *vvsite;
00706 vcomponents.erase( vcomponents.begin() );
00707 break;
00708 }
00709 }
00710
00711 if ( ALIstring_found ) {
00712 return 1;
00713 } else {
00714 return 0;
00715 }
00716 }
00717
00718
00719
00720
00721
00722
00723 ALIbool Model::getComponentOptOs( const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents)
00724 {
00725
00726 std::vector<OpticalObject*>::iterator voite;
00727 for (voite = vcomponents.begin(); voite != vcomponents.end(); voite++) {
00728 vcomponents.pop_back();
00729 }
00730
00731
00732 OpticalObject* opto = getOptOByName( opto_name );
00733
00734 if ( ALIUtils::debug >= 99) std::cout << opto_name << "getComponentOptOs: opto " << opto << opto->name() << std::endl;
00735 std::vector<OpticalObject*>::const_iterator vocite;
00736
00737 if ( ALIUtils::debug >= 99) std::cout << "optolist size " << OptOList().size() << std::endl;
00738 ALIbool opto_found = 0;
00739 for (vocite = OptOList().begin(); vocite != OptOList().end(); vocite++) {
00740 if( (*vocite)->parent() != 0 ) {
00741
00742 if( (*vocite)->parent()->name() == opto_name ) {
00743 opto_found = 1;
00744 vcomponents.push_back( (*vocite) );
00745 }
00746 }
00747 }
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760 return opto_found;
00761
00762 }
00763
00764
00766
00767
00768
00769 ALIbool Model::createCopyComponentList( const ALIstring& typ )
00770 {
00771
00772 if(ALIUtils::debug >= 3) std::cout << "createCopyComponentList " << typ << std::endl;
00773 OpticalObject* start_opto = getOptOByType( typ );
00774
00775
00776 theOptOsToCopyList.erase( theOptOsToCopyList.begin(), theOptOsToCopyList.end() );
00777
00778
00779 fillCopyComponentList( start_opto );
00780
00781
00782 theOptOsToCopyListIterator = theOptOsToCopyList.begin();
00783 return 1;
00784 }
00785
00786
00787
00788
00789
00790 ALIbool Model::fillCopyComponentList( const OpticalObject* opto )
00791 {
00792 if(ALIUtils::debug >= 3) std::cout << "entering fillCopyComponentList(): OptO" << opto->name() << std::endl;
00793
00794 std::vector<OpticalObject*> vopto;
00795 ALIbool opto_found = getComponentOptOs( opto->name(), vopto);
00796 if( !opto_found ) {
00797 if(ALIUtils::debug >= 5) std::cout << "fillCopyComponentList: NO COMPONENTS TO COPY IN THIS OptO" << opto->name() << std::endl ;
00798 }
00799
00800
00801 std::vector<OpticalObject*>::const_iterator vocite;
00802 for( vocite = vopto.begin(); vocite != vopto.end(); vocite++ ){
00803 theOptOsToCopyList.push_back( *vocite );
00804 if(ALIUtils::debug >= 5) std::cout << "fillCopyOptOList " << (*vocite)->type() << " " << (*vocite)->name() << std::endl;
00805
00806 fillCopyComponentList( *vocite );
00807 }
00808 return opto_found;
00809 }
00810
00811
00812
00813
00814
00815
00816 OpticalObject* Model::nextOptOToCopy()
00817 {
00818 if(ALIUtils::debug >= 5) std::cout << "entering nextOptOToCopy() " << std::endl;
00819 theOptOsToCopyListIterator++;
00820
00821 return *(theOptOsToCopyListIterator-1);
00822 }
00823
00824
00826
00827
00828
00829 void Model::CMSLinkFit( ALIint cmslink)
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
00886
00887 void Model::CMSLinkCleanModel()
00888 {
00889 deleteOptO("s");
00890
00891 ALIuint odsize = theOptODictionary.size();
00892 for( ALIuint ii = 0; ii < odsize; ii++) {
00893 theOptODictionary.pop_back();
00894 }
00895
00896 }
00897
00898
00899
00900
00901
00902 void Model::CMSLinkDeleteOptOs( )
00903 {
00904 ALIint cmslink_iter = Model::CMSLinkIteration;
00905 ALIdouble cmslink_method;
00906
00907 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
00908 assert(gomgr->getGlobalOptionValue("cms_link_method", cmslink_method));
00909 ALIdouble cmslink_halfplanes;
00910 assert(gomgr->getGlobalOptionValue("cms_link_halfplanes", cmslink_halfplanes));
00911 if(ALIUtils::debug >= 2) std::cout << "CMSLinkDeleteOptOs: cms_link_halfplanes " << cmslink_halfplanes << cmslink_iter << std::endl;
00912
00913 if( cmslink_iter == 1){
00914
00915
00916
00917 deleteOptO("s/mabsL");
00918
00919 if (cmslink_method == 1){
00920 deleteOptO("s/tracker/det_trkDL");
00921 deleteOptO("s/tracker/det_trkDR");
00922 }
00923
00924 if( cmslink_halfplanes == 2) {
00925
00926 deleteOptO("s/mabsR");
00927 }
00928
00929 } else if( cmslink_iter == 2) {
00930
00931
00932 deleteOptO("s/mabsL");
00933 deleteOptO("s/tracker/CST/wheel_trkL/peri/mirror");
00934 deleteOptO("s/tracker/CST/wheel_trkL/det_trkU");
00935
00936
00937
00938 if( cmslink_halfplanes <= 1) {
00939 deleteOptO("s/tracker/CST/wheel_trkR");
00940 } else if( cmslink_halfplanes == 2) {
00941
00942 deleteOptO("s/mabsR");
00943 deleteOptO("s/tracker/CST/wheel_trkR/peri/mirror");
00944 deleteOptO("s/tracker/CST/wheel_trkR/det_trkU");
00945 }
00946
00947 } else if( cmslink_iter == 3) {
00948
00949
00950 deleteOptO("s/tracker");
00951
00952 if( cmslink_halfplanes == 2) {
00953
00954 }
00955
00956 } else {
00957
00958 }
00959
00960 }
00961
00962
00963
00964
00965
00966 void Model::CMSLinkSaveParamFittedSigma( ALIint cms_link )
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
01030
01031 void Model::CMSLinkSaveParamFittedValueDisplacement( ALIint cms_link )
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
01057
01058 void Model::CMSLinkRecoverParamFittedSigma( ALIint cms_link )
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
01118
01119 void Model::CMSLinkRecoverParamFittedValueDisplacement( ALIint cms_link )
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
01146
01147 void Model::deleteOptO( const ALIstring& opto_name )
01148 {
01149 OpticalObject* opto = getOptOByName( opto_name );
01150 deleteOptO( opto );
01151 }
01152
01153
01154
01155
01156
01157 void Model::deleteOptO( OpticalObject* opto )
01158 {
01159 if(ALIUtils::debug >= 5 ) std::cout << "DELETING OptO" << opto->name() << std::endl;
01160
01161
01162 std::vector<Entry*>::const_iterator vecite;
01163 std::vector<Entry*>::iterator veite2;
01164 if ( ALIUtils::debug >= 9) std::cout << "SIZE" << theEntryVector.size() <<std::endl;
01165 for( vecite = opto->CoordinateEntryList().begin(); vecite != opto->CoordinateEntryList().end(); vecite++) {
01166
01167 veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
01168
01169 delete ( (*veite2) );
01170 theEntryVector.erase( veite2 );
01171 }
01172
01173 for( vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); vecite++) {
01174
01175 veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
01176
01177 delete ( (*veite2) );
01178 theEntryVector.erase( veite2 );
01179 }
01180
01181
01182 for( vecite = theEntryVector.begin(); vecite != theEntryVector.end(); vecite++ ) {
01183
01184 }
01185
01186
01187 std::vector<Measurement*> MeasToBeDeleted;
01188 std::vector<Measurement*>::const_iterator vmite;
01189 std::vector<OpticalObject*>::const_iterator vocite;
01190 for( vmite = MeasurementList().begin(); vmite != MeasurementList().end(); vmite++ ) {
01191 if(ALIUtils::debug >= 5) std::cout << "Deleting Measurement" << (*vmite)->name() << std::endl;
01192
01193 for( vocite = (*vmite)->OptOList().begin(); vocite != (*vmite)->OptOList().end(); vocite++) {
01194 if( (*vocite) == opto ) {
01195
01196 MeasToBeDeleted.push_back( *vmite );
01197
01198 break;
01199 }
01200 }
01201 }
01202
01203
01204 std::vector<Measurement*>::const_iterator vmcite;
01205 std::vector<Measurement*>::iterator vmite2;
01206 if ( ALIUtils::debug >= 9) std::cout << "SIZEMEAS" << MeasToBeDeleted.size() <<std::endl;
01207 for( vmcite = MeasToBeDeleted.begin(); vmcite != MeasToBeDeleted.end(); vmcite++) {
01208 vmite2 = find( theMeasurementVector.begin(), theMeasurementVector.end(), (*vmcite) );
01209
01210 delete ( (*vmite2) );
01211 theMeasurementVector.erase( vmite2 );
01212 }
01213
01214
01215
01216
01217 std::vector<OpticalObject*> vopto;
01218
01219 for( vocite = vopto.begin(); vocite != vopto.end(); vocite++ ) {
01220 deleteOptO( *vocite );
01221 }
01222
01223
01224
01225
01226
01227
01228 std::vector< OpticalObject* >::iterator dvoite =
01229 find( theOptOList.begin(), theOptOList.end(),
01230 std::vector< OpticalObject* >::value_type( opto) );
01231
01232 theOptOList.erase( dvoite );
01233 delete opto;
01234
01235 }
01236
01237
01238
01239
01240
01241 void Model::saveParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name)
01242 {
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254
01255
01256 }
01257
01258
01259
01260
01261
01262 void Model::saveParamFittedCorrelation( const ALIstring& opto_name1, const ALIstring& entry_name1, const ALIstring& opto_name2, const ALIstring& entry_name2)
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
01297
01298 void Model::recoverParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position )
01299 {
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313 }
01314
01315
01316
01317
01318
01319 ALIdouble Model::getParamFittedSigmaVectorItem( const ALIuint position )
01320 {
01321 if( position >= theParamFittedSigmaVector.size() ) {
01322 std::cerr << "!!EXITING at getParamFittedSigma: position" << position <<
01323 " bigger than dimension of theParamFittedSigmaVector " << theParamFittedSigmaVector.size() << std::endl;
01324 exit(3);
01325 }
01326 std::vector<ALIdouble>::const_iterator vdcite = theParamFittedSigmaVector.begin() + position;
01327 return (*vdcite);
01328
01329 }
01330
01331
01332
01333
01334
01335
01336 ALIbool Model::readMeasurementsFromFile(ALIstring only1Date, ALIstring only1Time )
01337 {
01338 if(ALIUtils::debug >= 5) std::cout << " readMeasurementsFromFile " << Measurement::measurementsFileName() << std::endl;
01339 if( Measurement::measurementsFileName() == "") return 1;
01340
01341 ALIFileIn& filein = ALIFileIn::getInstance( Measurement::measurementsFileName() );
01342 std::vector<ALIstring> wordlist;
01343
01344
01345
01346
01347 if( filein.getWordsInLine(wordlist) == 0 ) {
01348 if(ALIUtils::debug>=4 ) std::cout << "@@@@ No more measurements left" << std::endl;
01349 return 0;
01350 }
01351
01353
01354
01355
01356
01357 if( Measurement::only1 ) {
01358 for(;;) {
01359 if( wordlist[0] == "DATE:" && wordlist[1] == Measurement::only1Date && wordlist[2] == Measurement::only1Time ) break;
01360 filein.getWordsInLine(wordlist);
01361 if(filein.eof() ) {
01362 std::cerr << "!! EXITING date not found in measurements file" << Measurement::only1Date << " " << Measurement::only1Time << std::endl;
01363 exit(1);
01364 }
01365 }
01366 }
01367
01368
01369 if( wordlist[0] == "DATE:" ) {
01370 Measurement::setCurrentDate( wordlist );
01371 }
01372
01373
01374 ALIint nMeas = Model::MeasurementList().size();
01375 if(ALIUtils::debug >= 4) {
01376 std::cout << " Reading " << nMeas << " measurements from file " << Measurement::measurementsFileName()
01377 << " DATE: " << wordlist[1] << " " << wordlist[1] << std::endl;
01378 }
01379 ALIint ii;
01380 for(ii = 0; ii < nMeas; ii++) {
01381 filein.getWordsInLine(wordlist);
01382 if( wordlist[0] == ALIstring("SENSOR2D") || wordlist[0] == ALIstring("TILTMETER") || wordlist[0] == ALIstring("DISTANCEMETER") || wordlist[0] == ALIstring("DISTANCEMETER1DIM") || wordlist[0] == ALIstring("COPS") ) {
01383 if( wordlist.size() != 2 ) {
01384 std::cerr << "!!!EXITING Model::readMeasurementsFromFile. number of words should be 2 instead of " << wordlist.size() << std::endl;
01385 ALIUtils::dumpVS( wordlist, " " );
01386 exit(1);
01387 }
01388 std::vector< Measurement* >::const_iterator vmcite;
01389 for( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++ ) {
01390
01391
01392
01393
01394
01395
01396
01397 ALIint fcolon = (*vmcite)->name().find(':');
01398 ALIstring oname = (*vmcite)->name();
01399 oname = oname.substr(fcolon+1,oname.length());
01400
01401 if( oname == wordlist[1] ) {
01402
01403 if( (*vmcite)->type() != wordlist[0] ) {
01404 std::cerr << "!!! Reading measurement from file: type in file is "
01405 << wordlist[0] << " and should be " << (*vmcite)->type() << std::endl;
01406 exit(1);
01407 }
01408 Measurement* meastemp = *vmcite;
01409
01410 GlobalOptionMgr* gomgr = GlobalOptionMgr::getInstance();
01411 ALIbool sigmaFF = gomgr->GlobalOptions()["measurementErrorFromFile"];
01412
01413 for ( ALIuint ii=0; ii < meastemp->dim(); ii++){
01414 filein.getWordsInLine( wordlist );
01415 ALIdouble sigma = 0.;
01416 if( !sigmaFF ) {
01417
01418 const ALIdouble* sigmav = meastemp->sigma();
01419 sigma = sigmav[ii];
01420 }
01421
01422 if( meastemp->valueType(ii) != wordlist[0] ) {
01423 filein.ErrorInLine();
01424 std::cerr << "!!!FATAL ERROR: Measurement value type is " << wordlist[0] << " while in setup definition was " << meastemp->valueType(ii) << std::endl;
01425 exit(1);
01426 }
01427 meastemp->fillData( ii, wordlist );
01428 if( !sigmaFF ) {
01429 meastemp->setSigma( ii, sigma );
01430 }
01431 }
01432 meastemp->correctValueAndSigma();
01433 break;
01434 }
01435 }
01436 if( vmcite == MeasurementList().end() ) {
01437 for( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++ ) {
01438 std::cerr << "MEAS: " << (*vmcite)->name() << " " << (*vmcite)->type() << std::endl;
01439 }
01440 std::cerr << "!!! Reading measurement from file: measurement not found in list: type in file is " << wordlist[1] << std::endl;
01441 exit(1);
01442 }
01443 } else {
01444 std::cerr << " wrong type of measurement: " << wordlist[0] << std::endl
01445 << " Available types are SENSOR2D, TILTMETER, DISTANCEMETER, DISTANCEMETER1DIM, COPS" << std::endl;
01446 exit(1);
01447 }
01448 }
01449
01450
01451 return 1;
01452 }
01453
01454
01455
01456
01457
01458 void Model::copyMeasurements( const std::vector<ALIstring>& wl )
01459 {
01460
01461
01462
01463
01464
01465
01466 std::string subsstr1 = wl[1].substr( 0, wl[1].find("/") );
01467 std::string subsstr2 = wl[1].substr( wl[1].find("/")+1, wl[1].rfind("/") - wl[1].find("/")-1 );
01468 std::string querystr = wl[1].substr( wl[1].rfind("/")+1, wl[1].length() );
01469
01470 std::cout << " Model::copyMeasurements " << " subsstr1 " << subsstr1 << " subsstr2 " << subsstr2 << " querystr " << querystr << std::endl;
01471
01472 std::vector< Measurement* > measToCopy;
01473 std::vector< Measurement* >::iterator mite;
01474 for( mite = theMeasurementVector.begin(); mite != theMeasurementVector.end(); mite++) {
01475 Measurement* meas = (*mite);
01476
01477 if( meas->name().find( querystr ) != std::string::npos ) {
01478 measToCopy.push_back( meas );
01479 }
01480 }
01481
01482
01483 Measurement* meastemp = 0;
01484 for( mite = measToCopy.begin(); mite != measToCopy.end(); mite++) {
01485 Measurement* meas = (*mite);
01486 std::vector<ALIstring> wlt;
01487 wlt.push_back( meas->type() );
01488
01489
01490 std::string newName = ALIUtils::changeName( meas->name(), subsstr1, subsstr2 );
01491 std::cout << " newName " << newName << std::endl;
01492 wlt.push_back( newName );
01493
01494 ALIstring measType = wlt[0];
01495 ALIstring measName;
01496 if( wlt.size() == 2 ) {
01497 measName = wlt[1];
01498 } else {
01499 measName = "";
01500 }
01501 if ( meas->type() == ALIstring("SENSOR2D") ) {
01502 meastemp = new MeasurementSensor2D( 2, measType, measName );
01503
01504
01505 } else if ( meas->type() == ALIstring("DISTANCEMETER") ||
01506 meas->type() == ALIstring("DISTANCEMETER1DIM") ) {
01507 meastemp = new MeasurementDistancemeter( 1, measType, measName );
01508 } else if ( meas->type() == ALIstring("TILTMETER") ) {
01509 meastemp = new MeasurementTiltmeter( 1, measType, measName );
01510 } else if ( meas->type() == ALIstring("DIFFCENTRE") ) {
01511
01512 } else if ( meas->type() == ALIstring("DIFFANGLE") ) {
01513
01514 } else if ( meas->type() == ALIstring("DIFFENTRY") ) {
01515 meastemp = new MeasurementDiffEntry( 1, measType, measName );
01516 } else if ( meas->type() == ALIstring("COPS") ) {
01517 meastemp = new MeasurementCOPS( 4, measType, measName );
01518 }
01519
01520
01521 meastemp->copyMeas(meas, subsstr1, subsstr2);
01522
01523 break;
01524 }
01525
01526 }
01527
01528
01529
01530 void Model::SetValueDisplacementsFromReportOut()
01531 {
01532 if( ALIUtils::debug >= 3 ) std::cout << " Model::SetValueDisplacementsFromReportOut() " << std::endl;
01533
01534 EntryMgr* entryMgr = EntryMgr::getInstance();
01535
01536 if( entryMgr->numberOfEntries() != 0 ){
01537 EntryData* entryData;
01538
01539 std::vector<Entry*>::const_iterator vecite;
01540 for ( vecite = Model::EntryList().begin();
01541 vecite != Model::EntryList().end(); vecite++ ) {
01542
01543 entryData = entryMgr->findEntryByLongName( (*vecite)->OptOCurrent()->longName(), (*vecite)->name() );
01544 if( ALIUtils::debug >= 3 ) std::cout << "SetValueDisplacementsFromReportOut "<< (*vecite)->OptOCurrent()->longName() << " " << (*vecite)->name() << " " << entryData->valueDisplacement() << std::endl;
01545 (*vecite)->addFittedDisplacementToValue( entryData->valueDisplacement() );
01546 }
01547 }
01548
01549 }
01550
01551
01552
01553 std::string Model::printCocoaStatus(const cocoaStatus cs)
01554 {
01555 std::string str ="";
01556
01557 if( cs == COCOA_Init ) {
01558 str = "COCOA_Init ";
01559 }else if( cs == COCOA_ReadingModel) {
01560 str = "COCOA_ReadingModel";
01561 }else if( cs == COCOA_InitFit) {
01562 str = "COCOA_InitFit";
01563 }else if( cs == COCOA_FitOK) {
01564 str = "COCOA_FitOK";
01565 }else if( cs == COCOA_FitImproving) {
01566 str = "COCOA_FitImproving";
01567 }else if( cs == COCOA_FitCannotImprove) {
01568 str = "COCOA_FitCannotImprove";
01569 }else if( cs == COCOA_FitChi2Worsened) {
01570 str = "COCOA_FitChi2Worsened";
01571 }else if( cs == COCOA_FitMatrixNonInversable) {
01572 str = "COCOA_FitMatrixNonInversable";
01573 }
01574
01575 return str;
01576 }
01577
01578
01579
01580 void Model::BuildSystemDescriptionFromOA( OpticalAlignments& optAlig )
01581 {
01582 theOpticalAlignments = optAlig.opticalAlignments();
01583
01584 OpticalAlignInfo oai_system = FindOptAlignInfoByType( "system" );
01585
01586 OpticalObject* OptOsystem = new OpticalObject( 0, "system", oai_system.name_, 0 );
01587
01588 OptOsystem->constructFromOptAligInfo( oai_system );
01589
01590
01591
01592 theOptOList.push_back( OptOsystem );
01593 }
01594
01595
01596
01597 OpticalAlignInfo Model::FindOptAlignInfoByType( const ALIstring& type )
01598 {
01599 OpticalAlignInfo oai;
01600
01601 ALIbool bFound = 0;
01602 std::vector<OpticalAlignInfo>::iterator ite;
01603 for( ite = theOpticalAlignments.begin(); ite != theOpticalAlignments.end(); ite++ ){
01604
01605 if( (*ite).type_ == type ) {
01606 if( !bFound ){
01607 oai = *ite;
01608 bFound = 1;
01609 } else {
01610 std::cerr << "!! WARNING: Model::FindOptAlignInfoByType more than one objects of type " << type << std::endl;
01611 std::cerr << " returning object " << oai.name_ << std::endl
01612 << " skipping object " << (*ite).name_ << std::endl;
01613 }
01614 }
01615 }
01616 if( !bFound ) {
01617 std::cerr << "!! ERROR: Model::FindOptAlignInfoByType object not found, of type " << type << std::endl;
01618 std::exception();
01619 }
01620
01621 return oai;
01622 }
01623
01624
01625
01626 void Model::BuildMeasurementsFromOA( OpticalAlignMeasurements& measList )
01627 {
01628 std::vector<OpticalAlignMeasurementInfo>::iterator mite;
01629
01630 if( ALIUtils::debug >= 5 ) std::cout << " BuildMeasurementsFromOA " << std::endl;
01631 std::vector<OpticalAlignMeasurementInfo> measInfos = measList.oaMeasurements_;
01632 for( mite = measInfos.begin(); mite != measInfos.end(); mite++ ) {
01633 std::string measType = (*mite).type_;
01634 std::string measName = (*mite).name_;
01635 if( ALIUtils::debug >= 4 ) std::cout << " BuildMeasurementsFromOA measType " << measType << " measName " << measName << std::endl;
01636
01637 Measurement* meastemp = 0;
01638 if ( measType == ALIstring("SENSOR2D") ) {
01639 meastemp = new MeasurementSensor2D( 2, measType, measName );
01640 } else if ( measType == ALIstring("DISTANCEMETER3DIM") ) {
01641 meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
01642 } else if ( measType == ALIstring("DISTANCEMETER") ||
01643 measType == ALIstring("DISTANCEMETER1DIM") ) {
01644 meastemp = new MeasurementDistancemeter( 1, measType, measName );
01645 } else if ( measType == ALIstring("TILTMETER") ) {
01646 meastemp = new MeasurementTiltmeter( 1, measType, measName );
01647 } else if ( measType == ALIstring("COPS") ) {
01648 meastemp = new MeasurementCOPS( 4, measType, measName );
01649 } else if ( measType == ALIstring("DIFFCENTRE") ) {
01650
01651 } else if ( measType == ALIstring("DIFFANGLE") ) {
01652
01653 } else if ( measType == ALIstring("DIFFENTRY") ) {
01654 meastemp = new MeasurementDiffEntry( 1, measType, measName );
01655 } else {
01656 std::cerr << " !!! Model::BuildMeasurementsFromOA : measType not found " << measType << std::endl;
01657 std::exception();
01658 }
01659 meastemp->constructFromOA( *mite );
01660
01661 }
01662 }