Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PlexPixelSpotId.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PlexPixelSpotId.cxx,v 1.20 2005/08/26 18:47:03 rhatcher Exp $
00003 //
00004 // PlexPixelSpotId encapsulates mux/tube/pixel/spot number encoding
00005 //
00006 // Author:  R. Hatcher 2001.06.26
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 //CVSID("$Id: PlexPixelSpotId.cxx,v 1.20 2005/08/26 18:47:03 rhatcher Exp $");
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    // Default ctor constructs meaningless value
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    // Normal ctor
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    // Normal ctor
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    // constructor from pre-encoded value
00072 }
00073 
00074 //_____________________________________________________________________________
00075 PlexPixelSpotId::~PlexPixelSpotId()
00076 {
00077    // delete all the owned sub-objects
00078 }
00079 
00080 //_____________________________________________________________________________
00081 const char * PlexPixelSpotId::AsString(Option_t *option) const
00082 {
00083    // Return unpacked PlexPixelSpotId as a string
00084    // User should copy result because it points to a 
00085    // statically allocated string.
00086    // Internally uses a circular list of buffers to avoid problems
00087    // using AsString multiple times in a cout-like situation.
00088 
00089    const int nbuffers = 8;  // use a circular list of strings
00090    static char newstring[nbuffers][64];
00091    static int ibuffer = nbuffers;
00092    ibuffer = (ibuffer+1)%nbuffers;  // each time move to next buffer
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    // Print the (decoded) value
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    // !!! PlexPixelSpotId::EncodeMuxBox and PlexPinDiodeId::EncodeMuxBox
00140    // !!! must be kept in synch.
00141    //
00142    // encode logical muxbox id into 12 bits
00143    // eastwest  := side on which rack is located
00144    //              east: 'e', 'E'
00145    //              west: 'w', 'W'
00146    // racklevel := level on which rack is located
00147    //              top/upper:     't', 'T', 'u', 'U'
00148    //              bottom/lower:  'b', 'B', 'l', 'L'
00149    // rackbay   := rack within eastwest/racklevel
00150    //              far:   1 - 16
00151    //              near:  1 - 14
00152    // inrack    := placement within the rack  0:7
00153 
00154    //    MSB                          LSB
00155    //     3         2         1         0
00156    //    10987654321098765432109876543210
00157    //                        wellbbbbbiii
00158    //                  ddddeemmmmmmmmmmmm
00159    //
00160    //    we : 01b=east,  10b=west
00161    //    ll : 00b=lower, 01b=middle, 10b=upper, 11b=??
00162    // bbbbb : bay
00163    //   iii : in rack
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    // reverse EncodeMuxBox
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   // Stream a PlexPixelSpotId
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     // Process versions pre-automatic schema evolution
00253     R__b >> fEncoded;
00254     if (R__v == 1) ConvertToVersion2();
00255     // Check byte count may not work for version 2 because base class
00256     // streamer was bypassed
00257     // R__b.CheckByteCount(R__s, R__c, PlexPixelSpotId::IsA());
00258   }
00259   else {
00260     // versions 3 & up will enjoy automatic schema evolution
00261     PlexPixelSpotId::Class()->WriteBuffer(R__b, this);
00262   }
00263 }
00264 
00265 //_____________________________________________________________________________

Generated on Fri Mar 28 15:37:41 2008 for loon by  doxygen 1.3.9.1