00001 #include "Identifier/MucID.h"
00002 #include <assert.h>
00003
00004 const unsigned int MucID::CHANNEL_BARREL_LAYER_NUM[MucID::LAYER_BARREL_NUM] =
00005 {64,112,64,112,64,112,64,112,64};
00006
00007 MucID::MucID(void) {
00008 }
00009
00010 MucID::~MucID(void) {
00011 }
00012
00013
00014 bool MucID::values_ok ( const unsigned int barrel_ec,
00015 const unsigned int segment,
00016 const unsigned int layer,
00017 const unsigned int channel
00018 ) {
00019
00020 if ( barrel_ec >= BARREL_EC_NUM ) return false;
00021 if ( barrel_ec == 0 || barrel_ec == BARREL_EC_NUM - 1 ) {
00022 if ( segment >= SEGMENT_ENDCAP_NUM ) return false;
00023 if ( layer >= LAYER_ENDCAP_NUM ) return false;
00024 if ( channel >= CHANNEL_ENDCAP_NUM_MAX ) return false;
00025 }
00026 else {
00027 if ( segment >= SEGMENT_BARREL_NUM ) return false;
00028 if ( layer >= LAYER_BARREL_NUM ) return false;
00029 if ( channel >= CHANNEL_BARREL_LAYER_NUM[layer] ) return false;
00030 }
00031 return true;
00032 }
00033
00034
00035 bool MucID::is_barrel (const Identifier& id) {
00036 unsigned int pos = (id.get_value() & MucID::BARREL_EC_MASK) >> MucID::BARREL_EC_INDEX;
00037 return (pos == 0 || pos == BARREL_EC_NUM - 1) ? false : true;
00038 }
00039
00040
00041 int MucID::barrel_ec (const Identifier& id) {
00042 return ((id.get_value() & MucID::BARREL_EC_MASK) >> MucID::BARREL_EC_INDEX);
00043 }
00044
00045
00046 int MucID::part (const Identifier& id) {
00047 return ((id.get_value() & MucID::BARREL_EC_MASK) >> MucID::BARREL_EC_INDEX);
00048 }
00049
00050
00051 int MucID::segment (const Identifier& id) {
00052 return (id.get_value() & MucID::SEGMENT_MASK) >> MucID::SEGMENT_INDEX;
00053 }
00054
00055
00056 int MucID::seg (const Identifier& id) {
00057 return (id.get_value() & MucID::SEGMENT_MASK) >> MucID::SEGMENT_INDEX;
00058 }
00059
00060
00061 int MucID::layer (const Identifier& id) {
00062 return (id.get_value() & MucID::LAYER_MASK) >> MucID::LAYER_INDEX;
00063 }
00064
00065
00066 int MucID::gap (const Identifier& id) {
00067 return (id.get_value() & MucID::LAYER_MASK) >> MucID::LAYER_INDEX;
00068 }
00069
00070
00071 int MucID::channel (const Identifier& id) {
00072 return (id.get_value() & MucID::CHANNEL_MASK) >> MucID::CHANNEL_INDEX;
00073 }
00074
00075
00076 int MucID::strip (const Identifier& id) {
00077 return (id.get_value() & MucID::CHANNEL_MASK) >> MucID::CHANNEL_INDEX;
00078 }
00079
00080
00081 int MucID::segment_max (const Identifier& id) {
00082 if (is_barrel(id)) {
00083 return SEGMENT_BARREL_NUM - 1;
00084 } else {
00085 return SEGMENT_ENDCAP_NUM - 1;
00086 }
00087 }
00088
00089
00090 int MucID::getSegNum (const Identifier& id) {
00091 if (is_barrel(id)) {
00092 return SEGMENT_BARREL_NUM;
00093 } else {
00094 return SEGMENT_ENDCAP_NUM;
00095 }
00096 }
00097
00098
00099 int MucID::layer_max (const Identifier& id) {
00100 if (this->is_barrel(id)) {
00101 return LAYER_BARREL_NUM - 1;
00102 } else {
00103 return LAYER_ENDCAP_NUM - 1;
00104 }
00105 }
00106
00107
00108 int MucID::getGapNum (const Identifier& id) {
00109 if (this->is_barrel(id)) {
00110 return LAYER_BARREL_NUM;
00111 } else {
00112 return LAYER_ENDCAP_NUM;
00113 }
00114 }
00115
00116
00117 int MucID::channel_max (const Identifier& id) {
00118 if (this->is_barrel(id)) {
00119 return CHANNEL_BARREL_NUM_MAX - 1;
00120 } else {
00121 return CHANNEL_ENDCAP_NUM_MAX - 1;
00122 }
00123 }
00124
00125
00126 int MucID::getStripNum (const Identifier& id) {
00127 if (this->is_barrel(id)) {
00128 return CHANNEL_BARREL_LAYER_NUM[this->gap(id)];
00129 } else {
00130 return CHANNEL_ENDCAP_NUM_MAX;
00131 }
00132 }
00133
00134
00135 Identifier MucID::channel_id ( int barrel_ec,
00136 int segment,
00137 int layer,
00138 int channel
00139 ) {
00140 assert ( values_ok(barrel_ec, segment, layer, channel) );
00141 value_type value = (MUC_ID << MUC_INDEX) | (barrel_ec << BARREL_EC_INDEX)|
00142 (segment << SEGMENT_INDEX) | (layer << LAYER_INDEX) | (channel << CHANNEL_INDEX);
00143 return Identifier(value);
00144 }
00145
00146
00147 unsigned int MucID::getIntID ( int barrel_ec,
00148 int segment,
00149 int layer,
00150 int channel
00151 ) {
00152 value_type value = (MUC_ID << MUC_INDEX) | (barrel_ec << BARREL_EC_INDEX)|
00153 (segment << SEGMENT_INDEX) | (layer << LAYER_INDEX) | (channel << CHANNEL_INDEX);
00154 return value;
00155
00156 }
00157
00158
00159 unsigned int MucID::getPartNum(){
00160 return BARREL_EC_NUM;
00161 }
00162
00164 unsigned int MucID::getSegNum( int part ) {
00165 if (part == 1) return SEGMENT_BARREL_NUM;
00166 else if (part == 0 || part == 2) return SEGMENT_ENDCAP_NUM;
00167 else return 0;
00168 }
00169
00170
00171 unsigned int MucID::getGapNum( int part ) {
00172 if (part == 1) return LAYER_BARREL_NUM;
00173 if (part == 0 || part == 2) return LAYER_ENDCAP_NUM;
00174 else return 0;
00175 }
00176
00177
00178 unsigned int MucID::getStripNum (int part, int seg, int gap) {
00179 if (part == 1) {
00180 if (seg == 2) return CHANNEL_BARREL_LAYER_NUM[gap];
00181 else return CHANNEL_BARREL_LAYER_NUM[gap];
00182 } else {
00183 return CHANNEL_ENDCAP_NUM_MAX;
00184 }
00185 }
00186
00188 unsigned int MucID::getSegMax() {
00189 if (SEGMENT_BARREL_NUM > SEGMENT_ENDCAP_NUM) return SEGMENT_BARREL_NUM;
00190 else return SEGMENT_ENDCAP_NUM;
00191 }
00192
00194
00195 unsigned int MucID::getGapMax() {
00196 if (LAYER_BARREL_NUM > LAYER_ENDCAP_NUM) return LAYER_BARREL_NUM;
00197 else return LAYER_ENDCAP_NUM;
00198 }
00199
00200 unsigned int MucID::getStripMax() {
00201 if (CHANNEL_BARREL_NUM_MAX > CHANNEL_ENDCAP_NUM_MAX) return CHANNEL_BARREL_NUM_MAX;
00202 else return CHANNEL_ENDCAP_NUM_MAX;
00203 }
00204
00205
00206 unsigned int MucID::getSEGMENT_BARREL_MAX(){
00207 return SEGMENT_BARREL_NUM - 1;
00208 }
00209
00210
00211 unsigned int MucID::getSEGMENT_ENDCAP_MAX(){
00212 return SEGMENT_ENDCAP_NUM - 1;
00213 }
00214
00215
00216 unsigned int MucID::getLAYER_BARREL_MAX(){
00217 return LAYER_BARREL_NUM - 1;
00218 }
00219
00220
00221 unsigned int MucID::getLAYER_ENDCAP_MAX(){
00222 return LAYER_ENDCAP_NUM - 1;
00223 }
00224
00225
00226 unsigned int MucID::getCHANNEL_BARREL_MAX(){
00227 return CHANNEL_BARREL_NUM_MAX;
00228 }
00229
00230
00231 unsigned int MucID::getCHANNEL_ENDCAP_MAX(){
00232 return CHANNEL_ENDCAP_NUM_MAX;
00233 }
00234
00235
00236 unsigned int MucID::getBARREL_EC_MAX(){
00237 return BARREL_EC_NUM - 1;
00238 }
00239
00240
00241 unsigned int MucID::getBARREL_EC_MIN(){
00242 return 0;
00243 }