00001 #include "Identifier/HltID.h"
00002 #include <assert.h>
00003 #include <stdint.h>
00004
00005 HltID::HltID(void) {
00006 }
00007
00008 HltID::~HltID(void) {
00009 }
00010
00011
00012 Identifier HltID::convert(const unsigned int id,const int nmdc,const int ntof,const int nemc,const int nmuc) {
00013 uint32_t subid=id&(HltID::DETECTOR_MASK|HltID::ID_SUB_MASK);
00014
00015 if(subid<=getID_HLT_MAX()) return data_type_id(HLT,subid);
00016
00017 subid = subid - getID_HLT_MAX();
00018 if(subid<=nmdc) return data_type_id(MDC,subid-1);
00019
00020 subid = subid - nmdc;
00021 if(subid<=ntof) return data_type_id(TOF,subid-1);
00022
00023 subid = subid - ntof;
00024 if(subid<=nemc) return data_type_id(EMC,subid-1);
00025
00026 subid = subid - nemc;
00027 if(subid<=nmuc) return data_type_id(MUC,subid-1);
00028
00029 subid = subid - nmuc;
00030 return data_type_id(CON,subid-1);
00031 }
00032
00033
00034 bool HltID::values_ok (const unsigned int detector,const unsigned int id_in_sub) {
00035
00036
00037
00038 switch(detector)
00039 {
00040 case HLT:
00041 if ( id_in_sub > ID_HLT_MAX ) return false;
00042 break;
00043 case MDC:
00044 if ( id_in_sub > ID_MDC_MAX ) return false;
00045 break;
00046 case TOF:
00047 if ( id_in_sub > ID_TOF_MAX ) return false;
00048 break;
00049 case EMC:
00050 if ( id_in_sub > ID_EMC_MAX ) return false;
00051 break;
00052 case MUC:
00053 if ( id_in_sub > ID_MUC_MAX ) return false;
00054 break;
00055 case CON:
00056 return true;
00057 break;
00058 default:
00059 return false;
00060 break;
00061 }
00062
00063 return true;
00064 }
00065
00066
00067 bool HltID::is_ef_result (const Identifier& id) {
00068 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00069 return (pos == HLT) ? true : false ;
00070 }
00071
00072 bool HltID::is_eventtype (const Identifier& id) {
00073 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00074 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00075 return ((pos == HLT)&&(no==EVENTTYPE)) ? true : false ;
00076 }
00077
00078 bool HltID::is_algorithm (const Identifier& id) {
00079 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00080 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00081 return ((pos == HLT)&&(no==ALGORITHM)) ? true : false ;
00082 }
00083
00084 bool HltID::is_criteria (const Identifier& id) {
00085 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00086 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00087 return ((pos == HLT)&&(no==CRITERIA)) ? true : false ;
00088 }
00089
00090 bool HltID::is_version (const Identifier& id) {
00091 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00092 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00093 return ((pos == HLT)&&(no==VERSION)) ? true : false ;
00094 }
00095
00096 bool HltID::is_energy (const Identifier& id) {
00097 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00098 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00099 return ((pos == HLT)&&(no==ENERGY)) ? true : false ;
00100 }
00101
00102 bool HltID::is_number (const Identifier& id) {
00103 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00104 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00105 return ((pos == HLT)&&(no==NUMSUB)) ? true : false ;
00106 }
00107
00108 bool HltID::is_ncon (const Identifier& id) {
00109 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00110 unsigned int no = (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00111 return ((pos == CON)&&(no==NUMCON)) ? true : false ;
00112 }
00113
00114 bool HltID::is_mdc_inf (const Identifier& id) {
00115 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00116 return (pos == MDC) ? true : false ;
00117 }
00118
00119 bool HltID::is_tof_inf (const Identifier& id) {
00120 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00121 return (pos == TOF) ? true : false ;
00122 }
00123
00124 bool HltID::is_emc_inf (const Identifier& id) {
00125 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00126 return (pos == EMC) ? true : false ;
00127 }
00128
00129 bool HltID::is_muc_inf (const Identifier& id) {
00130 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00131 return (pos == MUC) ? true : false ;
00132 }
00133
00134 bool HltID::is_con_inf (const Identifier& id) {
00135 unsigned int pos = (id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX;
00136 return (pos == CON) ? true : false ;
00137 }
00138
00139
00140 unsigned int HltID::detector (const Identifier& id) {
00141 return ((id.get_value() & HltID::DETECTOR_MASK) >> HltID::DETECTOR_INDEX);
00142 }
00143
00144
00145 unsigned int HltID::id_sub (const Identifier& id) {
00146 return (id.get_value() & HltID::ID_SUB_MASK) >> HltID::ID_SUB_INDEX;
00147 }
00148
00149
00150 unsigned int HltID::id_sub_max (const Identifier& id) {
00151 if (is_ef_result(id)) {
00152 return ID_HLT_MAX;
00153 }
00154 else if (is_mdc_inf(id)) {
00155 return ID_MDC_MAX;
00156 }
00157 else if (is_tof_inf(id)) {
00158 return ID_TOF_MAX;
00159 }
00160 else if (is_emc_inf(id)) {
00161 return ID_EMC_MAX;
00162 }
00163 else if (is_muc_inf(id)) {
00164 return ID_MUC_MAX;
00165 }
00166 else {
00167 return 0;
00168 }
00169 }
00170
00171
00172 Identifier HltID::data_type_id(const unsigned int detector,const unsigned int id_in_sub){
00173 assert ( values_ok(detector, id_in_sub) );
00174
00175
00176 unsigned int value = (HLT_ID << HLT_INDEX) | (detector << DETECTOR_INDEX)|
00177 (id_in_sub<< ID_SUB_INDEX);
00178 return Identifier(value);
00179 }
00180
00181 unsigned int HltID::getIntID (const unsigned int detector,const unsigned int id_in_sub){
00182 assert ( values_ok(detector, id_in_sub) );
00183
00184
00185 unsigned int value = (HLT_ID << HLT_INDEX) | (detector << DETECTOR_INDEX)|
00186 (id_in_sub<< ID_SUB_INDEX);
00187 return value;
00188 }
00189