00001 #include <iostream>
00002 #include <string>
00003
00004 #include "utility.h"
00005
00006 #include "primParams.h"
00007
00008 #include "SctApi.h"
00009
00010 using namespace std;
00011
00012 namespace SctApi {
00013 namespace Utility {
00014 void printMemoryBlock(ostream &os, unsigned long *mem, unsigned long words, int wordsPerLine, int level)
00015 {
00016 unsigned int lines = words/wordsPerLine;
00017 int skipping = 0;
00018
00019 os.fill('0');
00020
00021 os << hex;
00022 for(unsigned int i=0; i<lines; i++) {
00023 int val = 0;
00024 for(int j=0; j<wordsPerLine; j++) {
00025 val+=mem[i*wordsPerLine+j];
00026 }
00027 if(val == 0) {
00028 if(!skipping)
00029 os << string(" ", 0, level) << ".";
00030 skipping++;
00031 } else {
00032 if(skipping) os << " Skipped " << dec << skipping << hex << " blank lines\n";
00033 skipping = 0;
00034
00035 os << string(" ", 0, level);
00036 for(int j=0; j<wordsPerLine; j++) {
00037 os.fill('0');
00038 os.width(8);
00039 os << mem[i*wordsPerLine+j] << " ";
00040 }
00041 os << endl;
00042 }
00043 }
00044 if(skipping) os << " Skipped " << dec << skipping << hex << " blank lines\n";
00045 if(lines*wordsPerLine < words) {
00046 os << string(" ", 0, level);
00047 for(unsigned int i=lines*wordsPerLine; i<words; i++) {
00048 os.fill('0');
00049 os.width(8);
00050 os << mem[i] << " ";
00051 }
00052 os << endl;
00053 }
00054 os.fill(' ');
00055
00056 os << dec;
00057 }
00058
00059 int translateBank(BankType bank) {
00060 int realBank;
00061 switch(bank) {
00062 #ifdef PHYSICS_MODULE_CONFIG
00063 case SCTAPI_BANK_PHYSICS:
00064 realBank = PHYSICS_MODULE_CONFIG;
00065 break;
00066 case SCTAPI_BANK_SCAN:
00067 realBank = SCAN_MODULE_CONFIG;
00068 break;
00069 case SCTAPI_BANK_CALIBRATION:
00070 realBank = SPARE_MODULE_CONFIG;
00071 break;
00072 #else
00073 case SCTAPI_BANK_PHYSICS:
00074 realBank = INIT_MODULE_CONFIG;
00075 break;
00076 case SCTAPI_BANK_SCAN:
00077 realBank = WORK_MODULE_CONFIG;
00078 break;
00079 case SCTAPI_BANK_CALIBRATION:
00080 realBank = SPARE_MODULE_CONFIG;
00081 break;
00082 #endif
00083 default:
00084 std::cout << "translateBank: Invalid bank specification " << bank << endl;
00085 throw SctApiException("Invalid bank specification");
00086 }
00087 return realBank;
00088 }
00089 }
00090 }