CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/CocoaModel/src/ErrorCorrelationMgr.cc

Go to the documentation of this file.
00001 //   COCOA class implementation file
00002 //Id:  ErrorCorrelationMgr.cc
00003 //CAT: Model
00004 //
00005 
00006 #include "Alignment/CocoaModel/interface/ErrorCorrelationMgr.h"
00007 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
00008 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
00009 #include <cstdlib>
00010 
00011 //----------------------------------------------------------------------------
00012 ErrorCorrelationMgr* ErrorCorrelationMgr::theInstance = 0;
00013 
00014 //----------------------------------------------------------------------------
00015 ErrorCorrelationMgr* ErrorCorrelationMgr::getInstance()
00016 {
00017   if( !theInstance ) {
00018     theInstance = new ErrorCorrelationMgr;
00019   }
00020 
00021   return theInstance;
00022 
00023 }
00024 
00025 
00026 //----------------------------------------------------------------------------
00027 void ErrorCorrelationMgr::readFromReportFile( const ALIstring& filename )
00028 {
00029   if( ALIUtils::debug >= 4 ) std::cout << " ErrorCorrelationMgr::readFromReportFile " << std::endl;
00030   //------ Open the file
00031   ALIFileIn fin = ALIFileIn::getInstance( filename );
00032 
00033   //------ Read the file
00034   std::vector<ALIstring> wl;
00035   typedef std::map< ALIint, std::pair<ALIstring,ALIstring>, std::less<ALIint> > miss;
00036   miss theEntries;
00037   miss::iterator missite;
00038 
00039   for(;;) {
00040     if( fin.getWordsInLine( wl ) == 0 ) break;
00041     // build the list of entries 
00042     if( wl[0] == "CAL:" || wl[0] == "UNK:" ) {
00043       if( ALIUtils::debug >= 4 ) ALIUtils::dumpVS( wl, " ErrorCorrelationMgr: reading entry ");
00044       theEntries[ALIUtils::getInt( wl[1] )] = std::pair<ALIstring,ALIstring>( wl[2], wl[3] );
00045     //    } else if( wl[0][0] == '(' ) {
00046     } else if( wl[0].substr(0,5) == "CORR:" ) {
00047       // find the two entries 
00048       int p1 = wl[1].find('(');
00049       int p2 = wl[1].find(')');
00050       //      std::cout << "( found " << p1 << " " << p2 << " = " << wl[1].substr(p1+1,p2-p1-1) << std::endl;
00051       if( p2 == -1 ) {
00052         std::cerr << "!!!ERROR:  ErrorCorrelationMgr::readFromReportFile. Word found that starts with '(' but has no ')'" << wl[1] << std::endl;
00053         std::exception(); 
00054       }
00055       ALIint nent = ALIUtils::getInt( wl[1].substr(p1+1,p2-p1-1));
00056       missite = theEntries.find( nent );
00057       std::pair<ALIstring,ALIstring> entry1 = (*missite).second;
00058       
00059       p1 = wl[2].find('(');
00060       p2 = wl[2].find(')');
00061       //      std::cout << "( found " << p1 << " " << p2 << " = " << wl[2].substr(p1+1,p2-p1-1) << std::endl;
00062       if( p2 == -1 ){
00063         std::cerr << "!!!ERROR:  ErrorCorrelationMgr::readFromReportFile. Word found that starts with '(' but has no ')'" << wl[2] << std::endl;
00064         std::exception(); 
00065       }
00066       nent = ALIUtils::getInt( wl[2].substr(p1+1,p2-p1-1));
00067       missite = theEntries.find( nent );
00068       std::pair<ALIstring,ALIstring> entry2 = (*missite).second;
00069 
00070       // build an ErrorCorrelation or update it if it exists
00071       std::vector<ErrorCorrelation*>::iterator itecorr = findErrorCorrelation( entry1, entry2 );
00072       if( itecorr == theCorrs.end() ){
00073         ErrorCorrelation* corr = new ErrorCorrelation( entry1, entry2, ALIUtils::getFloat( wl[3] ) );
00074         if( ALIUtils::debug >= 4 ) {
00075           std::cout << " ErrorCorrelationMgr: correlation created " << entry1.first << " " << entry1.second << "  " << entry2.first << " " << entry2.second << "  " << wl[3] << std::endl;
00076         }
00077         theCorrs.push_back( corr );
00078       } else {
00079         (*itecorr)->update( ALIUtils::getFloat( wl[3] ) );
00080         if( ALIUtils::debug >=  4 ) {
00081           std::cout << " ErrorCorrelationMgr: correlation updated " << entry1.first << " " << entry1.second << "  " << entry2.first << " " << entry2.second << "  " << wl[3] << std::endl;
00082         }
00083       }
00084     }
00085   }
00086 
00087 }
00088 
00089 
00090 //----------------------------------------------------------------------------
00091 ErrorCorrelation* ErrorCorrelationMgr::getCorrelation( ALIint ii )
00092 {
00093   if( ii < 0 || ii >= ALIint(theCorrs.size()) ){
00094     std::cerr << "!!!EXITING: ErrorCorrelationMgr::getCorrelation. incorrect nubmer = " << ii << " size = " << theCorrs.size() << std::endl;
00095     exit(1);
00096   } else {
00097     return theCorrs[ii];
00098   }
00099 }
00100 
00101 //----------------------------------------------------------------------------
00102 std::vector<ErrorCorrelation*>::iterator ErrorCorrelationMgr::findErrorCorrelation( pss& entry1, pss& entry2 )
00103 {
00104   std::vector<ErrorCorrelation*>::iterator itecorr;
00105   for( itecorr = theCorrs.begin(); itecorr != theCorrs.end(); itecorr++ ) {
00106     if( (*itecorr)->getEntry1() == entry1 &&  (*itecorr)->getEntry2() == entry2 ) {
00107       return itecorr;
00108     }
00109   }
00110 
00111   return itecorr;
00112 
00113 }