Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

TxCurrentConfigUpdater.cpp

00001 #include "TxCurrentConfigUpdater.h"
00002 #include "ConfigUpdaterManager.h"
00003 #include "../SctApiAccessException.h"
00004 #include "../SctApiCall.h"
00005 
00006 #include "Sct_SctApi/SctApi.hh"
00007 #include "Sct/SctParameters.h"
00008 #include "Sct/SctNames.h"
00009 #include "SctData/TxCurrentTestResult.h"
00010 #include "Sct/AbcdScans.h"
00011 #include "SctApi/utility.h"
00012 
00013 using namespace Sct;
00014 using namespace SctData;
00015 
00016 namespace SctCalibrationController {
00017 
00018 bool TxCurrentConfigUpdater::inMap = ConfigUpdaterManager::instance().setUpdater("SctData::TxCurrentTestResult", shared_ptr<ConfigUpdater> (new TxCurrentConfigUpdater()));
00019 
00020   void TxCurrentConfigUpdater::complainIf(const int threshold,
00021                                           const unsigned int linkNumber,
00022                                           const unsigned long mid,
00023                                           const std::string & name,
00024                                           const int otherMin,
00025                                           const int otherMax) {
00026     if ((threshold>otherMax && TxCurrentTestResult::StreamResult::isGoodPhysicalTxCurrent(otherMax)) || (threshold<otherMin && TxCurrentTestResult::StreamResult::isGoodPhysicalTxCurrent(otherMin))) {
00027       unsigned partition, crate, rod, channel;
00028       SctApi::Utility::getpcrc(mid, partition, crate, rod, channel);
00029       std::ostringstream os;
00030       os << "Warning: while setting the TxCurrent for module " << mid << " named " << name << " in prcc " << partition << "/" << crate << "/" << rod << "/" << channel << " at line " << __LINE__<< " of " << __FILE__ << " it was thought best to use the data returned from link " << linkNumber<< " as it appeared slightly more reliable.  This link indicated that a TxCurrent setting of " << threshold << " would be sensible.  The problem is that the value of TxCurrent we have just chosen to use is flaggeed as *unacceptable* by the data from the other link which expected a value lying in the range ["<<otherMin<<", "<<otherMax<<"].  So either link "<<(1-linkNumber)<< " is not working properly even though I thought it was fine.  You had better check the cause of this inconsistency.";
00031       SctNames::Mrs() << "CC_UPDATE" << MRS_WARNING << MRS_TEXT(os.str()) << ENDM;
00032     };
00033   };
00034 
00035   void TxCurrentConfigUpdater::updateUsing(const int threshold,
00036                                            const unsigned int linkNumber,
00037                                            Sct_SctApi::SctApiIPC_ptr api,
00038                                            const unsigned long mid,
00039                                            const std::string & name) {
00040     unsigned partition, crate, rod, channel;
00041     SctApi::Utility::getpcrc(mid, partition, crate, rod, channel);
00042 
00043     if (TxCurrentTestResult::StreamResult::isGoodPhysicalTxCurrent(threshold)) {  
00044       APICALL(api, modifyBOCParam(partition, crate, rod, channel, ST_TX_CURRENT, threshold ), "TxCurrentConfigUpdater failed to set delay") ;
00045       std::ostringstream os;
00046       os << "Setting Register ST_TX_CURRENT=" << ST_TX_CURRENT << " based on data from link " << linkNumber << " of module " << mid << " named " << name << " in prcc " << partition << "/" << crate << "/" << rod << "/" << channel << " to " << threshold;
00047       SctNames::Mrs() << "CC_UPDATE" << MRS_INFORMATION << MRS_TEXT(os.str()) << ENDM;
00048     } else {
00049       std::ostringstream os;
00050       os << "Warning: was unable to set the TxCurrent based on data from link "<<linkNumber<<" of module " << mid << " in prcc " << partition << "/" << crate << "/" << rod << "/" << channel << " as the test was not able to determine a sensible value for it! ["<<threshold<<"]";
00051       SctNames::Mrs() << "CC_UPDATE" << MRS_WARNING << MRS_TEXT(os.str()) << ENDM;
00052     };
00053   };
00054 
00055 void TxCurrentConfigUpdater::update(const TestResult& testresult, Sct_SctApi::SctApiIPC_ptr api) const {
00056     const TxCurrentTestResult& t = dynamic_cast<const TxCurrentTestResult&> (testresult);
00057 
00058     unsigned long mid = getMID(t, api);
00059     SctNames::Mrs() << "CC_UPDATE" << MRS_TEXT("CalibrationController updating TxCurrent") << MRS_PARAM<long>("ModuleID", mid) << MRS_DIAGNOSTIC << ENDM;
00060 
00061     const TxCurrentTestResult::StreamResult & sr0 = t.getStreamResult(0);
00062     const TxCurrentTestResult::StreamResult & sr1 = t.getStreamResult(1);
00063     
00064     const int link0ThreshMin = sr0.minErrorFreeTxCurrent();
00065     const int link1ThreshMin = sr1.minErrorFreeTxCurrent();
00066     const int link0ThreshMax = sr0.maxErrorFreeTxCurrent();
00067     const int link1ThreshMax = sr1.maxErrorFreeTxCurrent();
00068     const int link0ThreshBest = sr0.bestTxCurrent();
00069     const int link1ThreshBest = sr1.bestTxCurrent();
00070     const int link0Width = link0ThreshMax - link0ThreshMin;
00071     const int link1Width = link1ThreshMax - link1ThreshMin;
00072     const bool link0Invalid = sr0.isInvalid(); 
00073     const bool link1Invalid = sr1.isInvalid();
00074  
00075     const std::string & name = t.getModuleName();
00076 
00077     if (link0Invalid && link1Invalid) {
00078       // both bad
00079     } else if (link0Invalid) {
00080       // link 1 ok
00081       this->updateUsing(link1ThreshBest, 1, api, mid, name);
00082     } else if (link1Invalid) {
00083       // link 0 ok
00084       this->updateUsing(link0ThreshBest, 0, api, mid, name);
00085     } else {
00086       // Both links ok.
00087       // For setting tx current we want (where possible) to be INSENSITVE to problems that there might be with the ability of the modules to send, so if one of the streams is worse than the other it is nothing to do with us.  We therefore set on the basis of the BEST (widest) window we see.
00088       if (link0Width>link1Width) {
00089         this->updateUsing(link0ThreshBest, 0, api, mid, name);
00090         this-> complainIf(link0ThreshBest, 0,      mid, name, link1ThreshMin, link1ThreshMax);
00091       } else {
00092         this->updateUsing(link1ThreshBest, 1, api, mid, name);
00093         this-> complainIf(link1ThreshBest, 1,      mid, name, link0ThreshMin, link0ThreshMax);
00094       };
00095     };
00096 }
00097     
00098 }

Generated on Fri Dec 16 19:38:25 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5