00001
00002 #include "SctApi.h"
00003
00004 #include "Sct/MultiMessageDebugStream.h"
00005 #include "CommonWithDsp/registerIndices.h"
00006
00007 #include "sctConf/configuration.h"
00008
00009 #include "primListWrapper.h"
00010 #include "PrimBuilder.h"
00011
00012 #include "CommonWithDsp/primParams.h"
00013
00014 namespace SctApi {
00015 bool SctApi::changeRunMode(enum RunType mode) {
00016 switch(mode) {
00017 case SCTAPI_RUN_PHYSICS:
00018 {
00019 {
00020 Sct::MultiMessageDebugStream m(true,false,true);
00021 m << ucid() << " Is changing to Physics mode\n";
00022 }
00023
00024
00025 if(!checkAllModulesProbe("E")) {
00026 #warning "Possibly disable the ones that aren't returning events? (with warnings!)"
00027 if(mrs) {
00028 *mrs << "SCAN_ABORTED" << MRS_ERROR << MRS_QUALIF("SCTAPI")
00029 << MRS_TEXT("Switch to physics mode aborting (All modules not returning events)")
00030 << MRS_PARAM<const char*>("ucid",static_cast<std::string>(ucid()).c_str()) << ENDM;
00031 }
00032 return false;
00033 }
00034
00035
00036
00037 boost::shared_ptr<PrimListWrapper> preTimList(new PrimListWrapper(4));
00038
00039 for(int f=0; f<8; f++) {
00040
00041
00042
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 boost::shared_ptr<PrimListWrapper> binTimList(new PrimListWrapper(4));
00055
00056 bool doingHistograms = false;
00057 if(doingHistograms) {
00058
00059 boost::shared_ptr<PrimListWrapper> setTriggerList(new PrimListWrapper(4));
00060
00061
00062
00063 for(int s=0; s<4; s++) {
00064 PrimBuilder::instance().slavePrimList(binTimList, setTriggerList, s, 1, 0);
00065 }
00066 }
00067
00068
00069
00070 PrimBuilder::instance().writeRegister(binTimList, EFB_CMND_0, 24, 8, 0xfb);
00071 PrimBuilder::instance().rodMode(binTimList, DATA_TAKING_MODE, 0, 1, 0, 0, 1);
00072
00073
00074 std::cout << "Sending TIM setup list\n";
00075 synchSendPrimListAll(binTimList);
00076 std::cout << " done sending TIM setup list\n";
00077
00078
00079 timWriteRegister(0x14, 0x0000);
00080
00081
00082 unsigned short triggerEnablesInternal = 0x0;
00083 unsigned short triggerEnablesTTC = 0x62f;
00084
00085 try {
00086 SctConfiguration::TimConfig timConf;
00087 timConf = config->getTimConfig(ucid().partition(), ucid().crate());
00088
00089 if(timConf.validMask & 0x18) {
00090 timConf.triggerEnablesInternal = triggerEnablesInternal;
00091 timConf.triggerEnablesTTC = triggerEnablesTTC;
00092 }
00093 } catch(SctConfiguration::ConfigurationException &c) {
00094
00095 }
00096
00097 timWriteRegister(0x18, triggerEnablesTTC);
00098 timWriteRegister(0x0, triggerEnablesInternal);
00099
00100 std::cout << ucid() << " Is in Physics mode\n";
00101
00102 currentRunMode = SCTAPI_RUN_PHYSICS;
00103
00104 return true;
00105 }
00106 case SCTAPI_RUN_CALIBRATION:
00107 {
00108
00109
00110 timWriteRegister(0x18, 0);
00111 timWriteRegister( 0x0, 0);
00112
00113 calib_init();
00114 std::cout << ucid() << " Is in calibration mode\n";
00115
00116 currentRunMode = SCTAPI_RUN_CALIBRATION;
00117
00118 return true;
00119 }
00120 }
00121 return false;
00122 }
00123
00124 bool SctApi::changeEventFormat(enum EventFormatType format) {
00125 boost::shared_ptr<PrimListWrapper> formatPrimList(new PrimListWrapper(4));
00126 switch(format) {
00127 case SCTAPI_EVENT_FORMAT_NORMAL:
00128 {
00129 for(int f=0; f<8; f++) {
00130 PrimBuilder::instance().writeRegister(formatPrimList, FMT_EXP_MODE_EN(f), 0, 12, 0x0);
00131 PrimBuilder::instance().writeRegister(formatPrimList, FMT_CONFIG_MODE_EN(f), 0, 12, 0x0);
00132 }
00133 break;
00134 }
00135
00136 case SCTAPI_EVENT_FORMAT_EXPANDED:
00137 {
00138 for(int f=0; f<8; f++) {
00139 PrimBuilder::instance().writeRegister(formatPrimList, FMT_EXP_MODE_EN(f), 0, 12, 0xfff);
00140 PrimBuilder::instance().writeRegister(formatPrimList, FMT_CONFIG_MODE_EN(f), 0, 12, 0x0);
00141 }
00142 break;
00143 }
00144
00145 case SCTAPI_EVENT_FORMAT_RAW:
00146 {
00147 for(int f=0; f<8; f++) {
00148 PrimBuilder::instance().writeRegister(formatPrimList, FMT_EXP_MODE_EN(f), 0, 12, 0x0);
00149 PrimBuilder::instance().writeRegister(formatPrimList, FMT_CONFIG_MODE_EN(f), 0, 12, 0xfff);
00150 }
00151 break;
00152 }
00153 }
00154 synchSendPrimListAll(formatPrimList);
00155 }
00156 }