00001
00002
00003
00004
00005
00006
00007
00008
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
00044
00045
00046
00047
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
00067
00068 SetStrip(strip);
00069 SetEnd(end);
00070 SetSubPart(subpart);
00071 }
00072
00073
00074 const char * PlexStripEndId::AsString(Option_t *option) const
00075 {
00076
00077
00078
00079
00080
00081
00082 const int nbuffers = 8;
00083 static char newstring[nbuffers][27];
00084
00085 static int ibuffer = nbuffers;
00086 ibuffer = (ibuffer+1)%nbuffers;
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
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
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
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
00123
00124
00125 return PlexPlaneId::AsString(option);
00126 break;
00127 default:
00128
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
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
00164
00165 return PlexScintMdlId::StripToScintMdl(*this,this->GetStrip());
00166 }
00167
00168
00169 UShort_t PlexStripEndId::GetStripInMdl() const
00170 {
00171
00172
00173
00174 return PlexScintMdlId::GetStripInMdl(*this,this->GetStrip());
00175 }
00176
00177
00178 UShort_t PlexStripEndId::GetMapperStripInMdl() const
00179 {
00180
00181
00182
00183
00184 return PlexScintMdlId::GetMapperStripInMdl(*this,this->GetStrip());
00185 }
00186
00187
00188 StripEnd::StripEnd_t PlexStripEndId::GetManifoldF1() const
00189 {
00190
00191
00192 switch (GetDetector()) {
00193 case Detector::kFar:
00194
00195 return ((GetStrip()<96) ? StripEnd::kWest : StripEnd::kEast );
00196 break;
00197 case Detector::kCalDet:
00198 {
00199
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
00208 return StripEnd::kWest;
00209 }
00210 }
00211
00212
00213
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
00223
00224
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
00236
00237
00238
00239
00240
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;
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
00267 if (end != StripEnd::kWest) {
00268 MAXMSG("Plex",Msg::kWarning,10)
00269 << "PlexStripEndId " << *this << " has non-West readout" << endl;
00270
00271 }
00272 }
00273 else {
00274
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
00292
00293 Int_t nStrips = 192;
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
00308 if ( key & 1 ) end = StripEnd::kWest;
00309 else end = StripEnd::kEast;
00310 key >>= 1;
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
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
00333
00334 return (GetEnd() == other.GetEnd() && IsSameStrip(other) );
00335
00336 }
00337
00338
00339 Bool_t PlexStripEndId::IsOppositeStripEnd(const PlexStripEndId &other) const
00340 {
00341
00342
00343
00344
00345 return (GetEnd() != other.GetEnd() && IsSameStrip(other) );
00346
00347 }
00348
00349
00350 Bool_t PlexStripEndId::IsValid() const
00351 {
00352
00353
00354
00355
00356 if ( ! PlexPlaneId::IsValid() ) return false;
00357 return ( GetStrip() < NumberOfStrips() );
00358 }
00359
00360
00361 void PlexStripEndId::Print(Option_t *option) const
00362 {
00363
00364
00365 printf("%s\n",AsString(option));
00366 }
00367
00368
00369