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

PlexStripEndId.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PlexStripEndId.cxx,v 1.35 2005/08/26 18:47:04 rhatcher Exp $
00003 //
00004 // PlexStripEndId
00005 //
00006 // PlexStripEndId encapsulates strip end encoding
00007 //
00008 // Author:  R. Hatcher 2000.05.03
00009 //
00011 
00012 #include "Plex/PlexStripEndId.h"
00013 
00014 #include <iostream>
00015 #include <iomanip>
00016 #include <string>
00017 
00018 #ifndef CASSERT
00019 #include <cassert>
00020 #define CASSERT
00021 #endif
00022 
00023 #include "MessageService/MsgService.h"
00024 CVSID("$Id: PlexStripEndId.cxx,v 1.35 2005/08/26 18:47:04 rhatcher Exp $");
00025 
00026 ClassImp(PlexStripEndId)
00027 
00028 //_____________________________________________________________________________
00029 std::ostream& operator<<(std::ostream& os, const PlexStripEndId& p)
00030 {
00031    os << p.AsString();
00032 
00033   return os;
00034 }
00035 
00036 //_____________________________________________________________________________
00037 PlexStripEndId::PlexStripEndId(PlexPlaneId plnid,
00038                                UInt_t strip,
00039                                StripEnd::StripEnd_t end,
00040                                StripEnd::StripEnd_t subpart)
00041    : PlexPlaneId(plnid)
00042 {
00043    // Normal ctor from PlaneId + extras
00044 
00045    // ensure that it isn't tagged as "steel" even if plnid was
00046    // but don't do this for veto shield as we use steel bit
00047    // in that case for additional PlaneCoverage enums
00048    if (!IsVetoShield()) SetIsSteel(kFALSE);
00049 
00050    SetStrip(strip);
00051    SetEnd(end);
00052    SetSubPart(subpart);
00053 
00054 }
00055 
00056 //_____________________________________________________________________________
00057 PlexStripEndId::PlexStripEndId(Detector::Detector_t detector,
00058                                UInt_t plane, UInt_t strip,
00059                                StripEnd::StripEnd_t end,
00060                                StripEnd::StripEnd_t subpart,
00061                                PlaneView::PlaneView_t view,
00062                                PlaneCoverage::PlaneCoverage_t coverage)
00063 
00064    : PlexPlaneId(detector,plane,kFALSE,view,coverage)
00065 {
00066    // Normal ctor from all components
00067 
00068    SetStrip(strip);
00069    SetEnd(end);
00070    SetSubPart(subpart);
00071 }
00072 
00073 //____________________________________________________________________________
00074 const char * PlexStripEndId::AsString(Option_t *option) const
00075 {
00076    // Return unpacked StripEndId as a string
00077    // User should copy result because it points to a 
00078    // statically allocated string.
00079    // Internally uses a circular list of buffers to avoid problems
00080    // using AsString multiple times in a cout-like situation.
00081 
00082    const int nbuffers = 8;   // use a circular list of strings
00083    static char newstring[nbuffers][27]; // = "|123456789|1234 VX|123|SE|";
00084       //                                      12345678901234567890123456
00085    static int  ibuffer = nbuffers;
00086    ibuffer = (ibuffer+1)%nbuffers;  // each time move to next buffer
00087 
00088    Detector::Detector_t           det   = GetDetector();
00089    PlaneView::PlaneView_t         view  = GetPlaneView();
00090    PlaneCoverage::PlaneCoverage_t cover = GetPlaneCoverage();
00091 
00092    switch (option[0]) {
00093    case 's':
00094       // only the part the defines the "shape"
00095       sprintf(newstring[ibuffer],"%c%c%c%3.3d",
00096               Detector::AsString(det)[0],
00097               PlaneView::AsString(view)[0],
00098               PlaneCoverage::AsString(cover)[0],
00099               GetStrip());
00100       break;
00101    case 'c':
00102       // compact rendering identifying whole strip info (but not end info)
00103       sprintf(newstring[ibuffer],"%c%4.4d%c%c%3.3d",
00104               Detector::AsString(det)[0],
00105               GetPlane(),
00106               PlaneView::AsString(view)[0],
00107               PlaneCoverage::AsString(cover)[0],
00108               GetStrip());
00109       break;
00110    case 'C':
00111       // compact rendering identifying whole strip info & end info
00112      sprintf(newstring[ibuffer],"%c%4.4d%c%c%3.3d%c",
00113              Detector::AsString(det)[0],
00114              GetPlane(),
00115              PlaneView::AsString(view)[0],
00116              PlaneCoverage::AsString(cover)[0],
00117              GetStrip(),
00118              StripEnd::AsString(GetEnd(),det,view)[0]);
00119      break;
00120    case 'p':
00121    case 'b':
00122       // compact rendering identifying only the plane info
00123       // p is for plane including one char {P,A} := {passive, active}
00124       // b is for "box" containing steel+scint (or steel alone if no active)
00125       return PlexPlaneId::AsString(option);
00126       break;
00127    default:
00128       // full and complete info
00129       sprintf(newstring[ibuffer],"[%6.6s|%4d %c%c|%3d|%c%c]",
00130               Detector::AsString(det),
00131               GetPlane(),
00132               PlaneView::AsString(view)[0],
00133               PlaneCoverage::AsString(cover)[0],
00134               GetStrip(),
00135               StripEnd::AsString(GetSubPart())[0],
00136               StripEnd::AsString(GetEnd(),det,view)[0]);
00137       break;
00138    }
00139    
00140    return newstring[ibuffer];
00141 }
00142 
00143 //_____________________________________________________________________________
00144 PlexStripEndId PlexStripEndId::GetOppositeSEId() const
00145 {
00146    // Return an Id for the opposite end
00147 
00148    PlexStripEndId other(fEncoded);
00149    StripEnd::StripEnd_t end = GetEnd();
00150    switch (end) {
00151    case StripEnd::kNegative: end = StripEnd::kPositive; break;
00152    case StripEnd::kPositive: end = StripEnd::kNegative; break;
00153    default: break;
00154    }
00155    other.SetEnd(end);
00156    return other;
00157    
00158 }
00159 
00160 //_____________________________________________________________________________
00161 PlexScintMdlId PlexStripEndId::GetScintMdlId() const
00162 {
00163    // Return an Id for the scint module this strip is in
00164 
00165    return PlexScintMdlId::StripToScintMdl(*this,this->GetStrip());
00166 }
00167 
00168 //_____________________________________________________________________________
00169 UShort_t PlexStripEndId::GetStripInMdl() const
00170 {
00171    // Return an strip # within a module 
00172    // using offline convention of [0,nstripInMdl)
00173 
00174    return PlexScintMdlId::GetStripInMdl(*this,this->GetStrip());
00175 }
00176 
00177 //_____________________________________________________________________________
00178 UShort_t PlexStripEndId::GetMapperStripInMdl() const
00179 {
00180    // Return an strip # within a module using construction based notation
00181    // starts w/ 1 .. flip flops w/ increasing 'tpos' depending on
00182    // installation orientation
00183 
00184    return PlexScintMdlId::GetMapperStripInMdl(*this,this->GetStrip());
00185 }
00186 
00187 //_____________________________________________________________________________
00188 StripEnd::StripEnd_t PlexStripEndId::GetManifoldF1() const
00189 {
00190    // Return the side with the "F1" manifold (construction notation)
00191 
00192    switch (GetDetector()) {
00193    case Detector::kFar:
00194      // lower half has F1 on West side, upper on the East
00195      return ((GetStrip()<96) ? StripEnd::kWest : StripEnd::kEast );
00196      break;
00197    case Detector::kCalDet:
00198      {
00199        // ???? this might not be right!!!
00200        MAXMSG("Plex",Msg::kWarning,10)
00201          << "GetManifoldF1 not verified for CalDet!!" << endl;
00202        return ((GetPlaneView()==PlaneView::kU) ? 
00203                StripEnd::kDown : StripEnd::kWest );
00204      }
00205      break;
00206    default:
00207      // near detector only has west side
00208      return StripEnd::kWest;
00209    }
00210 }
00211 
00212 //_____________________________________________________________________________
00213 //inline
00214 Int_t PlexStripEndId::Build18BitPlnStripKey() const
00215 {
00216    return ( GetPlane() << bitsPlexIdStrip ) | GetStrip();
00217 }
00218 
00219 //_____________________________________________________________________________
00220 PlexStripEndId PlexStripEndId::Unbuild18BitPlnStripKey(Detector::Detector_t det, Int_t key)
00221 {
00222    // recover true id object from hashed down version
00223    // needs detector info that was lost in compactification
00224    // obviously can't recover end info that was lost
00225 
00226    const UInt_t maskLower = ( maskPlexIdStrip >> shftPlexIdStrip );
00227    UInt_t strip = key & maskLower;
00228    UInt_t plane = key >> bitsPlexIdStrip;
00229    return PlexStripEndId(det,plane,strip);
00230 }
00231 
00232 //_____________________________________________________________________________
00233 Int_t PlexStripEndId::BuildPlnStripEndKey() const
00234 {
00235    // compactified plane,strip,end (assuming only east/west ends)
00236    // packed tightly, not simple bit shifts
00237 
00238    // this isn't quite as tight as it could possibly be for the
00239    // near detector as it doesn't worry about partial vs. full planes
00240    // and has gaps for empty spectrometer planes 
00241 
00242    Int_t plane = GetPlane();
00243    Int_t strip = GetStrip();
00244    Detector::Detector_t det = GetDetector();
00245    StripEnd::StripEnd_t end = GetEnd();
00246 
00247    Int_t nStrips = 192;  // need some default
00248    switch (det) {
00249    case Detector::kNear:   nStrips =  96; break;
00250    case Detector::kFar:    nStrips = 192; break;
00251    case Detector::kCalDet: nStrips =  24; break;
00252    default:
00253       MAXMSG("Plex",Msg::kWarning,10)
00254          << "PlexStripEndId " << *this << " is not Near/Far/CalDet" << endl;
00255    }
00256 
00257    if (strip>=nStrips) {
00258      MAXMSG("Plex",Msg::kWarning,10)
00259        << "PlexStripEndId " << *this 
00260        << " exceeds expected nStrips " << nStrips << endl;
00261    }
00262 
00263    Int_t hvalue = plane*nStrips + strip;
00264 
00265    if (det == Detector::kNear) {
00266       // near detector only has west readout
00267      if (end != StripEnd::kWest) {
00268        MAXMSG("Plex",Msg::kWarning,10)
00269          << "PlexStripEndId " << *this << " has non-West readout" << endl;
00270      // but do nothing
00271      }
00272    }
00273    else {
00274       // make room for end bit
00275       hvalue <<= 1;
00276       switch (GetEnd()) {
00277       case StripEnd::kEast: hvalue += 0; break;
00278       case StripEnd::kWest: hvalue += 1; break;
00279       default:
00280          MAXMSG("Plex",Msg::kWarning,10)
00281             << "PlexStripEndId " << *this << " is not East/West" << endl;
00282       }
00283    }
00284 
00285    return hvalue;
00286 }
00287 
00288 //_____________________________________________________________________________
00289 PlexStripEndId PlexStripEndId::UnbuildPlnStripEndKey(Detector::Detector_t det, Int_t key)
00290 {
00291    // recover true id object from hashed down version
00292    // needs detector info that was lost in compactification
00293    Int_t nStrips = 192;  // need some default
00294    switch (det) {
00295    case Detector::kNear:   nStrips =  96; break;
00296    case Detector::kFar:    nStrips = 192; break;
00297    case Detector::kCalDet: nStrips =  24; break;
00298    default:
00299       MAXMSG("Plex",Msg::kWarning,10)
00300          << "PlexStripEndId " << Detector::AsString(det) 
00301          << "(" << (int)det << ")"
00302          << " is not Near/Far/CalDet" << endl;
00303    }
00304    
00305    StripEnd::StripEnd_t end = StripEnd::kWest;
00306    if ( Detector::kNear != det ) {
00307      // NearDet has only west readout so it isn't part of the hash
00308      if ( key & 1 ) end = StripEnd::kWest;
00309      else           end = StripEnd::kEast;
00310      key >>= 1;  // for non-NearDet we can now remove bit
00311    }
00312    Int_t plane = key / nStrips;
00313    Int_t strip = key - (plane*nStrips);
00314 
00315    return PlexStripEndId(det,plane,strip,end);
00316 }
00317 
00318 //_____________________________________________________________________________
00319 Bool_t PlexStripEndId::IsSameStrip(const PlexStripEndId &other) const
00320 {
00321    // Determine if "this" and "other" are the same strip
00322 
00323    return (GetDetector() == other.GetDetector() &&
00324            GetPlane()    == other.GetPlane()    &&
00325            GetStrip()    == other.GetStrip()       );
00326    
00327 }
00328 
00329 //_____________________________________________________________________________
00330 Bool_t PlexStripEndId::IsSameStripEnd(const PlexStripEndId &other) const
00331 {
00332    // Determine if "this" and "other" are the same strip and end
00333 
00334    return (GetEnd() == other.GetEnd() && IsSameStrip(other) );
00335    
00336 }
00337 
00338 //_____________________________________________________________________________
00339 Bool_t PlexStripEndId::IsOppositeStripEnd(const PlexStripEndId &other) const
00340 {
00341    // Determine if "this" and "other" are the same strip
00342    // but opposite ends.
00343    // !!!! Assumes one can test this by != on ends
00344 
00345    return (GetEnd() != other.GetEnd() && IsSameStrip(other) );
00346    
00347 }
00348 
00349 //_____________________________________________________________________________
00350 Bool_t PlexStripEndId::IsValid() const
00351 { 
00352   // test if plane is valid
00353   //   ie. # = all bits on as signal of invalid value
00354   //       also fail if IsSteel=false but PlaneCoverage=NoActive
00355   //  then test if the strip # makes sense (hard code some #'s in)
00356   if ( ! PlexPlaneId::IsValid() ) return false;
00357   return ( GetStrip() < NumberOfStrips() );
00358 }
00359 
00360 //_____________________________________________________________________________
00361 void PlexStripEndId::Print(Option_t *option) const
00362 {
00363    // Print the (decoded) value
00364 
00365    printf("%s\n",AsString(option));
00366 }
00367 
00368 //_____________________________________________________________________________
00369 

Generated on Sat Nov 21 22:47:21 2009 for loon by  doxygen 1.3.9.1