TrimRangeConfigUpdater.cpp

00001 #include "TrimRangeConfigUpdater.h"
00002 #include "ConfigUpdaterManager.h"
00003 #include "../SctApiAccessException.h"
00004 #include "../SctApiCall.h"
00005 
00006 #include "Sct_SctApi/SctApi.hh"
00007 #include "Sct/SequenceUtils.h"
00008 #include "Sct/SctParameters.h"
00009 #include "Sct/SctNames.h"
00010 #include "Sct/OutOfRangeError.h"
00011 #include "SctData/TrimRangeTestResult.h"
00012 #include "SctData/DefectPrototype.h"
00013 #include "Sct/AbcdScans.h"
00014 
00015 using namespace SctData;
00016 using namespace Sct;
00017 
00018 namespace SctCalibrationController {
00019 
00020 bool TrimRangeConfigUpdater::inMap = ConfigUpdaterManager::instance().setUpdater("SctData::TrimRangeTestResult", shared_ptr<TrimRangeConfigUpdater> (new TrimRangeConfigUpdater() ) );
00021 
00022 void TrimRangeConfigUpdater::update(const TestResult& testresult, Sct_SctApi::SctApiIPC_ptr api) const {
00023     const TrimRangeTestResult& t = dynamic_cast<const TrimRangeTestResult&> (testresult) ;
00024     unsigned long mid = getMID(t, api);
00025     short trims[nChannelModule];
00026 
00027     if (t.chipTrim.size()!=Sct::nChipModule) {
00028     throw Sct::OutOfRangeError<int>("Wrong number of chip trims!", __FILE__, __LINE__, t.chipTrim.size(), Sct::nChipModule, Sct::nChipModule);
00029     }
00030 
00031     for (unsigned ichip=0; ichip<Sct::nChipModule; ++ichip) {
00032          if (t.chipTrim[ichip].get()){
00033          unsigned int range = t.chipTrim[ichip]->range;
00034          float target = t.chipTrim[ichip]->target;
00035          SctNames::Mrs() << "CC_UPDATE" << MRS_TEXT("CalibrationController updating trim target and range") 
00036                      << MRS_PARAM<long>("ModuleID", mid) << MRS_PARAM<long>("Chip", ichip) 
00037                  << MRS_PARAM<int>("Range", range) << MRS_PARAM<float>("Target(mV)", target) 
00038                  << MRS_INFORMATION << ENDM;
00039          APICALL(api, modifyABCDChipVar(mid, ichip, ST_TRIM_RANGE, range), "TrimRangeConfigUpdater failed to set trim range")
00040          APICALL(api, modifyABCDChipVar(mid, ichip, ST_TARGET, target), "TrimRangeConfigUpdater failed to set trim range")
00041      } else {
00042          std::ostringstream oss;
00043          oss << "CalibrationController could not update trim range for chip " << ichip;
00044          SctNames::Mrs() << "CC_UPDATE" << MRS_TEXT(oss.str().c_str()) 
00045                      << MRS_PARAM<long>("ModuleID", mid)  << MRS_PARAM<long>("Chip#", ichip) 
00046                  << MRS_DIAGNOSTIC << ENDM;
00047          continue;
00048     }
00049     for (unsigned ichannel=0; ichannel < nChannelChip; ++ ichannel){
00050         unsigned channelInModule=ichip*nChannelChip+ichannel;
00051         
00052         assert(channelInModule<Sct::nChannelModule);
00053         
00054         if (t.chipTrim[ichip]->channelTrim.getAt(ichannel).valid){
00055         trims[channelInModule] =  t.chipTrim[ichip]->channelTrim.getAt(ichannel).value.trim ;
00056         }else{
00057         trims[channelInModule] = 8;
00058         }
00059     }   
00060     }
00061     
00062     SctNames::Mrs() << "CC_UPDATE" << MRS_TEXT("CalibrationController updating trims") << MRS_PARAM<long>("ModuleID", mid) << MRS_INFORMATION << ENDM;
00063     Sct_SctApi::CharBlock data = SequenceUtils::safeSequence<Sct_SctApi::CharBlock>(nChannelModule);
00064     for (unsigned int i=0; i<nChannelModule; ++i) {
00065       data[i]=trims[i];
00066     };
00067     APICALL(api, modifyABCDTrims(mid, data), "TrimRangeConfigUpdater failed to set trims")
00068 
00069     maskChannels(t, UNUSEABLE, api);
00070 }       
00071 
00072 }

Generated on Mon Feb 6 14:01:36 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6