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

PlexPinDiodeId.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PlexPinDiodeId.cxx,v 1.14 2005/08/26 18:47:03 rhatcher Exp $
00003 //
00004 // PlexPinDiodeId encapsulates mux/inbox/gain number encoding
00005 //
00006 // Author:  R. Hatcher 2001.06.26
00007 //
00009 
00010 #include "Plex/PlexPinDiodeId.h"
00011 #include "Plex/PlexPixelSpotId.h"
00012 
00013 #include "TBuffer.h"
00014 #include "TClass.h"
00015 
00016 #include <iostream>
00017 #include <iomanip>
00018 #include <string>
00019 
00020 #include <cassert>
00021 
00022 #include "MessageService/MsgService.h"
00023 //CVSID("$Id: PlexPinDiodeId.cxx,v 1.14 2005/08/26 18:47:03 rhatcher Exp $");
00024 
00025 ClassImp(PlexPinDiodeId)
00026 
00027 //_____________________________________________________________________________
00028 ostream& operator<<(ostream& os, const PlexPinDiodeId& p)
00029 {
00030    os << p.AsString();
00031 
00032   return os;
00033 }
00034 
00035 //_____________________________________________________________________________
00036 PlexPinDiodeId::PlexPinDiodeId()
00037    : PlexMuxBoxId()
00038 {
00039    // Default ctor constructs meaningless value
00040 }
00041 
00042 //_____________________________________________________________________________
00043 PlexPinDiodeId::PlexPinDiodeId(Detector::Detector_t detector,
00044                                ElecType::Elec_t elec,
00045                                Char_t eastwest, Char_t racklevel,
00046                                UInt_t rackbay, UInt_t inrack,
00047                                UInt_t inbox, UInt_t gain)
00048   : PlexMuxBoxId(detector,elec,eastwest,racklevel,rackbay,inrack)
00049 {
00050    // Normal ctor
00051 
00052    SetInBox(inbox);
00053    SetGain(gain);
00054 }
00055 
00056 //_____________________________________________________________________________
00057 PlexPinDiodeId::PlexPinDiodeId(PlexMuxBoxId muxbox,
00058                                UInt_t inbox, UInt_t gain)
00059   : PlexMuxBoxId(muxbox)
00060 {
00061    // Normal ctor
00062 
00063    SetInBox(inbox);
00064    SetGain(gain);
00065 }
00066 
00067 //_____________________________________________________________________________
00068 PlexPinDiodeId::PlexPinDiodeId(const UInt_t encoded)
00069    : PlexMuxBoxId(encoded)
00070 {
00071    // constructor from pre-encoded value
00072 }
00073 
00074 //_____________________________________________________________________________
00075 PlexPinDiodeId::~PlexPinDiodeId()
00076 {
00077    // delete all the owned sub-objects
00078 }
00079 
00080 //_____________________________________________________________________________
00081 const char * PlexPinDiodeId::AsString(Option_t *option) const
00082 {
00083    // Return unpacked PlexPinDiodeId 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 
00097    const char*   efmt = "%s-PIN-%3.3d%c";
00098    if (extended) efmt = "%s-PIN-diode %3.3d gain %c";
00099 
00100    const char* muxAsString = PlexMuxBoxId::AsString(option);
00101    sprintf(newstring[ibuffer],efmt,muxAsString,GetInBox(),(IsLowGain()?'L':'H'));
00102    
00103    return newstring[ibuffer];
00104 }
00105 
00106 //_____________________________________________________________________________
00107 void PlexPinDiodeId::Print(Option_t *option) const
00108 {
00109    // Print the (decoded) value
00110 
00111    printf("%s\n",AsString(option));
00112 }
00113 
00114 //_____________________________________________________________________________
00115 void PlexPinDiodeId::Streamer(TBuffer &R__b)
00116 {
00117   // Stream a PlexPinDiodeId
00118   if (R__b.IsReading()) {
00119     UInt_t R__s, R__c;
00120     Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
00121     if ( R__v > 2 ) {
00122       PlexPinDiodeId::Class()->ReadBuffer(R__b, this, R__v, R__s, R__c);
00123       return;
00124     }
00125     // Process versions pre-automatic schema evolution
00126     R__b >> fEncoded;
00127     if (R__v == 1) ConvertToVersion2();
00128     // Check byte count likely won't work for version 2 because base class
00129     // streamer was bypassed
00130     // R__b.CheckByteCount(R__s, R__c, PlexPinDiode::IsA());
00131   }
00132   else {
00133     // versions 3 & up will enjoy automatic schema evolution
00134     PlexPinDiodeId::Class()->WriteBuffer(R__b, this);
00135   }
00136 }
00137 
00138 #ifdef ENABLE_PINDIODEID_ISNULL
00139 //_____________________________________________________________________________
00140 Bool_t PlexPinDiodeId::IsNull() const
00141 {
00142    MSG("Plex",Msg::kWarning) 
00143      << "PlexPinDiodeId::IsNull() is obsolete -- use !IsValid()" << endl;
00144    return !IsValid();
00145 }
00146 #endif
00147 
00148 #ifdef ENABLE_PINDIODEID_ENCODEMUXBOX
00149 //_____________________________________________________________________________
00150 Int_t PlexPinDiodeId::EncodeMuxBox(Char_t eastwest, Char_t racklevel,
00151                                     Int_t rackbay, Int_t inrack)
00152 {
00153    // !!! PlexPixelSpotId::EncodeMuxBox and PlexPinDiodeId::EncodeMuxBox
00154    // !!! must be kept in synch.
00155    //
00156    // encode logical muxbox id into 12 bits
00157 
00158    return PlexPixelSpotId::EncodeMuxBox(eastwest,racklevel,rackbay,inrack);
00159 }
00160 
00161 //_____________________________________________________________________________
00162 void PlexPinDiodeId::DecodeMuxBox(Int_t muxbox, Char_t& eastwest, 
00163                                   Char_t& racklevel, Int_t& rackbay, 
00164                                   Int_t& inrack) 
00165 {
00166    // !!! PlexPixelSpotId::EncodeMuxBox and PlexPinDiodeId::EncodeMuxBox
00167    // !!! must be kept in synch.
00168    //
00169    // encode logical muxbox id into 12 bits
00170 
00171    PlexPixelSpotId::DecodeMuxBox(muxbox,eastwest,racklevel,rackbay,inrack);
00172 }
00173 #endif
00174 
00175 //_____________________________________________________________________________

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