Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:28

0001 //   COCOA class implementation file

0002 //Id:  ErrorCorrelationMgr.cc

0003 //CAT: Model

0004 //

0005 
0006 #include "Alignment/CocoaModel/interface/ErrorCorrelationMgr.h"
0007 #include "Alignment/CocoaUtilities/interface/ALIFileIn.h"
0008 #include "Alignment/CocoaUtilities/interface/ALIUtils.h"
0009 #include <cstdlib>
0010 
0011 //----------------------------------------------------------------------------

0012 ErrorCorrelationMgr* ErrorCorrelationMgr::theInstance = nullptr;
0013 
0014 //----------------------------------------------------------------------------

0015 ErrorCorrelationMgr* ErrorCorrelationMgr::getInstance() {
0016   if (!theInstance) {
0017     theInstance = new ErrorCorrelationMgr;
0018   }
0019 
0020   return theInstance;
0021 }
0022 
0023 //----------------------------------------------------------------------------

0024 void ErrorCorrelationMgr::readFromReportFile(const ALIstring& filename) {
0025   if (ALIUtils::debug >= 4)
0026     std::cout << " ErrorCorrelationMgr::readFromReportFile " << std::endl;
0027   //------ Open the file

0028   ALIFileIn fin = ALIFileIn::getInstance(filename);
0029 
0030   //------ Read the file

0031   std::vector<ALIstring> wl;
0032   typedef std::map<ALIint, std::pair<ALIstring, ALIstring>, std::less<ALIint> > miss;
0033   miss theEntries;
0034   miss::iterator missite;
0035 
0036   for (;;) {
0037     if (fin.getWordsInLine(wl) == 0)
0038       break;
0039     // build the list of entries

0040     if (wl[0] == "CAL:" || wl[0] == "UNK:") {
0041       if (ALIUtils::debug >= 4)
0042         ALIUtils::dumpVS(wl, " ErrorCorrelationMgr: reading entry ");
0043       theEntries[ALIUtils::getInt(wl[1])] = std::pair<ALIstring, ALIstring>(wl[2], wl[3]);
0044       //    } else if( wl[0][0] == '(' ) {

0045     } else if (wl[0].substr(0, 5) == "CORR:") {
0046       // find the two entries

0047       int p1 = wl[1].find('(');
0048       int p2 = wl[1].find(')');
0049       //      std::cout << "( found " << p1 << " " << p2 << " = " << wl[1].substr(p1+1,p2-p1-1) << std::endl;

0050       if (p2 == -1) {
0051         std::cerr
0052             << "!!!ERROR:  ErrorCorrelationMgr::readFromReportFile. Word found that starts with '(' but has no ')'"
0053             << wl[1] << std::endl;
0054         std::exception();
0055       }
0056       ALIint nent = ALIUtils::getInt(wl[1].substr(p1 + 1, p2 - p1 - 1));
0057       missite = theEntries.find(nent);
0058       std::pair<ALIstring, ALIstring> entry1 = (*missite).second;
0059 
0060       p1 = wl[2].find('(');
0061       p2 = wl[2].find(')');
0062       //      std::cout << "( found " << p1 << " " << p2 << " = " << wl[2].substr(p1+1,p2-p1-1) << std::endl;

0063       if (p2 == -1) {
0064         std::cerr
0065             << "!!!ERROR:  ErrorCorrelationMgr::readFromReportFile. Word found that starts with '(' but has no ')'"
0066             << wl[2] << std::endl;
0067         std::exception();
0068       }
0069       nent = ALIUtils::getInt(wl[2].substr(p1 + 1, p2 - p1 - 1));
0070       missite = theEntries.find(nent);
0071       std::pair<ALIstring, ALIstring> entry2 = (*missite).second;
0072 
0073       // build an ErrorCorrelation or update it if it exists

0074       std::vector<ErrorCorrelation*>::iterator itecorr = findErrorCorrelation(entry1, entry2);
0075       if (itecorr == theCorrs.end()) {
0076         ErrorCorrelation* corr = new ErrorCorrelation(entry1, entry2, ALIUtils::getFloat(wl[3]));
0077         if (ALIUtils::debug >= 4) {
0078           std::cout << " ErrorCorrelationMgr: correlation created " << entry1.first << " " << entry1.second << "  "
0079                     << entry2.first << " " << entry2.second << "  " << wl[3] << std::endl;
0080         }
0081         theCorrs.push_back(corr);
0082       } else {
0083         (*itecorr)->update(ALIUtils::getFloat(wl[3]));
0084         if (ALIUtils::debug >= 4) {
0085           std::cout << " ErrorCorrelationMgr: correlation updated " << entry1.first << " " << entry1.second << "  "
0086                     << entry2.first << " " << entry2.second << "  " << wl[3] << std::endl;
0087         }
0088       }
0089     }
0090   }
0091 }
0092 
0093 //----------------------------------------------------------------------------

0094 ErrorCorrelation* ErrorCorrelationMgr::getCorrelation(ALIint ii) {
0095   if (ii < 0 || ii >= ALIint(theCorrs.size())) {
0096     std::cerr << "!!!EXITING: ErrorCorrelationMgr::getCorrelation. incorrect nubmer = " << ii
0097               << " size = " << theCorrs.size() << std::endl;
0098     exit(1);
0099   } else {
0100     return theCorrs[ii];
0101   }
0102 }
0103 
0104 //----------------------------------------------------------------------------

0105 std::vector<ErrorCorrelation*>::iterator ErrorCorrelationMgr::findErrorCorrelation(pss& entry1, pss& entry2) {
0106   std::vector<ErrorCorrelation*>::iterator itecorr;
0107   for (itecorr = theCorrs.begin(); itecorr != theCorrs.end(); ++itecorr) {
0108     if ((*itecorr)->getEntry1() == entry1 && (*itecorr)->getEntry2() == entry2) {
0109       return itecorr;
0110     }
0111   }
0112 
0113   return itecorr;
0114 }