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

PlexMuxBoxId.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PlexMuxBoxId.cxx,v 1.7 2005/08/26 18:47:03 rhatcher Exp $
00003 //
00004 // PlexMuxBoxId encapsulates mux/tube/pixel/spot number encoding
00005 //
00006 // Author:  R. Hatcher 2001.06.26
00007 //
00009 
00010 #include "Plex/PlexMuxBoxId.h"
00011 
00012 #include <iostream>
00013 #include <iomanip>
00014 #include <string>
00015 #include <cassert>
00016 
00017 #include "MessageService/MsgService.h"
00018 CVSID("$Id: PlexMuxBoxId.cxx,v 1.7 2005/08/26 18:47:03 rhatcher Exp $");
00019 
00020 ClassImp(PlexMuxBoxId)
00021 
00022 //_____________________________________________________________________________
00023 ostream& operator<<(ostream& os, const PlexMuxBoxId& p)
00024 {
00025    os << p.AsString();
00026 
00027   return os;
00028 }
00029 
00030 //_____________________________________________________________________________
00031 PlexMuxBoxId::PlexMuxBoxId()
00032    : fEncoded(defaultMuxBoxId)
00033 {
00034    // Default ctor constructs meaningless value
00035 }
00036 
00037 //_____________________________________________________________________________
00038 PlexMuxBoxId::PlexMuxBoxId(Detector::Detector_t detector,
00039                            ElecType::Elec_t elec,
00040                            Char_t eastwest, Char_t racklevel,
00041                            UInt_t rackbay, UInt_t inrack)
00042    : fEncoded(defaultMuxBoxId)
00043 {
00044    // Normal ctor
00045 
00046    fEncoded =  maskPlexMuxVersion;
00047    SetDetector(detector);
00048    SetElecType(elec);
00049    SetEastWest(eastwest);
00050    SetRackLevel(racklevel);
00051    SetRackBay(rackbay);
00052    SetInRack(inrack);
00053 }
00054 
00055 //_____________________________________________________________________________
00056 PlexMuxBoxId::PlexMuxBoxId(const UInt_t encoded)
00057    : fEncoded(encoded)
00058 {
00059    // constructor from pre-encoded value
00060    ConvertToVersion2();
00061    //ju -bad for derived classes:  fEncoded &= zeroPlexMuxUnused;
00062 }
00063 
00064 //_____________________________________________________________________________
00065 PlexMuxBoxId::PlexMuxBoxId(const PlexMuxBoxId& muxid)
00066     : fEncoded(muxid.fEncoded)
00067     //ju -bad for derived classes : fEncoded(muxid.fEncoded&zeroPlexMuxUnused)
00068 {
00069     // copy ctor  (trim irrelevant bits)
00070 }
00071 
00072 //_____________________________________________________________________________
00073 PlexMuxBoxId& PlexMuxBoxId::operator=(const PlexMuxBoxId& muxid)
00074 {
00075     // assignment   (trim irrelevant bits)
00076     //ju -bad for derived classes: fEncoded = muxid.fEncoded&zeroPlexMuxUnused;
00077     fEncoded = muxid.fEncoded;
00078     return *this;
00079 }
00080 
00081 //_____________________________________________________________________________
00082 const char * PlexMuxBoxId::AsString(Option_t *option) const
00083 {
00084    // Return unpacked PlexMuxBoxId as a string
00085    // User should copy result because it points to a 
00086    // statically allocated string.
00087    // Internally uses a circular list of buffers to avoid problems
00088    // using AsString multiple times in a cout-like situation.
00089 
00090    const int nbuffers = 8;  // use a circular list of strings
00091    static char newstring[nbuffers][64];
00092    static int ibuffer = nbuffers;
00093    ibuffer = (ibuffer+1)%nbuffers;  // each time move to next buffer
00094 
00095    string opt = option;
00096    bool numeric_mux  = (opt.find("N") != string::npos);
00097    bool extended     = (opt.find("e") != string::npos);
00098 
00099    const char* efmt =
00100      "MUXB-%c%c-%c%c%2.2d:%2.2d";
00101    if (extended) efmt =
00102      "MUXB-%c%c-%c%c bay %2.2d: inrack %2.2d ";
00103 
00104    const char detc = Detector::AsString(GetDetector())[0];
00105    const char elec = ElecType::AsString(GetElecType())[0];
00106 
00107    if (numeric_mux) {
00108       // numeric mux box location
00109       sprintf(newstring[ibuffer],"SPOT-%c%c%3.3d",
00110               detc,elec,GetNumericMuxBox());
00111    } else {
00112       // unpacked MUX box location
00113       Char_t eastwest  = GetEastWest();
00114       Char_t racklevel = GetRackLevel();
00115       Int_t  rackbay  = GetRackBay();
00116       Int_t  inrack  = GetInRack();
00117       sprintf(newstring[ibuffer],efmt,
00118               detc,elec,
00119               eastwest,racklevel,rackbay,inrack);
00120    }
00121    
00122    return newstring[ibuffer];
00123 }
00124 
00125 //_____________________________________________________________________________
00126 void PlexMuxBoxId::Print(Option_t *option) const
00127 {
00128    // Print the (decoded) value
00129 
00130    printf("%s\n",AsString(option));
00131 }
00132 
00133 //_____________________________________________________________________________
00134 //inline 
00135 void PlexMuxBoxId::ConvertToVersion2() const
00136 { // VERY DANGEROUS!
00137   if (! (fEncoded&maskPlexMuxVersion) ) {
00138     if ( fEncoded != defaultMuxBoxId )
00139       MSG("Plex",Msg::kInfo)
00140         << "PlexMuxBoxId::ConvertToVersion2() required " << endl;
00141     // defeat "const"-ness
00142     PlexMuxBoxId *nonconst = const_cast<PlexMuxBoxId*>(this);
00143     nonconst->fEncoded = ConvertEncodedToVersion2(fEncoded); 
00144   }
00145 }
00146 
00147 //_____________________________________________________________________________
00148 UInt_t PlexMuxBoxId::ConvertEncodedToVersion2(UInt_t encoded)
00149 { 
00150   // VERY DANGEROUS!
00151   // conversion for bit layout for rearranged bits
00152   if (encoded & maskPlexMuxVersion) return encoded; // nothing to do
00153 
00154   // this funkiness should work for both old 
00155   // PlexPixelSpotId and PlexPinDiodeId layouts
00156 
00157 //    MSB                          LSB
00158 //     3         2         1         0
00159 //    10987654321098765432109876543210
00160 //    -dddeeWELLBBBBBIII-----iiiiiiiig  old pin diode
00161 //    -dddeeWELLBBBBBIIIttppppppppssss  old pixel spot id
00162 //                        ^- remove this bit
00163 //    77776666555544443333222211110000
00164 //                   v- insert this bit
00165 //    vdddeeWELLBBBBBIIII----iiiiiiiig  new pin diode
00166 //    vdddeeWELLBBBBBIIIIttpppppppssss  new pixel spot id
00167 
00168 //                               76543210
00169   UInt_t unchanged =  encoded & 0x7FFE07FF;
00170   UInt_t newmiddle = ((encoded & 0x0001F000) >> 1 );
00171 
00172   return maskPlexMuxVersion|unchanged|newmiddle;
00173 }
00174 
00175 //_____________________________________________________________________________

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