00001 #include "Trigger.h"
00002 #include "RodCrate/TimDefine.h"
00003 #include <iostream>
00004 #include <sstream>
00005 #include "SctApiException.h"
00006 #include "CommonWithDsp/Sct/ABCDchip.h"
00007
00008 namespace SctApi{
00009 Trigger::~Trigger(){}
00010
00011
00012 int Trigger::getUniqueSlowCommandType(const ::SctApi::Trigger::RODTriggers& rTrigs){
00013 unsigned slow_command_type=0;
00014 for (::SctApi::Trigger::RODTriggers::const_iterator i=rTrigs.begin();
00015 i!=rTrigs.end(); ++i){
00016 switch ((*i).first) {
00017 case CALIBRATION_PULSE :
00018 case PULSE_INPUT_REG :
00019 case ENABLE_DATA_TAKING : {
00020 if (slow_command_type && slow_command_type!=(*i).first){
00021 std::ostringstream message;
00022 message << "Invalid TIM trigger. Contains more than one type of slow command, first "
00023 << slow_command_type << " and then later " << (*i).first;
00024 throw SctApiException(message.str());
00025 }
00026 slow_command_type=(*i).first;
00027 }
00028 default: continue;
00029 }
00030 }
00031 return slow_command_type;
00032 }
00033
00034
00035
00036 ::SctApi::Trigger::TIMTriggers Trigger::convertToTIMTriggers(const ::SctApi::Trigger::RODTriggers& rTrigs){
00037
00038 unsigned slow_command_type=0;
00039
00040 using namespace SctPixelRod;
00041 ::SctApi::Trigger::TIMTriggers tTrigs;
00042 for (::SctApi::Trigger::RODTriggers::const_iterator i=rTrigs.begin();
00043 i!=rTrigs.end(); ++i){
00044 switch ((*i).first) {
00045 case L1_TRIGGER : tTrigs.push_back(TIM_L1A); continue;
00046 case BC_RESET : tTrigs.push_back(TIM_BCR); continue;
00047 case SOFT_RESET : tTrigs.push_back(TIM_ECR); continue;
00048
00049 case CALIBRATION_PULSE :
00050 case PULSE_INPUT_REG :
00051 case ENABLE_DATA_TAKING : {
00052 if (slow_command_type && slow_command_type!=(*i).first){
00053 std::ostringstream message;
00054 message << "Invalid TIM trigger. Contains more than one type of slow command, first "
00055 << slow_command_type << " and then later " << (*i).first;
00056 throw SctApiException(message.str());
00057 }
00058 slow_command_type=(*i).first;
00059 tTrigs.push_back(TIM_CAL);
00060 continue;
00061 }
00062
00063 case DELAY : tTrigs.resize(tTrigs.size()+(*i).second, 0); continue;
00064 default: {
00065 std::ostringstream message;
00066 message << "Not a valid TIM trigger type: " << (*i).first;
00067 throw SctApiException(message.str());
00068 }
00069 }
00070 }
00071 return tTrigs;
00072 }
00073
00074 std::string Trigger::getNameOfRODTrigger(RODTrigger t){
00075 switch (t.first){
00076 case L1_TRIGGER: return "L1A";
00077 case BC_RESET: return "BCR";
00078 case SOFT_RESET: return "SOFT" ;
00079 case CALIBRATION_PULSE: return "CAL";
00080 case DELAY: {
00081 std::ostringstream name;
00082 name << "DELAY (" << t.second<< ")";
00083 return name.str();
00084 }
00085 case ENABLE_DATA_TAKING: return "ENABLE_DATA_TAKING" ;
00086 case PULSE_INPUT_REG: return "PULSE_INPUT_REG" ;
00087 default: {
00088 std::ostringstream name;
00089 name << t.first << "=UNKNOWN";
00090 return name.str();
00091 }
00092 }
00093 }
00094
00095 }