00001
00002
00003
00004
00005
00006
00007
00009
00010 #include "Plex/PlexPixelSpotId.h"
00011
00012 #include "TBuffer.h"
00013 #include "TClass.h"
00014
00015 #include <iostream>
00016 #include <iomanip>
00017 #include <string>
00018 #include <cassert>
00019
00020 #include "MessageService/MsgService.h"
00021
00022
00023 ClassImp(PlexPixelSpotId)
00024
00025
00026 ostream& operator<<(ostream& os, const PlexPixelSpotId& p)
00027 {
00028 os << p.AsString();
00029
00030 return os;
00031 }
00032
00033
00034 PlexPixelSpotId::PlexPixelSpotId()
00035 : PlexMuxBoxId()
00036 {
00037
00038 }
00039
00040
00041 PlexPixelSpotId::PlexPixelSpotId(Detector::Detector_t detector,
00042 ElecType::Elec_t elec,
00043 Char_t eastwest, Char_t racklevel,
00044 UInt_t rackbay, UInt_t inrack,
00045 UInt_t tube, UInt_t pixel, UInt_t spot)
00046 : PlexMuxBoxId(detector,elec,eastwest,racklevel,rackbay,inrack)
00047 {
00048
00049
00050 SetTube(tube);
00051 SetPixel(pixel);
00052 SetSpot(spot);
00053 }
00054
00055
00056 PlexPixelSpotId::PlexPixelSpotId(PlexMuxBoxId muxbox,
00057 UInt_t tube, UInt_t pixel, UInt_t spot)
00058 : PlexMuxBoxId(muxbox)
00059 {
00060
00061
00062 SetTube(tube);
00063 SetPixel(pixel);
00064 SetSpot(spot);
00065 }
00066
00067
00068 PlexPixelSpotId::PlexPixelSpotId(const UInt_t encoded)
00069 : PlexMuxBoxId(encoded)
00070 {
00071
00072 }
00073
00074
00075 PlexPixelSpotId::~PlexPixelSpotId()
00076 {
00077
00078 }
00079
00080
00081 const char * PlexPixelSpotId::AsString(Option_t *option) const
00082 {
00083
00084
00085
00086
00087
00088
00089 const int nbuffers = 8;
00090 static char newstring[nbuffers][64];
00091 static int ibuffer = nbuffers;
00092 ibuffer = (ibuffer+1)%nbuffers;
00093
00094 string opt = option;
00095 bool extended = (opt.find("e") != string::npos);
00096 bool pixel_only = (opt.find("p") != string::npos);
00097 bool tube_only = (opt.find("t") != string::npos);
00098
00099 const char* pfmt = "%s-PIXEL-%1.1d-%2.2d";
00100 const char* tfmt = "%s-TUBE-%1.1d";
00101 const char* efmt = "%s-SPOT-%1.1d-%2.2d-%2.2d";
00102 if (extended) efmt = "%s-SPOT-tube %1.1d pixel %2.2d spot %2.2d";
00103
00104 const char* muxAsString = PlexMuxBoxId::AsString(option);
00105
00106 if (pixel_only) sprintf(newstring[ibuffer],pfmt,
00107 muxAsString,GetTube(),GetPixel());
00108 else if(tube_only) sprintf(newstring[ibuffer],tfmt,
00109 muxAsString,GetTube());
00110 else sprintf(newstring[ibuffer],efmt,
00111 muxAsString,GetTube(),GetPixel(),GetSpot());
00112
00113 return newstring[ibuffer];
00114 }
00115
00116
00117 void PlexPixelSpotId::Print(Option_t *option) const
00118 {
00119
00120
00121 printf("%s\n",AsString(option));
00122 }
00123
00124 #ifdef ENABLE_PIXELSPOTID_ISNULL
00125
00126 Bool_t PlexPixelSpotId::IsNull() const
00127 {
00128 MSG("Plex",Msg::kWarning)
00129 << "PlexPinDidoeId::IsNull() is obsolete -- use !IsValid()" << endl;
00130 return !IsValid();
00131 }
00132 #endif
00133
00134 #ifdef ENABLE_PIXELSPOTID_ENCODEMUXBOX
00135
00136 Int_t PlexPixelSpotId::EncodeMuxBox(Char_t eastwest, Char_t racklevel,
00137 Int_t rackbay, Int_t inrack)
00138 {
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165 int ew = 0;
00166 switch (eastwest) {
00167 case 'e':
00168 case 'E':
00169 ew = 1;
00170 break;
00171 case 'w':
00172 case 'W':
00173 ew = 2;
00174 break;
00175 }
00176
00177 int level = 3;
00178 switch (racklevel) {
00179 case 'l':
00180 case 'L':
00181 case 'b':
00182 case 'B':
00183 level = 0;
00184 break;
00185 case 'm':
00186 case 'M':
00187 level = 1;
00188 break;
00189 case 't':
00190 case 'T':
00191 case 'u':
00192 case 'U':
00193 level = 2;
00194 break;
00195 }
00196
00197 inrack &= 0x00000007;
00198 rackbay &= 0x0000001f;
00199
00200 const int shiftEW = 10;
00201 const int shiftLevel = 8;
00202 const int shiftBay = 3;
00203
00204 return ( ew << shiftEW ) |
00205 ( level << shiftLevel ) |
00206 ( rackbay << shiftBay ) |
00207 inrack;
00208 }
00209
00210
00211 void PlexPixelSpotId::DecodeMuxBox(Int_t muxbox,
00212 Char_t& eastwest, Char_t& racklevel,
00213 Int_t& rackbay, Int_t& inrack)
00214 {
00215
00216
00217 const int shiftEW = 10;
00218 const int shiftLevel = 8;
00219 const int shiftBay = 3;
00220
00221 inrack = muxbox & 0x0007;
00222 rackbay = (muxbox >> shiftBay) & 0x001f;
00223 Int_t level = (muxbox >> shiftLevel ) & 0x0003;
00224 Int_t ew = (muxbox >> shiftEW ) & 0x0003;
00225
00226 switch (level) {
00227 case 0: racklevel = 'L'; break;
00228 case 1: racklevel = 'M'; break;
00229 case 2: racklevel = 'U'; break;
00230 default: racklevel = '?'; break;
00231 }
00232
00233 switch (ew) {
00234 case 1: eastwest = 'E'; break;
00235 case 2: eastwest = 'W'; break;
00236 default: eastwest = '?'; break;
00237 }
00238 }
00239 #endif
00240
00241
00242 void PlexPixelSpotId::Streamer(TBuffer &R__b)
00243 {
00244
00245 if (R__b.IsReading()) {
00246 UInt_t R__s, R__c;
00247 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00248 if ( R__v > 2 ) {
00249 PlexPixelSpotId::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
00250 return;
00251 }
00252
00253 R__b >> fEncoded;
00254 if (R__v == 1) ConvertToVersion2();
00255
00256
00257
00258 }
00259 else {
00260
00261 PlexPixelSpotId::Class()->WriteBuffer(R__b, this);
00262 }
00263 }
00264
00265