CMS 3D CMS Logo

Model.cc

Go to the documentation of this file.
00001 //   COCOA class implementation file
00002 //Id:  Model.cc
00003 //CAT: Model
00004 //
00005 //   History: v1.0 
00006 //   Pedro Arce
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 //t#include "Alignment/CocoaModel/interface/MeasurementDiffAngle.h"
00022 //t#include "Alignment/CocoaModel/interface/MeasurementCentreEntry.h"
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 //#include "Alignment/Scan/interface/ScanMgr.h"
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 //#include <algo.h>
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 //using namespace os_std;
00048 
00049 
00050 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00051 Model* Model::theInstance = 0;
00052 //map< ALIstring, ALIdouble, std::less<ALIstring> > Model::theParameters;
00053 std::vector< std::vector<ALIstring> > Model::theOptODictionary;
00054 //-map< ALIstring, int, std::less<ALIstring> > Model::theStandardMeasurerTypes;
00055 //-multimap< ALIstring, OpticalObject*, std::less<ALIstring> > Model::_OptOtree;
00056 //map< ALIstring, OpticalObject*, std::less<ALIstring> > Model::theOptOlist;
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 //struct tm Model::theMeasurementsTime = struct tm();
00072 // struct tm Model::theMeasurementsTime;
00073 cocoaStatus Model::theCocoaStatus = COCOA_Init;
00074 FittedEntriesReader* Model::theFittedEntriesReader = 0;
00075 std::vector<OpticalAlignInfo> Model::theOpticalAlignments;
00076 
00077 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00078 //@@  Gets the only instance of Model
00079 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00080 Model& Model::getInstance()
00081 {
00082   if(!theInstance) {
00083     theInstance = new Model;
00084   }
00085   return *theInstance;
00086 }
00087 
00088 
00089 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00090 //@@  Constructor
00091 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00092 Model::Model()
00093 {
00094   GlobalOptionMgr::getInstance()->setDefaultGlobalOptions();
00095   //  theMeasurementsTime = clock();
00096 }
00097 
00098 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00099 //@@  Reads the System Description file section by section and acts accordingly
00100 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00101 void Model::readSystemDescription()
00102 {
00103   Model::setCocoaStatus( COCOA_Init );
00104   
00105   ALIint data_reading = 0;  // variable to identify the first line of section SYSTEM_TREE_DATA 
00106   
00107   //---------- Open the system description file
00108   ALIFileIn& filein = ALIFileIn::getInstance( Model::SDFName());
00109  
00110   //----------- Set section titles
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   //---------------------------------------- Loops lines in SDF file  
00121   std::vector<ALIstring> wordlist;
00122   ALIint InSectionNo = -1; 
00123   ALIint currentSectionNo = -1; 
00124   while (!filein.eof()) {
00125 
00126     if( !filein.getWordsInLine(wordlist) ) break;  //----- Read line
00127     assert( wordlist.size() != 0 );
00128 
00129     //----- checking
00130     if( ALIUtils::debug > 99) {
00131       ALIUtils::dumpVS( wordlist, " ", std::cout );
00132     }
00133 
00134     //---------- Get in which section the current line is and act accordingly
00135 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00136 //@@@ ---------- Check if word is start of section 
00137     SectionTitleIterator = find(SectionTitle.begin(), SectionTitle.end(), *wordlist.begin());
00138     if( SectionTitleIterator != SectionTitle.end() ) { 
00139       //---------- Check that previous sections are correct
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 //@@@ ---------- Reading GLOBAL_OPTIONS section
00163     } else if( currentSectionNo == sectGlobalOptions ) {
00164       //-       std::cout << "utilsdebug " << ALIUtils::debug << std::endl;
00165       //-------- Check format of line read
00166       //----- Two words
00167       if( wordlist.size() == 2 ) {
00168         //----- Second word is number
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           //-or    GlobalOptions.insert(std::pair<const ALIstring, ALIdouble>(wordlist[0] , atof(wordlist[1].c_str()) ) );
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       //------- Set dimension factors for lengths and angles
00193       ALIUtils::SetLengthDimensionFactors();
00194       ALIUtils::SetAngleDimensionFactors();
00195       ALIUtils::SetOutputLengthDimensionFactors();
00196       ALIUtils::SetOutputAngleDimensionFactors();
00197 
00198 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00199 //@@@ ---------- Reading PARAMETERS section
00200     } else if( currentSectionNo == sectParameters ||
00201                currentSectionNo == -1 ) {  // Allow parameters in first lines (for easy study of different parameter values)
00202 
00203       //---------- Check format of line read
00204       //----- Two words
00205       if( wordlist.size() == 2 ) {
00206         /* now checked in ParameterMgr
00207         //----- Second is number
00208         int isnumber = ALIUtils::IsNumber( wordlist[1] );
00209         if( !isnumber ) {
00210           ALIFileIn::getInstance( Model::SDFName() ).ErrorInLine();
00211           std::cerr << ": EXPECTING A NUMBER, FOUND: " << wordlist[1] << std::endl;
00212           exit(2);
00213           } */
00214         
00215         //old---------- Create parameter with value read (or overwrite existing value)
00216         //---------- Create parameter with value read if parameter does not exist yet
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       //print it out
00252       if( ALIUtils::debug >= 1) { 
00253         ALIUtils::dumpVS( wordlist, "PARAMETERS:  ", std::cout );
00254       }
00255     
00256 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00257 //@@@ ---------- Reading SYSTEM_TREE_DESCRIPTION section
00258     } else if( currentSectionNo == sectSystemTreeDescription ) {
00259 
00260       //---------- Convert the numbers found in list of components (e.g. 2 laser -> laser laser )
00261       //----- Backup wordlist and erase it
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       //----- Loop objects looking for numbers to convert
00269       for ( vsite=wordlist2.begin(); vsite!=wordlist2.end(); vsite++ ) {
00270         if( ALIUtils::IsNumber( *vsite ) ) {
00271           int nOpticalObjects = atoi( (*vsite).c_str() );
00272           //----- If number is 1 it is not necessary
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             //-    wordlist.erase( wordlist.begin() + (vsite-wordlist2.begin()) );
00277           } else {
00278             //----- The number cannot be the last in the list and you cannot put two numbers together
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             //----- Right format: convert
00285             //--- Substitute the number by the object type in wordlist
00286             //-   *( wordlist.begin() + (vsite-wordlist2.begin()) ) = *(vsite+1);
00287             //--- Add n-1 object types to wordlist (the nth object will be added as the object taht goes after the number)
00288             for ( ALIint ii=0; ii<nOpticalObjects-1; ii++ ) {
00289               //-std::cout << ii << "inserting in wordlist " << *(vsite+1) << std::endl;
00290               wordlist.push_back( *(vsite+1) ); 
00291             }
00292           }
00293         } else {
00294           //----- Not number, add it to wordlist
00295           wordlist.push_back( *vsite );
00296         }
00297       }
00298 
00299       //---------- Dump system structure
00300       if ( ALIUtils::debug >= 1 ) {
00301         ALIUtils::dumpVS( wordlist, "SYSTEM TREE DESCRIPTION: before ordering, OBJECT: ", std::cout );
00302       }
00303 
00304       //---------- Fill the list of Optical Object with components (theOptODictionary)
00305       //----- First word is 'object': new OptO
00306       if ( wordlist[0] == ALIstring("object") ) {
00307           //----- Check out repeated objects
00308         std::vector< std::vector<ALIstring> >::iterator vvsite; 
00309         for ( vvsite = theOptODictionary.begin(); vvsite != theOptODictionary.end(); vvsite++) {
00310           //-     std::cout << " system" << vvsite << std::endl;
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         //------- Add an item to theOptODictionary
00319         std::vector<ALIstring> vstemp;
00320         copy( wordlist.begin()+1, wordlist.end(),back_inserter( vstemp ) );
00321         Model::OptODictionary().push_back(vstemp);
00322       } else {
00323         //----- First word is not 'object': add to previous OptO
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 //---------------------------------- Reading SYSTEM_TREE_DATA section
00335     } else if( currentSectionNo == sectSystemTreeData ) {
00336       //---------- First line of data:
00337       if ( !data_reading ) {
00338         //        ALIint dictsize = theOptODictionary.size();
00339         //------- Reorder theOptODictionary
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         //------- We start reordering with 'system', therefore if 'system' is not the top most object, the objects not hanging from it would not be considered
00347         //---- Check if all the objects are here
00348         std::vector< std::vector<ALIstring> >::const_iterator vvscite, vvscite2; 
00349         //      ALIint dictsizen = 0;
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         //------- Dump ordered OptOs
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         //---------- Create OpticalObject 'system' (first OpticalObject object): 
00381         //---------- it will create its components and recursively all the System Tree of Optical Objects
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             //-              Model::_OptOtree.insert( std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::value_type(OptOsystem->type(), OptOsystem) );
00390             //              theOptOlist[OptOsystem->name()] = OptOsystem; 
00391         theOptOList.push_back( OptOsystem ); 
00392        
00393       } else {      
00394         //----------- All system is read by the Optical Objects, it should not reach here
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 //----------------------------------- Reading MEASUREMENTS section
00402     } else if( currentSectionNo == sectMeasurements ) {
00403       //---------- Create Measurement with appropiate dimension
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  //t       meastemp = new MeasurementDiffCentre( 1, measType, measName );
00436         meastemp->construct();
00437       } else if ( measType == ALIstring("DIFFANGLE") ) {
00438 //t        meastemp = new MeasurementDiffAngle( 2, measType, measName );
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         //m Measurement::setMeasurementsFileName( wordlist[1] );
00446         //m if ( ALIUtils::debug >= 2) std::cout << " setting measurements_from_file " << measType << " == " << Measurement::measurementsFileName() << std::endl;
00447         if( wordlist.size() == 4) {
00448           Measurement::only1 = 1; 
00449           Measurement::only1Date = wordlist[2]; 
00450           Measurement::only1Time = wordlist[3]; 
00451           //-      std::cout << " setting Measurement::only1" <<  Measurement::only1 << std::endl;
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         //      } else if( wordlist[0] == "scan" || wordlist[0] == "@scan" ) {
00458         //      ScanMgr::getInstance()->addOptOEntry( wordlist );
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 //-      meastemp->setGlobalName( wordlist[0] );
00471 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00472 //@@@ ---------- Reading REPORT OUT  section
00473     } else if( currentSectionNo == sectReportOut ) {
00474       //----- It must be after global options section
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 //@@@ All system read
00491   //---------- make Measurements links to their OptOs 
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 //@@  reorderOptODictionary: REBUILDS THE SYSTEM_TREE_DESCRIPTION SECTION 'objects' 
00507 //@@ (_OptODictionary) IN A HIERARCHICAL (TREE LIKE) ORDER
00508 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00509 void Model::reorderOptODictionary(const ALIstring& ssearch, std::vector< std::vector<ALIstring> >& OptODictionary2 ){
00510 
00511   //  int ALIstring_found = 0;
00512   std::vector< std::vector<ALIstring> >::iterator vvsite; 
00513   std::vector< ALIstring >::iterator vsite; 
00514 
00515 //---------------------------------------- Look for 'ssearch' as the first ALIstring of an OptODictionary item
00516   for( vvsite = OptODictionary().begin(); vvsite != OptODictionary().end(); ++vvsite) {
00517    if( *( (*vvsite).begin() ) == ssearch ) {
00518      //     ALIstring_found = 1;
00519      OptODictionary2.push_back(*vvsite);
00520  
00521      //-    std::cout << "VVSITE";
00522      //-   ostream_iterator<ALIstring> outs(std::cout,"&");
00523      //-   copy( (*vvsite).begin(), (*vvsite).end(), outs);
00524  
00525 //---------------------------------- look for components of this _OptODictionary item
00526      for(  vsite = (*vvsite).begin()+1; vsite != (*vvsite).end(); ++vsite ) {
00527        reorderOptODictionary( *vsite, OptODictionary2 );
00528      }
00529      break;
00530    }
00531   }
00532  
00533   /*  //------- object 'system' should exist
00534   if(!ALIstring_found && ssearch == "system") {
00535     std::cerr << "SYSTEM_TREE_DATA section: no 'object system' found " << std::endl;
00536     exit(9);
00537     } */
00538 
00539 } 
00540 
00541 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00542 //@@ BuildMeasurementLinksToOptOs
00543 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00544 void Model::buildMeasurementsLinksToOptOs(){
00545 
00546 //---------- Loop Measurements
00547   std::vector< Measurement* >::const_iterator vmcite;
00548   for ( vmcite = MeasurementList().begin(); vmcite != MeasurementList().end(); vmcite++) {
00549 //---------- Transform for each Measurement the Measured OptO names to Measured OptO pointers
00550     //     (*vmcite)->buildOptOList();
00551 
00552 //---------- Build list of Entries that affect a Measurement 
00553     // (*vmcite)->buildAffectingEntryList();
00554 
00555   }
00556  
00557 }
00558 
00559 
00560 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00561 //@@ Get the value of a parameter in theParameters std::vector
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 //@@ getOptOByName: Find an OptO name in _OptOlist and return a pointer to it
00575 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00576 OpticalObject* Model::getOptOByName( const ALIstring& opto_name ) 
00577 {
00578   //---------- Look for Optical Object name in OptOList
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     //---------- If opto_name not found, exit
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        //       return (OpticalObject*)0;
00593   } else {
00594     //---------- If opto_name found, return pointer to it
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 //@@ getOptOByType: Find an OptO type in _OptOList (the first one with this type)
00606 //@@ and return a pointer to it
00607 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00608 OpticalObject* Model::getOptOByType( const ALIstring& opto_type ) 
00609 {
00610   //---------- Look for Optical Object type in OptOList
00611   std::vector< OpticalObject* >::const_iterator vocite;
00612   for( vocite = OptOList().begin(); vocite != OptOList().end(); vocite++ ) {
00613    //   std::cout << "OPTOList" << (*msocite).first << std::endl;
00614     if( (*vocite)->type() == opto_type ) break;
00615   }
00616 
00617   if ( vocite == OptOList().end() ) {
00618     //---------- If opto_type not found, exit
00619     std::cerr << "!!EXITING at getOptOByType: Optical Object " << opto_type << " doesn't exist!!" << std::endl;
00620     exit(4);
00621   } else {
00622     //---------- If opto_type found, return pointer to it
00623     return (*vocite);
00624  } 
00625 
00626 }
00627 
00628 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00629 //@@  Find an Entry name in theEntryVector and return a pointer to it
00630 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00631 Entry* Model::getEntryByName( const ALIstring& opto_name, const ALIstring& entry_name )
00632 {
00633   //---------- Look for Entry name type in EntryList
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     //-    std::cout << " optoName " << (*vecite)->OptOCurrent()->name()<< " " << (*vecite)->name() << std::endl;
00639     if( (*vecite)->OptOCurrent()->name() == opto_name &&
00640         (*vecite)->name() == entry_name ) {
00641       return *vecite;
00642     }
00643   }
00644   //---------- Entry not found!
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   //---------- Look for Optical Object name in OptOList
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     //---------- If opto_name found, return pointer to it
00661     return (*vmcite);
00662   }else {
00663     if( exists ) {
00664       //---------- If opto_name not found, exit
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       //       return (OpticalObject*)0;
00672     } else {
00673       return 0;
00674     }
00675 
00676   } 
00677 
00678   
00679 }
00680 
00681 
00682 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00683 //@@  Get an OptO list of components 
00684 //@@  Looks the theOptODictionary item that has 'opto_type' as the first ALIstring,
00685 //@@  copies this item to 'vcomponents', substracting the first ALIstring, that is the opto_type itself,
00686 //@@  Returns 1 if item found, 0 if not 
00687 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00688 ALIbool Model::getComponentOptOTypes( const ALIstring& opto_type, std::vector<ALIstring>& vcomponents )
00689 {
00690   //---------- clean std::vector in which you are going to store opto types
00691   std::vector<ALIstring>::iterator vsite;
00692   for (vsite = vcomponents.begin(); vsite != vcomponents.end(); vsite++) {
00693     vcomponents.pop_back();
00694   }
00695  
00696   //---------- Looks the theOptODictionary item that has 'opto_type' as the first ALIstring,
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       //tt  copies this item to 'vcomponents', substracting the first ALIstring, that is the opto_type itself,
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 //@@ Get from _OptOList the list of OptOs pointers that has as parent 'opto_name' 
00719 //@@ and store it in vcomponents
00720 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00721 ALIbool Model::getComponentOptOs( const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents) 
00722 {
00723   //---------- clean std::vector in which you are going to store opto pointers
00724   std::vector<OpticalObject*>::iterator voite;
00725   for (voite = vcomponents.begin(); voite != vcomponents.end(); voite++) {
00726     vcomponents.pop_back();
00727   }
00728 
00729   //---------- Get OptO corresponding to name 'opto_name'
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       //        std::cout << "looping OptOlist" << (*vocite)->name() << " parent " <<(*vocite)->parent()->name() << std::endl; 
00740       if( (*vocite)->parent()->name() == opto_name ) {
00741         opto_found = 1;
00742         vcomponents.push_back( (*vocite) );    
00743       }
00744     }
00745   }
00746     
00747   /*  std::pair<multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::iterator,
00748        std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::iterator> 
00749   pmmao =  _OptOtree.equal_range(opto_name);
00750 
00751   if( pmmao.first != _OptOtree.end()) {
00752     std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::const_iterator socite;
00753     for (socite = pmmao.first; socite != (pmmao.second); socite++) {
00754          vcomponents.push_back( (*socite).second );
00755     }
00756   }
00757   */
00758   return opto_found;
00759 
00760 }
00761 
00762 
00764 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00765 //@@ createCopyComponentList:
00766 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00767 ALIbool Model::createCopyComponentList( const ALIstring& typ )
00768 {
00769   //---------- Find an OptO with the same type (YOU HAVE TO BE SURE THAT ALL EXISTING OPTOs OF THIS TYPE HAVE SAME COMPONENTS, IF NOT COPYING MAY GIVE YOU UNPREDICTABLE RESULTS)
00770   if(ALIUtils::debug >= 3) std::cout << "createCopyComponentList " << typ << std::endl; 
00771   OpticalObject* start_opto = getOptOByType( typ );
00772   
00773   //---------- clean list of OptOs to copy
00774   theOptOsToCopyList.erase( theOptOsToCopyList.begin(), theOptOsToCopyList.end() );
00775   
00776   //---------- Fill list of OptOs to copy
00777   fillCopyComponentList( start_opto );
00778   //- if(ALIUtils::debug >= 9) std::cout << "createCopyComponentList " << typ << theOptOsToCopyList.size() << std::endl; 
00779   
00780   theOptOsToCopyListIterator = theOptOsToCopyList.begin();
00781   return 1;
00782 }
00783 
00784 
00785 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00786 //@@ fillCopyOptOList: Fill list of objects to copy with the components of 'opto'
00787 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00788 ALIbool Model::fillCopyComponentList( const OpticalObject* opto )
00789 {
00790   if(ALIUtils::debug >= 3) std::cout << "entering fillCopyComponentList(): OptO" << opto->name() << std::endl;
00791   //---------- Get list of components of 'opto'
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   //---------- Loop list of components of 'opto'
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     //---------- Add components of this component
00804     fillCopyComponentList( *vocite );
00805   }
00806   return opto_found;
00807 }
00808 
00809 
00810 
00811 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00812 //@@ nextOptOToCopy: return next object to copy from theOptOsToCopyListIterator
00813 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00814 OpticalObject* Model::nextOptOToCopy()
00815 {
00816   if(ALIUtils::debug >= 5) std::cout << "entering nextOptOToCopy() " << std::endl;
00817   theOptOsToCopyListIterator++;
00818   //  if(ALIUtils::debug >= 5) std::cout <<" nextOptOToCopy " << (*(theOptOsToCopyListIterator-1))->name() << std::endl;
00819   return *(theOptOsToCopyListIterator-1);
00820 }
00821 
00822 
00824 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00825 //@@ If fitting CMS link, it has to be fitted part by part, in several iterations
00826 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00827 void Model::CMSLinkFit( ALIint cmslink)
00828 {
00829   /*
00830   //---------- Get number of fits 
00831   ALIint cmslinkNoFits = 0;
00832   if( cmslink == 1) {
00833     cmslinkNoFits = 3;
00834   } else if( cmslink == 2) {
00835     cmslinkNoFits = 2;
00836   }
00837   if(ALIUtils::debug >= 4) std::cout << " Start CMS link fit with method " << cmslink << " (number of fits = " << cmslinkNoFits << ")" << std::endl;
00838 
00839   //----------- Loop number of cms_link fits 
00840   for(ALIint ilink = ALIint(Model::GlobalOptions()["cms_link"]); ilink <= cmslinkNoFits; ilink++) { 
00841 
00842   //----- Iteration 2 of method 2 resembles iteration 3 of method 1
00843      ALIdouble cmslink_method;
00844      assert(Model::getGlobalOptionValue("cms_link_method", cmslink_method)); 
00845      if( cmslink_method == 2 && ilink == 2) ilink = 3;
00846 
00847 //---- Set variable CMSLinkIteration, Checked in Fit.C and other     //- std::cout << "ilink" << ilink << std::endl;
00848     Model::setGlobalOption("cms_link", ilink); 
00849     Model::CMSLinkIteration = ilink;
00850 
00851     if(ilink > 1)Model::readSystemDescription(); //already read once to fill value Model::GlobalOptions()["cms_link"]
00852 
00853     //---------- Delete the OptO not fitted in this iteration
00854     //    Model::CMSLinkDeleteOptOs(); 
00855     // cannot be here because you may recover a parameter saved in previous iteration that now it is deleted (!!MODIFY THIS)  
00856 
00857     //---------- Recover parameters fitted in previous iteration
00858     Model::CMSLinkRecoverParamFittedSigma( ilink );
00859 
00860     Model::CMSLinkRecoverParamFittedValueDisplacement( ilink );
00861 
00862     //---------- Delete the OptO not fitted in this iteration
00863     Model::CMSLinkDeleteOptOs();
00864   
00865     //---------- Start fit
00866     Fit::startFit();
00867 
00868     //---------- Save parameters fitted in this iteration (to be used in next one)
00869     Model::CMSLinkSaveParamFittedSigma( ilink );
00870 
00871     Model::CMSLinkSaveParamFittedValueDisplacement( ilink );
00872 
00873     //---------- Delete whole system to start anew in next iteration
00874     Model::CMSLinkCleanModel();
00875 
00876   }    
00877   */
00878 }
00879 
00880 
00881 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00882 //@@ CMSLinkCleanModel: clean Model for new iteration while fitting CMS link 
00883 //@@ part by part
00884 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00885 void Model::CMSLinkCleanModel()
00886 {
00887   deleteOptO("s");
00888   //---------- Clean OptOdicitionary (in case this is not first reading)
00889   ALIuint odsize = theOptODictionary.size(); 
00890   for( ALIuint ii = 0; ii < odsize; ii++) {
00891       theOptODictionary.pop_back(); 
00892   }
00893 
00894 }
00895 
00896 
00897 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00898 //@@ CMSLinkDeleteOptOs
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     //---------- First fit: delete everything but laser1 and det_tkU
00913     //    deleteOptO("s/laserboxL/laser2");
00914     //-    std::cout << "delete mabs" << std::endl;
00915     deleteOptO("s/mabsL");
00916     //------- Method 1: detectors at tracker down
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       //      deleteOptO("s/laserboxR/laser2");
00924       deleteOptO("s/mabsR");
00925     }
00926 
00927   } else if( cmslink_iter == 2) {
00928     //---------- Second fit (method 1): delete everything but laser1 and det3
00929     //    deleteOptO("s/laserboxL/laser2");
00930     deleteOptO("s/mabsL");
00931     deleteOptO("s/tracker/CST/wheel_trkL/peri/mirror"); //??
00932     deleteOptO("s/tracker/CST/wheel_trkL/det_trkU");
00933     //------- Method 1: detectors on CST, Method 2: detectors on tracker
00934       //not necessary    deleteOptO("s/tracker/CST/det6");
00935 
00936     if( cmslink_halfplanes <= 1) {  
00937       deleteOptO("s/tracker/CST/wheel_trkR");
00938     } else if( cmslink_halfplanes == 2) { 
00939       //      deleteOptO("s/laserboxR/laser2");
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     //---------- Third fit: delete everything but laser2 and mabs
00947     //    deleteOptO("s/laserboxL/laser1");
00948     deleteOptO("s/tracker");
00949 
00950     if( cmslink_halfplanes == 2) {  
00951       //      deleteOptO("s/laserboxR/laser1");
00952     }
00953   //---------- Do nothing
00954   } else {
00955 
00956   }
00957 
00958 }
00959 
00960 
00961 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00962 //@@ CMSLinkSaveParamFittedSigma
00963 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
00964 void Model::CMSLinkSaveParamFittedSigma( ALIint cms_link )
00965 {
00966   /*
00967   ALIdouble cms_link_halfplanes = (GlobalOptions()["cms_link_halfplanes"]);
00968 
00969   cleanParamFittedSigmaVector(); 
00970 
00971   //---------- First fit: Save laserbox angles fitted at tracker 
00972   if( cms_link == 1) {
00973     //?    if (GlobalOptions()["cms_link_method"] < 10){
00974     saveParamFittedSigma("s/laserboxL","Angles X");   
00975     saveParamFittedSigma("s/laserboxL","Angles Y");
00976 
00977     saveParamFittedCorrelation("s/laserboxL","Angles X",
00978      "s/tracker/CST","Centre Y");
00979     saveParamFittedCorrelation("s/laserboxL","Angles Y",
00980      "s/tracker/CST","Centre X");
00981     if( cms_link_halfplanes == 2) {  
00982       saveParamFittedSigma("s/laserboxR","Angles X");   
00983       saveParamFittedSigma("s/laserboxR","Angles Y");
00984 
00985       saveParamFittedCorrelation("s/laserboxR","Angles X",
00986        "s/tracker/CST","Centre Y");
00987       saveParamFittedCorrelation("s/laserboxR","Angles Y",
00988        "s/tracker/CST","Centre X");
00989     }
00990 
00991   } else if( cms_link == 2) {
00992   //---------- Second fit: Save laserbox angles and position
00993     saveParamFittedSigma("s/laserboxL","Centre X");
00994     saveParamFittedSigma("s/laserboxL","Centre Y");
00995     // Make quality unk to cal
00996     saveParamFittedSigma("s/laserboxL","Centre Z");
00997     saveParamFittedSigma("s/laserboxL","Angles X");
00998     saveParamFittedSigma("s/laserboxL","Angles Y");
00999    
01000     saveParamFittedCorrelation("s/laserboxL","Centre X",
01001         "s/laserboxL","Angles Y");
01002     saveParamFittedCorrelation("s/laserboxL","Centre Y",
01003         "s/laserboxL","Angles X");
01004 
01005    if( cms_link_halfplanes == 2) {  
01006     saveParamFittedSigma("s/laserboxR","Centre X");
01007     saveParamFittedSigma("s/laserboxR","Centre Y");
01008     // Make quality unk to cal
01009     saveParamFittedSigma("s/laserboxR","Centre Z");
01010     saveParamFittedSigma("s/laserboxR","Angles X");
01011     saveParamFittedSigma("s/laserboxR","Angles Y");
01012    
01013     saveParamFittedCorrelation("s/laserboxR","Centre X",
01014         "s/laserboxR","Angles Y");
01015     saveParamFittedCorrelation("s/laserboxR","Centre Y",
01016         "s/laserboxR","Angles X");
01017    }  
01018   } else {
01019  //---------- Do nothing
01020 
01021   }
01022   */
01023 }
01024 
01025 
01026 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01027 //@@ CMSLinkSaveParamFittedValueDisplacement: 
01028 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01029 void Model::CMSLinkSaveParamFittedValueDisplacement( ALIint cms_link )
01030 {
01031   /*
01032   cleanParamFittedValueDisplacementMap(); 
01033 
01034   //---------- 
01035   if( cms_link == 1 || cms_link == 2 ) {
01036     std::vector<Entry*>::const_iterator vecite;
01037     for( vecite = EntryList().begin(); vecite != EntryList().end(); vecite++) {
01038       if( (*vecite)->valueDisplacementByFitting() != 0 ) {
01039         ALIstring names = (*vecite)->OptOCurrent()->name() + "/" + (*vecite)->name();
01040         std::cout << "saeParamFittedValueDisplacementMap" << names << (*vecite)->valueDisplacementByFitting() << std::endl;
01041         theParamFittedValueDisplacementMap[ names ] = (*vecite)->valueDisplacementByFitting();
01042       }
01043     }
01044 
01045   //---------- Do nothing
01046   } else {
01047 
01048   }
01049   */
01050 }
01051 
01052 
01053 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01054 //@@ CMSLinkRecoverParamFittedSigma:
01055 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01056 void Model::CMSLinkRecoverParamFittedSigma( ALIint cms_link )
01057 {
01058   /*
01059   ALIdouble cms_link_halfplanes = (GlobalOptions()["cms_link_halfplanes"]);
01060 
01061   if( cms_link == 2) {
01062   //---------- Second fit: recover laserbox angles
01063     recoverParamFittedSigma("s/laserboxL","Angles X",0);
01064     recoverParamFittedSigma("s/laserboxL","Angles Y",1);
01065 
01066     if( cms_link_halfplanes == 2) {  
01067       recoverParamFittedSigma("s/laserboxR","Angles X",0);
01068       recoverParamFittedSigma("s/laserboxR","Angles Y",1);
01069     }
01070 
01071   } else if( cms_link == 3) {
01072   //---------- Third fit: recover laserbox angles and position and rotate angles to mabs
01073     recoverParamFittedSigma("s/laserboxL","Centre X",0);
01074     recoverParamFittedSigma("s/laserboxL","Centre Y",1);
01075     recoverParamFittedSigma("s/laserboxL","Centre Z",2);
01076     recoverParamFittedSigma("s/laserboxL","Angles X",3);
01077 
01078     //----- Angle around Y is converted to angle around Z when turning 90 deg
01079     Entry* slaZ = getEntryByName("s/laserboxL","Angles Z");
01080     //--- prec_level_laser
01081     Entry* smaZ = getEntryByName("s/mabsL","Angles Z");
01082     slaZ->setQuality(0);
01083     slaZ->setValue( smaZ->value() );
01084     //    smaZ->setQuality(0); //!!???!!?
01085 
01086     Entry* slaY = getEntryByName("s/laserboxL","Angles Y");
01087     slaY->setQuality(0); 
01088 
01089     if( cms_link_halfplanes == 2) {   
01090       recoverParamFittedSigma("s/laserboxR","Centre X",0);
01091       recoverParamFittedSigma("s/laserboxR","Centre Y",1);
01092       recoverParamFittedSigma("s/laserboxR","Centre Z",2);
01093       recoverParamFittedSigma("s/laserboxR","Angles X",3);
01094 
01095       //----- Angle around Y is converted to angle around Z when turning 90 deg
01096       Entry* slaZ = getEntryByName("s/laserboxR","Angles Z");
01097       //--- prec_level_laser
01098       Entry* smaZ = getEntryByName("s/mabsR","Angles Z");
01099       slaZ->setQuality(0);
01100       slaZ->setValue( smaZ->value() );
01101       //    smaZ->setQuality(0); //!!???!!?
01102 
01103       Entry* slaY = getEntryByName("s/laserboxR","Angles Y");
01104       slaY->setQuality(0); 
01105     }
01106   } else {
01107   //---------- Do nothing
01108 
01109   }
01110   */
01111 }
01112 
01113 
01114 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01115 //@@ CMSLinkRecoverParamFittedValueDisplacement:
01116 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01117 void Model::CMSLinkRecoverParamFittedValueDisplacement( ALIint cms_link )
01118 {
01119   /*
01120   //---------- Second fit: recover laserbox angles
01121   if( cms_link == 2 || cms_link == 3 ) {
01122 
01123     std::map<ALIstring, ALIdouble, std::less<ALIstring> >::const_iterator vsdmite;
01124     if ( ALIUtils::debug >= 99) std::cout << "theParamFittedValueDisplacementMap.size " << theParamFittedValueDisplacementMap.size() << std::endl;
01125     for( vsdmite =  theParamFittedValueDisplacementMap.begin(); vsdmite !=  theParamFittedValueDisplacementMap.end(); vsdmite++) {
01126       std::cout << "reoverValueDisp" <<  (*vsdmite).first << "  " << (*vsdmite).second << std::endl;
01127       Entry* this_entry = getEntryByName( (*vsdmite).first);
01128       this_entry->displaceOriginal( (*vsdmite).second ); 
01129       this_entry->OptOCurrent()->resetGlobalCoordinates();
01130       this_entry->setValueDisplacementByFitting(  (*vsdmite).second ); 
01131 
01132     }
01133 
01134   //---------- Do nothing
01135   } else {
01136 
01137   }
01138   */
01139 }
01140 
01141 
01142 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01143 //@@  Delete an OptO
01144 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01145 void Model::deleteOptO( const ALIstring& opto_name )
01146 {
01147   OpticalObject* opto = getOptOByName( opto_name );
01148   deleteOptO( opto );
01149 }
01150 
01151 
01152 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01153 //@@  deleteOptO: delete OptO, its Entries, and the Measurements in which it participates. Then deleteOptO of components
01154 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01155 void Model::deleteOptO( OpticalObject* opto )
01156 {
01157   if(ALIUtils::debug >= 5 ) std::cout << "DELETING OptO" << opto->name() << std::endl;
01158   
01159   //---------- Delete Coordinate Entries of this OptO
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     //    ALIuint pos = FindItemInVector( (*veite), opto->CoordinateEntryList() );
01165     veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
01166     //-  if ( ALIUtils::debug >= 9) std::cout << (*veite2) << "DELETE ENTRY " << (*vecite) <<(*veite2)->OptOCurrent()->name() << (*veite2)->name() << std::endl;
01167     delete ( (*veite2) );
01168     theEntryVector.erase( veite2 );
01169   }
01170 
01171   for( vecite = opto->ExtraEntryList().begin(); vecite != opto->ExtraEntryList().end(); vecite++) {
01172     //    ALIuint pos = FindItemInVector( (*veite), opto->CoordinateEntryList() );
01173     veite2 = find( theEntryVector.begin(), theEntryVector.end(), (*vecite) );
01174     //-    if(ALIUtils::debug >= 9) std::cout << (*veite2) << "DELETE ENTRY " << (*veite2)->OptOCurrent()->name() << (*veite2)->name() << std::endl;
01175     delete ( (*veite2) );
01176     theEntryVector.erase( veite2 );
01177   }
01178 
01179  
01180   for( vecite = theEntryVector.begin(); vecite != theEntryVector.end(); vecite++ ) {
01181     //     std::cout << (*vecite) << "ENTReY " << (*vecite)->OptOCurrent()->name() << (*vecite)->name() << std::endl;
01182   }
01183 
01184   //---------- Delete all Measurement in which opto takes part
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     //----- If any of the OptO Measured is opto, delete this Measurement
01191     for( vocite = (*vmite)->OptOList().begin(); vocite != (*vmite)->OptOList().end(); vocite++) {
01192       if( (*vocite) == opto ) {
01193         //-      std::cout << "MEASTBD" << (*vmite) << std::endl;
01194         MeasToBeDeleted.push_back( *vmite );
01195         //?       delete (*vmite);
01196         break;
01197       }
01198     } 
01199   }
01200 
01201  //---------- Delete Measurements from list
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     //    std::cout << (*vmite2) << "DELETE MSEASU " << (*vmcite) << (*vmite2)->name()[0] << std::endl;
01208     delete ( (*vmite2) );
01209     theMeasurementVector.erase( vmite2 );
01210   }
01211 
01212 
01213   //---------- Delete components
01214   //  std::vector<OpticalObject*>::iterator voite;
01215   std::vector<OpticalObject*> vopto;
01216   //  ALIbool opto_found = getComponentOptOs( opto->name(), vopto );
01217   for( vocite = vopto.begin(); vocite != vopto.end(); vocite++ ) {
01218     deleteOptO( *vocite );
01219   }
01220      
01221   //---------- Delete this OptO
01222   //---------- Delete OptO (only from list, to delete it really first delete components)
01223   /*  map< ALIstring, OpticalObject*, std::less<ALIstring> >::iterator msoite =  
01224 find( theOptOList.begin(), theOptOList.end(), 
01225 map< ALIstring, OpticalObject*, std::less<ALIstring> >::value_type( opto->name(), opto) );*/
01226   std::vector< OpticalObject* >::iterator dvoite =  
01227    find( theOptOList.begin(), theOptOList.end(), 
01228          std::vector< OpticalObject* >::value_type( opto) );
01229   //-  std::cout << (*dvoite) << "DELETE OPTO " << opto <<"WW" << (*dvoite)->name() << std::endl;
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 //---------- Get sigma of param Optical
01243   Entry* entry = getEntryByName(opto_name, entry_name);
01244   ALIuint fit_pos = entry->fitPos();
01245   if( fit_pos < 0 || fit_pos >= Fit::propagationMatrix().NoLines()) {
01246     std::cerr << "!!EXITING at saveParamFittedSigma: fit position incorrect " <<
01247       fit_pos << "propagationMatrix size =" << Fit::propagationMatrix().NoLines() << opto_name << std::endl;
01248     exit(3);
01249   }
01250   std::cout << entry_name << "saveParamFittedSigma" << fit_pos << sqrt(Fit::propagationMatrix()( fit_pos, fit_pos)) << std::endl;
01251   theParamFittedSigmaVector.push_back( sqrt(Fit::propagationMatrix()( fit_pos, fit_pos)) );
01252   //-    Fit::propagationMatrix().Dump(" the 2PropagationMatrix");
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 //---------- Get sigma of param Optical
01264   Entry* entry1 = getEntryByName(opto_name1, entry_name1);
01265   Entry* entry2 = getEntryByName(opto_name2, entry_name2);
01266   ALIuint fit_pos1 = entry1->fitPos();
01267   ALIuint fit_pos2 = entry2->fitPos();
01268 
01269   //---------- Get correlation if entry has been fitted
01270   ALIuint pmsize = Fit::propagationMatrix().NoLines();
01271   if( fit_pos1 >= 0 && fit_pos1 < pmsize && fit_pos2 >= 0 && fit_pos2 < pmsize ) {
01272     ALIdouble error1 = sqrt( Fit::propagationMatrix()( fit_pos1, fit_pos1) );
01273     ALIdouble error2 = sqrt( Fit::propagationMatrix()( fit_pos2, fit_pos2) );
01274     ALIdouble correl = Fit::propagationMatrix()( fit_pos1, fit_pos2) / error1 / error2;
01275     theParamFittedSigmaVector.push_back( correl );
01276     if(ALIUtils::debug>=9) {
01277       std::cout  << "saveParamFittedCorre" << opto_name1 << entry_name1 << fit_pos1 << 
01278         opto_name2 << entry_name2 << fit_pos2 << "MM " << correl << std::endl;
01279     }
01280   } else {
01281     if(ALIUtils::debug>=9) {
01282       std::cout  << "NOsaveParamFittedCorre" << opto_name1 << entry_name1 << fit_pos1 << 
01283         opto_name2 << entry_name2 << fit_pos2 << "MM " << std::endl;
01284     theParamFittedSigmaVector.push_back( 0. );
01285     }
01286 
01287   }
01288   //-    Fit::propagationMatrix().Dump(" the 2PropagationMatrix");
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   if( position >= theParamFittedSigmaVector.size() ) {
01300     std::cerr << "!!EXITING at recoverParamFittedSigma: position" << position << 
01301  " bigger than dimension of theParamFittedSigmaVector " << theParamFittedSigmaVector.size() << std::endl;
01302     exit(3);
01303   }
01304   ALIdouble sigma = getParamFittedSigmaVectorItem( position );
01305 
01306   Entry* entry = getEntryByName(opto_name, entry_name);
01307   entry->setSigma( sigma );
01308   entry->setQuality( 1 );
01309   std::cout << "recover " << opto_name << entry_name << entry->sigma() <<std::endl;
01310   */
01311 }
01312 
01313 
01314 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01315 //@@  getParamFittedSigmaVectorItem
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 //@@  getParamFittedSigmaVectorItem
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   //---------- read date
01342   //  ALIint retfil = filein.getWordsInLine(wordlist);
01343   // std::cout << "@@@@@@@@@@@@@@@ RETFIL " << retfil << std::endl;
01344   //if( retfil == 0 ) {
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   //  struct tm tim;
01352   //t Model::setMeasurementsTime( tim );
01353 
01354   //if you are looking for only one measurement with a given date and time, loop all measurements until you find it
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   //set date and time of current measurement
01367   if( wordlist[0] == "DATE:" ) {
01368     Measurement::setCurrentDate( wordlist ); 
01369   } 
01370 
01371   //---------- loop measurements
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         //-------- Measurement found, fill data
01389         /*      ALIint last_slash =  (*vmcite)->name().rfind('/');
01390         ALIstring oname = (*vmcite)->name();
01391         if( last_slash != -1 ) {
01392           oname = oname.substr(last_slash+1, (*vmcite)->name().size()-1);
01393           } 
01394         */
01395         ALIint fcolon = (*vmcite)->name().find(':');
01396         ALIstring oname = (*vmcite)->name();
01397         oname = oname.substr(fcolon+1,oname.length());
01398         //-    std::cout << " measurement name " << (*vmcite)->name() << " short " << oname << std::endl;
01399         if( oname == wordlist[1] ) {
01400           //-   std::cout << " measurement name found " << oname << std::endl;
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           //---------- Read the data 
01411           for ( uint ii=0; ii < meastemp->dim(); ii++){
01412             filein.getWordsInLine( wordlist );
01413             ALIdouble sigma = 0.;
01414             if( !sigmaFF ) { 
01415               // keep the sigma, do not read it from file 
01416               const ALIdouble* sigmav = meastemp->sigma();
01417               sigma = sigmav[ii];
01418             }
01419             //---- Check measurement value type is OK
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   //-  std::cout << " returning readmeasff" << std::endl;
01448 
01449   return 1;
01450 }
01451 
01452 
01453 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01454 
01455 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
01456 void Model::copyMeasurements( const std::vector<ALIstring>& wl )
01457 {
01458  
01459   //----- Check format, e.g.  @copy_measurements _1/_2/*_1 
01460 
01461 
01462   //----- get list of Measurement's that satisfy the query in their name
01463   //t  std::string querystr = wl[1].substr( wl[1].find("/")+1, wl[1].length() );
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     //improve this
01475     if( meas->name().find( querystr ) != -1 ) {
01476       measToCopy.push_back( meas );
01477     }
01478   }
01479 
01480   //---- Build new measurements
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     //---- create new name 
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       //          } else if ( meas->type() == ALIstring("DISTANCEMETER3DIM") ) {
01502       //            meastemp = new MeasurementDistancemeter3dim( 1, measType, measName );
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  //     meastemp = new MeasurementDiffCentre( 1, measType, measName );
01510     } else if ( meas->type() == ALIstring("DIFFANGLE") ) {
01511 //      meastemp = new MeasurementDiffAngle( 1, measType, measName );
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     //later        meastemp->copyConversionFactor( wordlist );
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       //----- Find the EntryData corresponding to this entry
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   //-              Model::_OptOtree.insert( std::multimap< ALIstring, OpticalObject*, std::less<ALIstring> >::value_type(OptOsystem->type(), OptOsystem) );
01589   //              theOptOlist[OptOsystem->name()] = OptOsystem; 
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     //    std::cout << " Model::FindOptAlignInfoByType " <<  (*ite).type_ << " =? " << type << std::endl;
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     //---------- Create Measurement with appropiate dimension
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       //t       meastemp = new MeasurementDiffCentre( 1, measType, measName );
01649     } else if ( measType == ALIstring("DIFFANGLE") ) {
01650       //t        meastemp = new MeasurementDiffAngle( 2, measType, measName );
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 }

Generated on Tue Jun 9 17:23:39 2009 for CMSSW by  doxygen 1.5.4