00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012 #include "Plex/PlexVetoShieldHack.h"
00013
00014 #include <iostream>
00015 #include <iomanip>
00016 #include <string>
00017
00018 #include <cassert>
00019
00020 #include "DatabaseInterface/DbiResultPtr.h"
00021 #include "Plex/PlexVetoShieldMuxToMdl.h"
00022 #include "MessageService/MsgService.h"
00023 CVSID("$Id: PlexVetoShieldHack.cxx,v 1.10 2005/08/26 18:47:04 rhatcher Exp $");
00024
00025
00026 VldContext PlexVetoShieldHack::fgDefaultContext =
00027 VldContext(Detector::kFar,SimFlag::kData,VldTimeStamp());
00028
00029 ClassImp(PlexVetoShieldHack)
00030
00031
00032 VldContext PlexVetoShieldHack::SetDefaultContext(const VldContext& vldc)
00033 {
00034
00035
00036 MSG("Plex",Msg::kDebug)
00037 << "PlexVetoShieldHack::SetDefaultContext " << vldc << endl;
00038
00039 VldContext old = fgDefaultContext;
00040 fgDefaultContext = vldc;
00041 return old;
00042 }
00043
00044
00045 PlexStripEndId PlexVetoShieldHack::RenumberMuxToMdl(const VldContext& vldc,
00046 PlexStripEndId& seid)
00047 {
00048
00049 if (!seid.IsVetoShield()) return seid;
00050
00051 unsigned int mux_pln = seid.GetPlane();
00052
00053 if ( PlexVetoShieldHack::IsMdlPlnVetoShield(mux_pln) ) {
00054
00055 return seid;
00056 }
00057 else if ( ! PlexVetoShieldHack::IsMuxPlnVetoShield(mux_pln) ) {
00058
00059 MSG("Plex",Msg::kWarning)
00060 << " MuxToMdl unknown plane= " << mux_pln << endl;
00061 return seid;
00062 }
00063
00064 unsigned int mux_strip = seid.GetStrip();
00065 unsigned int mux_mdl = mux_strip/20;
00066
00067 const PlexVetoShieldMuxToMdl *the_muxtomdl =
00068 LookForMuxMdl(vldc,mux_pln,mux_mdl);
00069 if (!the_muxtomdl) {
00070 MSG("Plex",Msg::kInfo)
00071 << "RenumberMuxToMdl no match for Mux #'ed plane= "
00072 << seid.GetPlane() << " strip=" << setw(3) << seid.GetStrip() << endl;
00073 return seid;
00074 }
00075
00076 unsigned int strip_in_mdl = mux_strip%20;
00077
00078 if (the_muxtomdl->GetCountDir() < 0) strip_in_mdl = 19 - strip_in_mdl;
00079
00080 PlexStripEndId new_seid(the_muxtomdl->GetSingleMdlPlaneId(),
00081 strip_in_mdl,
00082 seid.GetEnd(),seid.GetSubPart());
00083 return new_seid;
00084 }
00085
00086
00087 PlexStripEndId PlexVetoShieldHack::RenumberMdlToMux(const VldContext& vldc,
00088 PlexStripEndId& seid)
00089 {
00090
00091 if (!seid.IsVetoShield()) return seid;
00092
00093 unsigned int mdl_pln = seid.GetPlane();
00094
00095 if ( PlexVetoShieldHack::IsMuxPlnVetoShield(mdl_pln) ) {
00096
00097 return seid;
00098 }
00099 else if ( ! PlexVetoShieldHack::IsMdlPlnVetoShield(mdl_pln) ) {
00100
00101 MSG("Plex",Msg::kWarning)
00102 << " MdlToMux unknown plane= " << mdl_pln << endl;
00103 return seid;
00104 }
00105
00106 const PlexVetoShieldMuxToMdl *the_muxtomdl = LookForSingleMdl(vldc,mdl_pln);
00107 if (!the_muxtomdl) {
00108 MSG("Plex",Msg::kInfo)
00109 << "RenumberMdlToMux no match for Mdl #'ed plane= "
00110 << seid.GetPlane() << " strip=" << setw(3) << seid.GetStrip() << endl;
00111 return seid;
00112 }
00113
00114 unsigned int mdl_strip = seid.GetStrip();
00115 unsigned int muxmdl = the_muxtomdl->GetMuxMdl();
00116 unsigned int mux_strip =
00117 (the_muxtomdl->GetCountDir() > 0) ?
00118 20*(muxmdl+0) + mdl_strip + 0:
00119 20*(muxmdl+1) - mdl_strip - 1;
00120
00121 PlexStripEndId new_seid(the_muxtomdl->GetMuxPlaneId(),
00122 mux_strip,
00123 seid.GetEnd(),seid.GetSubPart());
00124 return new_seid;
00125 }
00126
00127
00128 PlexScintMdlId PlexVetoShieldHack::RenumberMuxToMdl(const VldContext& vldc,
00129 PlexScintMdlId& mdlid)
00130 {
00131 if (!mdlid.IsVetoShield()) return mdlid;
00132
00133 unsigned int mux_pln = mdlid.GetPlane();
00134
00135 if ( PlexVetoShieldHack::IsMdlPlnVetoShield(mux_pln) ) {
00136
00137 return mdlid;
00138 }
00139 else if ( ! PlexVetoShieldHack::IsMuxPlnVetoShield(mux_pln) ) {
00140
00141 MSG("Plex",Msg::kWarning)
00142 << " MuxToMdl unknown plane= " << mux_pln << endl;
00143 return mdlid;
00144 }
00145
00146 unsigned int mux_mdl = mdlid.GetModule();
00147
00148 const PlexVetoShieldMuxToMdl *the_muxtomdl =
00149 LookForMuxMdl(vldc,mux_pln,mux_mdl);
00150 if (!the_muxtomdl) {
00151 MSG("Plex",Msg::kInfo)
00152 << "RenumberMuxToMdl no match for Mux #'ed plane= " << mdlid.GetPlane()
00153 << " module=" << mdlid.GetModule() << endl;
00154 return mdlid;
00155 }
00156
00157 return the_muxtomdl->GetSingleMdlScintMdlId();
00158 }
00159
00160
00161 PlexScintMdlId PlexVetoShieldHack::RenumberMdlToMux(const VldContext& vldc,
00162 PlexScintMdlId& mdlid)
00163 {
00164 if (!mdlid.IsVetoShield()) return mdlid;
00165
00166 unsigned int mdl_pln = mdlid.GetPlane();
00167
00168 if ( PlexVetoShieldHack::IsMuxPlnVetoShield(mdl_pln) ) {
00169
00170 return mdlid;
00171 }
00172 else if ( ! PlexVetoShieldHack::IsMdlPlnVetoShield(mdl_pln) ) {
00173
00174 MSG("Plex",Msg::kWarning)
00175 << " MdlToMux unknown plane= " << mdl_pln << endl;
00176 return mdlid;
00177 }
00178
00179 unsigned int mdl_mdl = mdlid.GetModule();
00180
00181 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00182 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00183 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00184 if (the_muxtomdl->GetMdlPln() == mdl_pln) {
00185
00186 const unsigned int kMdlMdl = 0;
00187 if (mdl_mdl != kMdlMdl) {
00188 MSG("Plex",Msg::kInfo)
00189 << "RenumberMdlToMux no match for Mdl #'ed plane= "
00190 << mdlid.GetPlane()
00191 << " module=" << mdlid.GetModule()
00192 << " > 0 " << endl;
00193 }
00194
00195 return the_muxtomdl->GetMuxScintMdlId();
00196 }
00197 }
00198 MSG("Plex",Msg::kInfo)
00199 << "RenumberMdlToMux no match for Mdl #'ed plane= " << mdlid.GetPlane()
00200 << " module=" << mdlid.GetModule() << endl;
00201 return mdlid;
00202 }
00203
00204
00205 PlexPlaneId PlexVetoShieldHack::RenumberMuxToMdl(const VldContext& vldc,
00206 PlexPlaneId& plnid)
00207 {
00208 if (!plnid.IsVetoShield()) return plnid;
00209
00210 unsigned int mux_pln = plnid.GetPlane();
00211
00212 if ( PlexVetoShieldHack::IsMdlPlnVetoShield(mux_pln) ) {
00213
00214 return plnid;
00215 }
00216 else if ( ! PlexVetoShieldHack::IsMuxPlnVetoShield(mux_pln) ) {
00217
00218 MSG("Plex",Msg::kWarning)
00219 << " MuxToMdl unknown plane= " << mux_pln << endl;
00220 return plnid;
00221 }
00222
00223
00224 unsigned int mux_mdl = 0;
00225
00226 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00227 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00228 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00229 if (the_muxtomdl->GetMuxPln() == mux_pln &&
00230 the_muxtomdl->GetMuxMdl() == mux_mdl ) {
00231
00232 MSG("Plex",Msg::kInfo)
00233 << " no unique match for mapping MuxToMdl for plane "
00234 << mux_pln << endl;
00235 return the_muxtomdl->GetSingleMdlPlaneId();
00236 }
00237 }
00238 MSG("Plex",Msg::kInfo)
00239 << "RenumberMuxToMdl no match for Mux #'ed plane= "
00240 << plnid.GetPlane() << endl;
00241 return plnid;
00242
00243 }
00244
00245
00246 PlexPlaneId PlexVetoShieldHack::RenumberMdlToMux(const VldContext& vldc,
00247 PlexPlaneId& plnid)
00248 {
00249 if (!plnid.IsVetoShield()) return plnid;
00250
00251 unsigned int mdl_pln = plnid.GetPlane();
00252
00253 if ( PlexVetoShieldHack::IsMuxPlnVetoShield(mdl_pln) ) {
00254
00255 return plnid;
00256 }
00257 else if ( ! PlexVetoShieldHack::IsMdlPlnVetoShield(mdl_pln) ) {
00258
00259 MSG("Plex",Msg::kWarning)
00260 << " MdlToMux unknown plane= " << mdl_pln << endl;
00261 return plnid;
00262 }
00263
00264 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00265 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00266 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00267 if (the_muxtomdl->GetMdlPln() == mdl_pln) {
00268
00269 return the_muxtomdl->GetMuxPlaneId();
00270 }
00271 }
00272 MSG("Plex",Msg::kInfo)
00273 << "RenumberMdlToMux no match for Mdl #'ed plane= "
00274 << plnid.GetPlane() << endl;
00275 return plnid;
00276 }
00277
00278
00279
00280 Bool_t PlexVetoShieldHack::IsMuxPlnVetoShield(UInt_t plane)
00281 {
00282
00283 return ( ( 513 <= plane ) && ( plane <= 524 ) );
00284 }
00285
00286 Bool_t PlexVetoShieldHack::IsMdlPlnVetoShield(UInt_t plane)
00287 {
00288
00289
00290
00291
00292 return ( ( 528 <= plane ) && ( plane <= 575 ) ) ||
00293 ( ( 576 <= plane ) && ( plane <= 639 ) ) ||
00294 ( ( 656 <= plane ) && ( plane <= 703 ) ) ||
00295 ( ( 720 <= plane ) && ( plane <= 767 ) ) ;
00296 }
00297
00298
00299 VldContext PlexVetoShieldHack::ConvertRangeToContext(const VldRange& vldr)
00300 {
00301 Detector::Detector_t detector =
00302 (Detector::Detector_t)(vldr.GetDetectorMask());
00303 SimFlag::SimFlag_t simflag =
00304 (vldr.GetSimMask() & SimFlag::kData) ? SimFlag::kData : SimFlag::kMC;
00305 VldTimeStamp ts = vldr.GetTimeStart();
00306 return VldContext(detector,simflag,ts);
00307 }
00308
00309
00310 PlaneView::PlaneView_t
00311 PlexVetoShieldHack::GetMdlPlaneView(const VldContext& vldc, UInt_t mdl_pln)
00312 {
00313 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00314 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00315 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00316 if (the_muxtomdl->GetMdlPln() == mdl_pln) {
00317 return the_muxtomdl->GetSingleMdlPlaneId().GetPlaneView();
00318 }
00319 }
00320 return PlaneView::kVSUnknown;
00321 }
00322
00323
00324 PlaneCoverage::PlaneCoverage_t
00325 PlexVetoShieldHack::GetMdlPlaneCoverage(const VldContext& vldc, UInt_t mdl_pln)
00326 {
00327
00328 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00329 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00330 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00331 if (the_muxtomdl->GetMdlPln() == mdl_pln) {
00332 return the_muxtomdl->GetSingleMdlPlaneId().GetPlaneCoverage();
00333 }
00334 }
00335 return PlaneCoverage::kUnknown;
00336 }
00337
00338
00339 const PlexVetoShieldMuxToMdl*
00340 PlexVetoShieldHack::LookForMuxMdl(const VldContext& vldc,
00341 UInt_t mux_pln, UInt_t mux_mdl)
00342 {
00343
00344 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00345 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00346 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00347 if (the_muxtomdl->GetMuxPln() == mux_pln &&
00348 the_muxtomdl->GetMuxMdl() == mux_mdl ) {
00349 return the_muxtomdl;
00350 }
00351 }
00352 return 0;
00353 }
00354
00355
00356 const PlexVetoShieldMuxToMdl*
00357 PlexVetoShieldHack::LookForSingleMdl(const VldContext& vldc,
00358 UInt_t mdl_pln)
00359 {
00360
00361 DbiResultPtr<PlexVetoShieldMuxToMdl> mapping(vldc);
00362 for (unsigned int i=0; i<mapping.GetNumRows(); ++i) {
00363 const PlexVetoShieldMuxToMdl *the_muxtomdl = mapping.GetRow(i);
00364 if (the_muxtomdl->GetMdlPln() == mdl_pln ) {
00365 return the_muxtomdl;
00366 }
00367 }
00368 return 0;
00369 }
00370
00371