00001
00002
00003
00004
00005
00006
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
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
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
00060 ConvertToVersion2();
00061
00062 }
00063
00064
00065 PlexMuxBoxId::PlexMuxBoxId(const PlexMuxBoxId& muxid)
00066 : fEncoded(muxid.fEncoded)
00067
00068 {
00069
00070 }
00071
00072
00073 PlexMuxBoxId& PlexMuxBoxId::operator=(const PlexMuxBoxId& muxid)
00074 {
00075
00076
00077 fEncoded = muxid.fEncoded;
00078 return *this;
00079 }
00080
00081
00082 const char * PlexMuxBoxId::AsString(Option_t *option) const
00083 {
00084
00085
00086
00087
00088
00089
00090 const int nbuffers = 8;
00091 static char newstring[nbuffers][64];
00092 static int ibuffer = nbuffers;
00093 ibuffer = (ibuffer+1)%nbuffers;
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
00109 sprintf(newstring[ibuffer],"SPOT-%c%c%3.3d",
00110 detc,elec,GetNumericMuxBox());
00111 } else {
00112
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
00129
00130 printf("%s\n",AsString(option));
00131 }
00132
00133
00134
00135 void PlexMuxBoxId::ConvertToVersion2() const
00136 {
00137 if (! (fEncoded&maskPlexMuxVersion) ) {
00138 if ( fEncoded != defaultMuxBoxId )
00139 MSG("Plex",Msg::kInfo)
00140 << "PlexMuxBoxId::ConvertToVersion2() required " << endl;
00141
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
00151
00152 if (encoded & maskPlexMuxVersion) return encoded;
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 UInt_t unchanged = encoded & 0x7FFE07FF;
00170 UInt_t newmiddle = ((encoded & 0x0001F000) >> 1 );
00171
00172 return maskPlexMuxVersion|unchanged|newmiddle;
00173 }
00174
00175