00001 #include "Sct/SctNames.h"
00002 #include "extraScans.h"
00003 #include "autoConfig.h"
00004 #include "SctApiImpl.h"
00005
00006 using namespace std;
00007 using namespace SctApi;
00008
00009 using namespace SctApi::AutoConf;
00010
00011 #include "ABCD/ABCDscans.h"
00012
00013 void AutoConfigurer::run() {
00014 api.modifyBOCParam(ST_RX_THRESHOLD, 128);
00015
00016
00017 boost::shared_ptr<Scan> txScan(new ScanDefImpl);
00018
00019 txScan->setNTrigs(1);
00020 txScan->getTrigger1()->singleL1A();
00021
00022 txScan->configure(SCT_SCAN_RAW_TX_CHANNELS, 0, 47, 1);
00023
00024
00025 MRSStream &mrs = Sct::SctNames::Mrs();
00026
00027 const list<RodLabel> rodList = api.listRods();
00028
00029 if(rodList.size() < 1) {
00030 cout << "AutoConfig: No RODs defined in configuration\n";
00031
00032 mrs << "AUTO_CONFIGURATION" << MRS_ERROR << MRS_QUALIF("SCTAPI") << MRS_QUALIF("AUTOPROBE")
00033 << MRS_TEXT("No RODs found in configuration")
00034 << ENDM;
00035 }
00036
00037 for(list<RodLabel>::const_iterator rl = rodList.begin();
00038 rl!=rodList.end();
00039 rl++){
00040
00041 const RodLabel &label = *rl;
00042
00043 std::vector< std::vector <char> > probeResult = api.probeScan(label.partition, label.crate, label.rod, txScan);
00044
00045 if(probeResult.size() < 48) {
00046 cout << "AutoConfig: Result too small: " << probeResult.size() << endl;
00047
00048 mrs << "AUTO_CONFIGURATION" << MRS_ERROR << MRS_QUALIF("SCTAPI") << MRS_QUALIF("AUTOPROBE")
00049 << MRS_PARAM<int>("crate", label.crate)
00050 << MRS_PARAM<int>("rod", label.rod)
00051 << MRS_TEXT("Scan failed for ROD")
00052 << ENDM;
00053 return;
00054 }
00055
00056 for(int point=0; point<48; point++) {
00057 if(probeResult[point].size() < 96) {
00058 cout << "AutoConfig: Scan too small: " << probeResult[point].size() << endl;
00059
00060 mrs << "AUTO_CONFIGURATION" << MRS_ERROR << MRS_QUALIF("SCTAPI") << MRS_QUALIF("AUTOPROBE")
00061 << MRS_PARAM<int>("pTTC", point)
00062 << MRS_PARAM<int>("crate", label.crate)
00063 << MRS_PARAM<int>("rod", label.rod)
00064 << MRS_TEXT("Internal error, result from scan too small")
00065 << ENDM;
00066 return;
00067 }
00068 for(int ch=0; ch<48; ch++) {
00069 char link0 = probeResult[point][ch*2 + 0];
00070 char link1 = probeResult[point][ch*2 + 1];
00071 if((link0 == '2' || link0 == 'E')
00072 && (link1 == '2' || link1 == 'E')) {
00073 cout << "AutoConfig: Module " << ch << " connected to tx " << point << endl;
00074
00075 results.push_back(AutoResult(label.partition, label.crate, label.rod, point, ch));
00076
00077 mrs << "MODULE_FOUND" << MRS_INFORMATION << MRS_QUALIF("SCTAPI") << MRS_QUALIF("AUTOPROBE")
00078
00079 << MRS_PARAM<int>("pTTC", point)
00080
00081 << MRS_PARAM<int>("rx0", ch*2 + 0)
00082 << MRS_PARAM<int>("rx1", ch*2 + 1)
00083 << MRS_PARAM<int>("crate", label.crate)
00084 << MRS_PARAM<int>("rod", label.rod)
00085 << MRS_PARAM<int>("harness", ch / 6)
00086 << MRS_PARAM<int>("position", (ch % 6) + 1)
00087 << MRS_TEXT("Module response found")
00088 << ENDM;
00089
00090 break;
00091 } else {
00092 continue;
00093 }
00094 }
00095 }
00096
00097
00098 api.configureBOC(label.partition, label.crate, label.rod);
00099 }
00100
00101 if(results.size() == 0) {
00102 mrs << "AUTO_CONFIGURATION" << MRS_INFORMATION << MRS_QUALIF("SCTAPI") << MRS_QUALIF("AUTOPROBE")
00103 << MRS_TEXT("Autoprobe complete, no modules found")
00104 << ENDM;
00105 cout << "Autoprobe complete, no modules found\n";
00106 }
00107 }
00108
00109 list<AutoResult> AutoConfigurer::getResults() {
00110 return results;
00111 }