SctApiHigh.cxx

00001 // enum RunType {PHYSICS, CALIBRATION};
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     // Modules already in Physics mode?
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     // What resets to do?
00035 
00036     // Prepare a longish primitive list 
00037     boost::shared_ptr<PrimListWrapper> preTimList(new PrimListWrapper(4));
00038 
00039     for(int f=0; f<8; f++) {
00040       //   PrimBuilder::instance().writeRegister(preTimList, DM_DFLT_LUT(f), 0, 16, 0xaaaa);   // Decrement L1 for check
00041       //   PrimBuilder::instance().writeRegister(preTimList, DM_DFLT_LUT(f), 0, 16, 0x5555);   // Increment L1 for check
00042       //    PrimBuilder::instance().writeRegister(preTimList, DM_DFLT_LUT(f), 0, 16, 0x0);   // Clear L1 inc
00043     }
00044 
00045     //for(int ch=0; ch<48; ch++) {
00046     //  PrimBuilder::instance().writeRegister(preTimList, Utility::EfbErrorMask(0, ch), 5, 1, 1);  // Mask L1ID check
00047     //  PrimBuilder::instance().writeRegister(preTimList, Utility::EfbErrorMask(1, ch), 5, 1, 1);  // Mask L1ID check
00048     //}
00049 
00050     //       std::cout << "Sending preparatory TIM setup list\n";
00051     //       synchSendPrimListAll(preTimList);
00052     //       std::cout << " done sending preparatory TIM setup list\n";
00053     
00054     boost::shared_ptr<PrimListWrapper> physicsSetupList(new PrimListWrapper(4));
00055     
00056     PrimBuilder &builder = PrimBuilder::instance();
00057 
00058     bool doingHistograms = false;
00059     if(doingHistograms) {
00060       // SET_TRIGGER (ie tell histograms about next bin)
00061       boost::shared_ptr<PrimListWrapper> setTriggerList(new PrimListWrapper(4));
00062       //    PrimBuilder::instance().setTrigger(setTriggerList, binCount, Utility::translateBank(SCTAPI_BANK_SCAN));
00063       
00064       // Send to all slaves
00065       for(int s=0; s<4; s++) {
00066         PrimBuilder::instance().slavePrimList(physicsSetupList, setTriggerList, s, 1, 0);
00067       }
00068     }
00069 
00070     // Set offset for BCID check
00071     //  (this value tested at CERN SR1 with local LTP resets and triggers)
00072     builder.writeRegister(physicsSetupList, EFB_CMND_0, 24, 8, 0xfb);
00073     builder.rodMode(physicsSetupList, DATA_TAKING_MODE, 0, 1, 0, 0, 1);
00074 
00075     // Don't mask LDown# or S-link!!!
00076     builder.writeRegister(physicsSetupList, RTR_CMND_STAT, RTR_INHIBIT_SLNK_WE_O, 1, 0);
00077     builder.writeRegister(physicsSetupList, RTR_CMND_STAT, RTR_SLINK_DOWN_OVERRIDE_O, 1, 0);
00078 
00079     std::cout << "Sending TIM setup list\n";
00080     synchSendPrimListAll(physicsSetupList);
00081     std::cout << " done sending TIM setup list\n";
00082 
00083     // Set BCID offset to 0  (reset value is 6!)
00084     timWriteRegister(0x14, 0x0000);
00085 
00086     // Specify some sane defaults
00087     unsigned short triggerEnablesInternal = 0x0;
00088     unsigned short triggerEnablesTTC = 0x62f; // We know this works, 0xc7af has more things
00089 
00090     try {
00091       SctConfiguration::TimConfig timConf;
00092       timConf = config->getTimConfig(ucid().partition(), ucid().crate());
00093 
00094       if(timConf.validMask & 0x18) { // One of triggerEnablesInternal or triggerEnablesTTC
00095         timConf.triggerEnablesInternal = triggerEnablesInternal;
00096         timConf.triggerEnablesTTC = triggerEnablesTTC;
00097       }
00098     } catch(SctConfiguration::ConfigurationException &c) {
00099       //
00100     }
00101 
00102     timWriteRegister(0x18, triggerEnablesTTC);
00103     timWriteRegister(0x0, triggerEnablesInternal);
00104 
00105     std::cout << ucid() << " Is in Physics mode\n";
00106 
00107     currentRunMode = SCTAPI_RUN_PHYSICS;
00108 
00109     return true;
00110       }
00111     case SCTAPI_RUN_CALIBRATION:
00112       {
00113     // Not really much to do... ???
00114 
00115     timWriteRegister(0x18, 0x600);
00116     timWriteRegister( 0x0, 0);
00117 
00118     calib_init();
00119 
00120     boost::shared_ptr<PrimListWrapper> calSetupList(new PrimListWrapper(4));
00121     PrimBuilder::instance().writeRegister(calSetupList, EFB_CMND_0, 24, 8, 0x0);
00122     std::cout << "Resetting BC offset for cal\n";
00123     synchSendPrimListAll(calSetupList);
00124     std::cout << " done resetting BC offset\n";
00125 
00126     std::cout << ucid() << " Is in calibration mode\n";
00127 
00128     currentRunMode = SCTAPI_RUN_CALIBRATION;
00129 
00130     return true;
00131       }
00132     }
00133     return false;
00134   }
00135 
00136   bool SctApi::changeEventFormat(enum EventFormatType format) {
00137     boost::shared_ptr<PrimListWrapper> formatPrimList(new PrimListWrapper(4));
00138     switch(format) {
00139     case SCTAPI_EVENT_FORMAT_NORMAL:
00140       {      
00141     for(int f=0; f<8; f++) {
00142       PrimBuilder::instance().writeRegister(formatPrimList, FMT_EXP_MODE_EN(f), 0, 12, 0x0);
00143       PrimBuilder::instance().writeRegister(formatPrimList, FMT_CONFIG_MODE_EN(f), 0, 12, 0x0);
00144     }
00145     break;
00146       }
00147 
00148     case SCTAPI_EVENT_FORMAT_EXPANDED:
00149       {      
00150     for(int f=0; f<8; f++) {
00151       PrimBuilder::instance().writeRegister(formatPrimList, FMT_EXP_MODE_EN(f), 0, 12, 0xfff);
00152       PrimBuilder::instance().writeRegister(formatPrimList, FMT_CONFIG_MODE_EN(f), 0, 12, 0x0);
00153     }
00154     break;
00155       }
00156 
00157     case SCTAPI_EVENT_FORMAT_RAW:
00158       {      
00159     for(int f=0; f<8; f++) {
00160       PrimBuilder::instance().writeRegister(formatPrimList, FMT_EXP_MODE_EN(f), 0, 12, 0x0);
00161       PrimBuilder::instance().writeRegister(formatPrimList, FMT_CONFIG_MODE_EN(f), 0, 12, 0xfff);
00162     }
00163     break;
00164       }
00165     }
00166     synchSendPrimListAll(formatPrimList);
00167   }
00168 }

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