CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Alignment/CocoaModel/interface/Model.h

Go to the documentation of this file.
00001 //   COCOA class header file
00002 //Id:  Model.h
00003 //CAT: Model
00004 //
00005 //   Utility class that steers the reading of the system description file
00006 //              and contains the static data 
00007 // 
00008 //   History: v1.0 
00009 //   Pedro Arce
00010 
00011 #ifndef MODEL_H
00012 #define MODEL_H
00013 
00014 #include <vector>
00015 #include <map>
00016 //#include <multimap.h>
00017 
00018 
00019 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h" 
00020 class Entry;
00021 //#include "Alignment/CocoaModel/interface/Entry.h"  //temporal
00022 class OpticalObject;
00023 //#include "Alignment/CocoaModel/interface/OpticalObject.h"
00024 class Measurement;
00025 class ALIFileIn;
00026 class FittedEntriesReader;
00027 
00028 class OpticalAlignments;
00029 class OpticalAlignMeasurements;
00030 
00031 #include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h"
00032 
00033 
00034 enum sectionType{ sectGlobalOptions, sectParameters, sectSystemTreeDescription, sectSystemTreeData, sectMeasurements, sectReportOut };
00035 
00036 enum cocoaStatus{ COCOA_Init, COCOA_ReadingModel, COCOA_InitFit, COCOA_FirstIterationInEvent, COCOA_NextIterationInEvent, COCOA_FitOK, COCOA_FitImproving, COCOA_FitCannotImprove, COCOA_FitChi2Worsened, COCOA_FitMatrixNonInversable };
00037 
00038 class Model 
00039 {
00040 public:
00041   //---------- Constructor / destructor 
00042   Model();
00043   ~Model(){};
00044 
00046   static Model& getInstance();  
00047 
00048   static cocoaStatus getCocoaStatus(){ return theCocoaStatus;}
00049   static void setCocoaStatus(const cocoaStatus cs ){ theCocoaStatus = cs; }
00050   static std::string printCocoaStatus(const cocoaStatus cs);
00051 
00053   static void readSystemDescription();
00054 
00055   //----------- Build OpticalObjects's from info in XML file
00056   void BuildSystemDescriptionFromOA( OpticalAlignments& optAlig );
00057   OpticalAlignInfo FindOptAlignInfoByType( const ALIstring& type );
00058   //----------- Build Measurements's from info in XML file
00059   void BuildMeasurementsFromOA( OpticalAlignMeasurements& measList );
00060 
00062 
00063   //  static std::map< ALIstring, ALIdouble, std::less<ALIstring> >& Parameters() {
00064   //     return theParameters;
00065   //  }
00066 
00067   static std::vector< std::vector<ALIstring> >& OptODictionary() {
00068       return theOptODictionary;
00069   }
00070 
00071   static std::vector< OpticalObject* >& OptOList(){
00072       return theOptOList;
00073   }
00074 
00075   static std::vector< Entry* >& EntryList() {
00076     return theEntryVector;
00077   }
00078 
00079   static std::vector< Measurement* >& MeasurementList() {
00080      return theMeasurementVector;
00081   }
00082 
00083   static Measurement* getMeasurementByName( const ALIstring& name, ALIbool exists = 1);
00084 
00086   static ALIstring& SDFName(){
00087     return theSDFName;
00088   }
00089 
00091   static ALIstring& MeasFName(){
00092     return theMeasFName;
00093   }
00094 
00096   static ALIstring& ReportFName(){
00097     return theReportFName;
00098   }
00099 
00101   static ALIstring& MatricesFName(){
00102     return theMatricesFName;
00103   }
00104 
00106 
00107 
00109   static int getParameterValue( const ALIstring& sstr, ALIdouble& val );
00110 
00112   static OpticalObject* getOptOByName( const ALIstring& opto_name );
00113 
00115   static OpticalObject* getOptOByType( const ALIstring& type );
00116 
00118   static Entry* getEntryByName( const ALIstring& opto_name, const ALIstring& entry_name );
00119 
00122   static Entry* getEntryByName( const ALIstring& opto_entry_name) {
00123     ALIint slash_pos = opto_entry_name.rfind('/');
00124     ALIint length = opto_entry_name.length();
00125     ALIstring opto_name = opto_entry_name.substr(0, slash_pos);
00126     ALIstring entry_name = opto_entry_name.substr(slash_pos+1, length);
00127     Entry* entry = getEntryByName( opto_name, entry_name);
00128     return entry;
00129   }
00130 
00132   static ALIbool getComponentOptOTypes( const ALIstring& opto_type, std::vector<ALIstring>& vcomponents );
00133 
00135   static ALIbool getComponentOptOs( const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents);
00136 
00137   static struct tm& MeasurementsTime() {
00138     return theMeasurementsTime;
00139   }
00140 
00141   static std::vector<OpticalAlignInfo> getOpticalAlignments() { return theOpticalAlignments; }
00142 
00143 
00145   static void addEntryToList( Entry* entry ) {
00146      theEntryVector.push_back( entry );
00147      //-     std::cout << entry << entry->OptOCurrent()->name() << "ADDENTRY " << entry->name() << " " << EntryList().size() << std::endl;
00148   }
00149 
00150   static void addMeasurementToList( Measurement* measadd ) {
00151       theMeasurementVector.push_back( measadd);  
00152       //   std::cout << "ADD MEASUREMENT" << theMeasurementVector.size() << std::endl ;  
00153   }
00154 
00155   //----- Set the name of the System Description File
00156   static void setSDFName( const ALIstring& name ) {
00157     theSDFName = name;
00158   }
00159   //----- Set the name of the report File
00160   static void setReportFName( const ALIstring& name ) {
00161     theReportFName = name;
00162   }
00163   //----- Set the name of the matrices File
00164   static void setMatricesFName( const ALIstring& name ) {
00165     theMatricesFName = name;
00166   }
00167 
00168   static void setMeasurementsTime( struct tm& tim ) {
00169     theMeasurementsTime = tim;
00170   }
00171 
00172 
00173   static ALIbool readMeasurementsFromFile( ALIstring only1Date = ALIstring(""), ALIstring only1Time = ALIstring("") );
00174  
00175 
00177 private:
00179   static void reorderOptODictionary( const ALIstring& ssearch, std::vector< std::vector<ALIstring> >& OptODictionary2); 
00180 
00182   //  static void readMeasurements( ALIFileIn& filein );
00183 
00185   static void buildMeasurementsLinksToOptOs();
00186 
00187   static void SetValueDisplacementsFromReportOut();
00188 
00191   static Model* theInstance;
00192 
00194   //-  static std::map< ALIstring, ALIdouble, std::less<ALIstring> > theParameters;
00195  
00197   static std::vector< std::vector<ALIstring> > theOptODictionary;
00198 
00200     //-  static multimap< ALIstring, OpticalObject*, std::less<ALIstring> > theOptOtree;
00202     //  static map< ALIstring, OpticalObject*, std::less<ALIstring> > theOptOList;
00203   static std::vector< OpticalObject* > theOptOList;
00204 
00206   static std::vector< Entry* > theEntryVector;
00207 
00209   static std::vector< Measurement* > theMeasurementVector;
00210 
00212   static ALIstring theSDFName;
00214   static ALIstring theMeasFName;
00216   static ALIstring theReportFName;
00218   static ALIstring theMatricesFName;
00219 
00221  public:
00222  //----- Steers the storing of the components of OptO named 'optoname'
00223   static ALIbool createCopyComponentList( const ALIstring& optoname );
00224  //----- Get next object to copy from the stored list of components and copy it
00225   static OpticalObject* nextOptOToCopy();
00226  private:
00227  //----- Stores the components of opto 
00228   static ALIbool fillCopyComponentList( const OpticalObject* opto );
00229   //----- List of components of an OptO to copy
00230   static std::vector<OpticalObject*> theOptOsToCopyList;
00231   //----- Iterator of the list of components of an OptO to copy
00232   static std::vector<OpticalObject*>::const_iterator theOptOsToCopyListIterator;
00233 
00234 
00235 
00237  public:
00238    static ALIint Ncmslinkrange;
00239    static std::vector<ALIdouble> CMSLinkRangeDetValue;
00240 
00241 
00243 public:
00244   void CMSLinkFit( ALIint cmslink);
00245 private:
00246   void CMSLinkCleanModel();
00247   static void CMSLinkDeleteOptOs();
00248   static void CMSLinkSaveParamFittedSigma( ALIint cmslink );
00249   static void CMSLinkSaveParamFittedValueDisplacement( ALIint cmslink );
00250   static void CMSLinkRecoverParamFittedSigma(ALIint cmslink);
00251   static void CMSLinkRecoverParamFittedValueDisplacement(ALIint cmslink);
00252 
00253   static ALIint CMSLinkIteration;
00254  
00255   //----- METHODS FOR FITTING IN SEVERAL STEPS
00256   static void deleteOptO( const ALIstring& opto_name );
00257   static void deleteOptO( OpticalObject* opto );
00258 
00259   static void saveParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name);
00260 
00261   static void saveParamFittedCorrelation( const ALIstring& opto_name1, const ALIstring& entry_name1, const ALIstring& opto_name2, const ALIstring& entry_name2);
00262 
00263   static void recoverParamFittedSigma( const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position );
00264 
00265  public:
00266   static ALIdouble getParamFittedSigmaVectorItem( const ALIuint position );
00267   static FittedEntriesReader* getFittedEntriesReader(){
00268     return theFittedEntriesReader; }
00269 
00270  private:
00271   static void cleanParamFittedSigmaVector() {
00272     ALIuint pfsv_size = theParamFittedSigmaVector.size();    
00273     for( ALIuint ii = 0; ii < pfsv_size; ii++) {
00274       theParamFittedSigmaVector.pop_back();
00275     }
00276   }
00277 
00278   static void cleanParamFittedValueDisplacementMap() {
00279     theParamFittedValueDisplacementMap.erase( theParamFittedValueDisplacementMap.begin(), theParamFittedValueDisplacementMap.end() );   
00280   }
00281 
00282   static void copyMeasurements( const std::vector<ALIstring>& wl );
00283  
00284  private:
00285 
00286   static cocoaStatus theCocoaStatus;
00287 
00288   static std::vector<ALIdouble> theParamFittedSigmaVector;
00289 
00290   static std::map<ALIstring, ALIdouble, std::less<ALIstring> > theParamFittedValueDisplacementMap;
00291 
00292   static struct tm theMeasurementsTime;
00293 
00294   static FittedEntriesReader* theFittedEntriesReader;
00295 
00296   static std::vector<OpticalAlignInfo> theOpticalAlignments;
00297 };
00298 
00299 #endif