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 if (TxCurrentTestResult::StreamResult::isGoodPhysicalTxCurrent(threshold)) {
00041 APICALL(api, modifyABCDModuleVar(mid, ST_TX_CURRENT, threshold ), "TxCurrentConfigUpdater failed to set delay") ;
00042 std::ostringstream os;
00043 os << "Setting Register ST_TX_CURRENT=" << ST_TX_CURRENT << " based on data from link " << linkNumber << " of module " << mid << " named " << name << " to " << threshold;
00044 SctNames::Mrs() << "CC_UPDATE" << MRS_INFORMATION << MRS_TEXT(os.str()) << ENDM;
00045 } else {
00046 std::ostringstream os;
00047 os << "Warning: was unable to set the TxCurrent based on data from link "<<linkNumber<<" of module " << mid << " as the test was not able to determine a sensible value for it! ["<<threshold<<"]";
00048 SctNames::Mrs() << "CC_UPDATE" << MRS_WARNING << MRS_TEXT(os.str()) << ENDM;
00049 };
00050 };
00051
00052 void TxCurrentConfigUpdater::update(const TestResult& testresult, Sct_SctApi::SctApiIPC_ptr api) const {
00053 const TxCurrentTestResult& t = dynamic_cast<const TxCurrentTestResult&> (testresult);
00054
00055 unsigned long mid = getMID(t, api);
00056 SctNames::Mrs() << "CC_UPDATE" << MRS_TEXT("CalibrationController updating TxCurrent") << MRS_PARAM<long>("ModuleID", mid) << MRS_DIAGNOSTIC << ENDM;
00057
00058 const TxCurrentTestResult::StreamResult & sr0 = t.getStreamResult(0);
00059 const TxCurrentTestResult::StreamResult & sr1 = t.getStreamResult(1);
00060
00061 const int link0ThreshMin = sr0.minErrorFreeTxCurrent();
00062 const int link1ThreshMin = sr1.minErrorFreeTxCurrent();
00063 const int link0ThreshMax = sr0.maxErrorFreeTxCurrent();
00064 const int link1ThreshMax = sr1.maxErrorFreeTxCurrent();
00065 const int link0ThreshBest = sr0.bestTxCurrent();
00066 const int link1ThreshBest = sr1.bestTxCurrent();
00067 const int link0Width = link0ThreshMax - link0ThreshMin;
00068 const int link1Width = link1ThreshMax - link1ThreshMin;
00069 const bool link0Invalid = sr0.isInvalid();
00070 const bool link1Invalid = sr1.isInvalid();
00071
00072 const std::string & name = t.getModuleName();
00073
00074 if (link0Invalid && link1Invalid) {
00075
00076 } else if (link0Invalid) {
00077
00078 this->updateUsing(link1ThreshBest, 1, api, mid, name);
00079 } else if (link1Invalid) {
00080
00081 this->updateUsing(link0ThreshBest, 0, api, mid, name);
00082 } else {
00083
00084
00085 if (link0Width>link1Width) {
00086 this->updateUsing(link0ThreshBest, 0, api, mid, name);
00087 this-> complainIf(link0ThreshBest, 0, mid, name, link1ThreshMin, link1ThreshMax);
00088 } else {
00089 this->updateUsing(link1ThreshBest, 1, api, mid, name);
00090 this-> complainIf(link1ThreshBest, 1, mid, name, link0ThreshMin, link0ThreshMax);
00091 };
00092 };
00093 }
00094
00095 }