Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages

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> binTimList(new PrimListWrapper(4));
00055     
00056     bool doingHistograms = false;
00057     if(doingHistograms) {
00058       // SET_TRIGGER (ie tell histograms about next bin)
00059       boost::shared_ptr<PrimListWrapper> setTriggerList(new PrimListWrapper(4));
00060       //    PrimBuilder::instance().setTrigger(setTriggerList, binCount, Utility::translateBank(SCTAPI_BANK_SCAN));
00061       
00062       // Send to all slaves
00063       for(int s=0; s<4; s++) {
00064         PrimBuilder::instance().slavePrimList(binTimList, setTriggerList, s, 1, 0);
00065       }
00066     }
00067 
00068     // Set offset for BCID check
00069     //  (this value tested at CERN SR1 with local LTP resets and triggers)
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     // Don't mask LDown#!!!
00073 
00074     std::cout << "Sending TIM setup list\n";
00075     synchSendPrimListAll(binTimList);
00076     std::cout << " done sending TIM setup list\n";
00077 
00078     // Set BCID offset to 0  (reset value is 6!)
00079     timWriteRegister(0x14, 0x0000);
00080 
00081     // Specify some sane defaults
00082     unsigned short triggerEnablesInternal = 0x0;
00083     unsigned short triggerEnablesTTC = 0x62f; // We know this works, 0xc7af has more things
00084 
00085     try {
00086       SctConfiguration::TimConfig timConf;
00087       timConf = config->getTimConfig(ucid().partition(), ucid().crate());
00088 
00089       if(timConf.validMask & 0x18) { // One of triggerEnablesInternal or triggerEnablesTTC
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     // Not really much to do... ???
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 }

Generated on Fri Dec 16 19:38:19 2005 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5