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

Plexus.cxx

Go to the documentation of this file.
00001 
00002 // $Id: Plexus.cxx,v 1.57 2007/04/26 14:22:46 west Exp $
00003 //
00004 // Plexus
00005 //
00006 // Plexus is an actual connection map
00007 //
00008 // Author:  R. Hatcher 2000.05.03
00009 //
00011 
00012 #include "Plex/Plexus.h"
00013 #include "Plex/PlexLoanPool.h"
00014 
00015 #include "DatabaseInterface/DbiResultPtr.h"
00016 #include "DatabaseInterface/DbiTableProxy.h"
00017 #include "DatabaseInterface/DbiCache.h"
00018 
00019 #include "Plex/PlexPixelSpotToStripEnd.h"
00020 #include "Plex/PlexPixelToRawChannel.h"
00021 #include "Plex/PlexRawChannelReadoutType.h"
00022 #include "Plex/PlexRawChannelToPinDiode.h"
00023 #include "Plex/PlexPinDiodeToLed.h"
00024 #include "Plex/PlexStripEndToLed.h"
00025 
00026 #include "Plex/PlexVetoShieldHack.h"
00027 
00028 #include "MessageService/MsgService.h"
00029 CVSID("$Id: Plexus.cxx,v 1.57 2007/04/26 14:22:46 west Exp $");
00030 
00031 #include "TSystem.h"
00032 #include "TString.h"
00033 
00034 #include <set>
00035 #include <cassert>
00036 #include <algorithm>
00037 
00038 ClassImp(Plexus)
00039 
00040 Bool_t Plexus::fgAltLHasBrokenFibers = false;
00041 Bool_t Plexus::fgAltLInitiallySortedBySEId = false;
00042 
00043 RawChannelId rcidNull;
00044 
00045 int paranoia = 0;
00046 
00047 //_____________________________________________________________________________
00048 struct less_altl_seid : 
00049    public binary_function<PlexSEIdAltLItem, PlexSEIdAltLItem, bool> 
00050 {
00051   bool operator()(PlexSEIdAltLItem x, PlexSEIdAltLItem y) 
00052   { 
00053     // sort by PlexStripEndId (should be no duplicates)
00054     return x.GetSEId() < y.GetSEId(); 
00055   }
00056 };
00057 
00058 //_____________________________________________________________________________
00059 Plexus::Plexus()
00060    : fRef(0), fVldRange(), fBuiltMaps(0)
00061 {
00062    // Default constructor
00063    MSG("Plex",Msg::kVerbose) << "default ctor " << endl;
00064 }
00065 
00066 //_____________________________________________________________________________
00067 Plexus::Plexus(const VldContext& vldc)
00068    : fRef(0), fBuiltMaps(0)
00069 {
00070    // normal constructor
00071    MSG("Plex",Msg::kVerbose) << "Plexus(vldc) ctor " << endl;
00072 
00073    const Int_t mostbits = 0x7fffffff;
00074    const VldTimeStamp longago     = VldTimeStamp((time_t)0,0);
00075    const VldTimeStamp forevermore = VldTimeStamp((time_t)mostbits,999999999);
00076    
00077    fVldRange = VldRange(mostbits,mostbits,longago,forevermore,"");
00078 
00079    const Registry& config = PlexLoanPool::Instance()->GetConfig();
00080    config.Get("Paranoia",paranoia);
00081    if (paranoia) {
00082      MSG("Plex",Msg::kInfo)
00083        << "Plexus(vldc) paranoia level " << paranoia << endl;
00084    }
00085 
00086    // prime veto shield converter table so that
00087    // DBI accounting for PlexPixelSpotToStripEnd is correctly attributed.
00088    if (vldc.GetDetector() == Detector::kFar) {
00089      MSG("Plex",Msg::kDebug) 
00090        << "Plexus(vldc) ctor - mux2mdl " << vldc << endl;
00091      DbiResultPtr<PlexVetoShieldMuxToMdl> mux2mdl(vldc);
00092    }
00093 
00094    BuildPixelMaps(vldc);
00095    BuildPinDiodeMap(vldc);
00096    // do Readout Map *after* we know ScintStrips and PinDiodes
00097    BuildReadoutMap(vldc);
00098    BuildLedMaps(vldc);
00099 }
00100 
00101 //_____________________________________________________________________________
00102 Plexus::~Plexus()
00103 {
00104    // delete all the owned sub-objects
00105 
00106 }
00107 
00108 //_____________________________________________________________________________
00109 Bool_t Plexus::IsCompatible(const VldContext &vldc)
00110 {
00111    // check compatibility of this plex with a context
00112 
00113    return fVldRange.IsCompatible(vldc);
00114 
00115 }
00116 
00117 //_____________________________________________________________________________
00118 Bool_t Plexus::IsCompatible(const VldContext *vldc)
00119 {
00120    // check compatibility of this plex with a context
00121 
00122    return fVldRange.IsCompatible(vldc);
00123 
00124 }
00125 
00126 //_____________________________________________________________________________
00127 void Plexus::Print(Option_t *option) const
00128 {
00129    // Print info about this object
00130    cout << " " << TObject::GetName()
00131         << " has " << CountRef() << " references " << endl
00132         << "    " << fVldRange.AsString("a") << endl;
00133 
00134    TString opt(option);
00135    if (opt.Contains("s")) {
00136 
00137      printf("   ChannelToPixel:    %6u   PixelToChannel:     %6u\n",
00138             (UInt_t)fChannelToPixel.size(),(UInt_t)fPixelToChannel.size());
00139      printf("   PixelToStripEnd:   %6u   StripEndToSpot:     %6u\n",
00140             (UInt_t)fPixelToStripEnd.size(),(UInt_t)fStripEndToSpot.size());
00141      printf("   ChannelToReadout:  %6u\n",(UInt_t)fChannelToReadout.size());
00142      printf("   ChannelToPinDiode: %6u\n",(UInt_t)fChannelToPinDiode.size());
00143      printf("   StripEndToLed:     %6u   PinDiodeToLed:      %6u\n",
00144             (UInt_t)fStripEndToLed.size(),(UInt_t)fPinDiodeToLed.size());
00145 
00146      // classify readout types
00147      if (opt.Contains("r")) {
00148        const vector<RawChannelId>& all_rcid = GetAllRawChannelIds();
00149        printf("   There are %u unique RawChannelIds\n",(UInt_t)all_rcid.size());
00150 
00151        std::map<ReadoutType::Readout_t,UInt_t> readoutTypeCount;
00152        for (size_t i=0; i<all_rcid.size(); ++i) {
00153          RawChannelId rcid = all_rcid[i];
00154          ReadoutType::Readout_t rtype = GetReadoutType(rcid);
00155          readoutTypeCount[rtype]++;
00156        }
00157        
00158        std::map<ReadoutType::Readout_t,UInt_t>::const_iterator rtcItr = 
00159          readoutTypeCount.begin();
00160        while ( rtcItr != readoutTypeCount.end() ) {
00161          printf("     %-15s had %5d channels\n",
00162                 ReadoutType::AsString(rtcItr->first),
00163                 rtcItr->second);
00164          rtcItr++;
00165        }
00166      }
00167    }
00168 }
00169 
00170 //_____________________________________________________________________________
00171 RawChannelId Plexus::GetRawChannelId(const PlexStripEndId& seid) const
00172 {
00173    // Convert PlexStripEndId into RawChannelId (m:1 mapping)
00174    
00175   StripEnd::StripEnd_t end = seid.GetEnd();;
00176   if ( StripEnd::kWhole == end || StripEnd::kUnknown == end ) {
00177     MAXMSG("Plex",Msg::kInfo,10)
00178       << "GetRawChannelId called for SEId=" 
00179       << seid << " which has StripEnd either 'Unknown' or 'Whole';"
00180       << " this is unlikely to succeed."
00181       << endl;
00182   }
00183   else {
00184     Detector::Detector_t det = seid.GetDetector();
00185     if ( Detector::kNear == det && StripEnd::kEast == end ) {
00186       MAXMSG("Plex",Msg::kInfo,10)
00187         << "GetRawChannelId called for SEId=" 
00188         << seid << " which has StripEnd of 'East';"
00189         << " this is unlikely to succeed."
00190       << endl;
00191     }    
00192   }
00193 
00194   // was: PlexPixelSpotId psid = fStripEndToSpot[seid];
00195   // use find() to avoid adding null entries
00196   std::map<PlexStripEndId,PlexPixelSpotId>::const_iterator sepsItr = 
00197       fStripEndToSpot.find(seid);
00198   if (sepsItr == fStripEndToSpot.end()) return RawChannelId(); // not there!
00199 
00200    return GetRawChannelId(sepsItr->second);
00201 }
00202 
00203 //_____________________________________________________________________________
00204 RawChannelId Plexus::GetRawChannelId(const PlexPixelSpotId& psid) const
00205 {
00206    // Convert PlexPixelSpotId into RawChannelId (m:1 mapping)
00207    
00208    // clear the spot value as that isn't used in pixel->channel
00209    PlexPixelSpotId psid_nospot = psid;
00210    psid_nospot.SetSpot(0);
00211 
00212    // was: return fPixelToChannel[psid_nospot];
00213    // use find() to avoid adding null entries
00214    std::map<PlexPixelSpotId,RawChannelId>::const_iterator psrcItr = 
00215        fPixelToChannel.find(psid_nospot);
00216    if (psrcItr == fPixelToChannel.end()) return RawChannelId(); // not there!
00217 
00218    return psrcItr->second;
00219 }
00220 
00221 //_____________________________________________________________________________
00222 RawChannelId Plexus::GetRawChannelId(const PlexPinDiodeId& diodeid) const
00223 {
00224    // Convert PinDiodeId into a RawChannelId
00225 
00226    // walk through the map looking for a match
00227    // this is slower than the reverse operation but
00228    // means that we don't need a second copy of the information
00229 
00230    typedef map<RawChannelId,PlexPinDiodeId>::const_iterator rc2pd_itr;
00231 
00232    for (rc2pd_itr irc2pd  = fChannelToPinDiode.begin();
00233                   irc2pd != fChannelToPinDiode.end(); ++irc2pd) {
00234       if (irc2pd->second == diodeid) return irc2pd->first;
00235    }
00236 
00237    // nothing appropriate found
00238    return RawChannelId();
00239 }
00240 
00241 //_____________________________________________________________________________
00242 PlexSEIdAltL Plexus::GetSEIdAltL(const RawChannelId& rcid,
00243                                  const PlexCalib* calib,
00244                                  Int_t adc, Double_t time) const
00245 { 
00246    // Convert RawChannelId into PlexStripEndId Alternative List (1:m mapping)
00247 
00248    //MSG("Plex",Msg::kVerbose)
00249    //   << " GetSEIdAltL RCID=" << rcid << ":" << endl;
00250 
00251    PlexSEIdAltL altlist;  // start with empty altlist
00252 
00253    // the map has the {pedestal,spars,common} mode bits off
00254    RawChannelId rcid0 = rcid;
00255    rcid0.ClearModeBits();
00256 
00257    // the near detector spectrometer can map RawChannel to >1 Pixel
00258    // far detector maps each Pixel to more than one StripEnd
00259    // do this as a nested loop over two multimaps
00260 
00261    typedef multimap<RawChannelId,PlexPixelSpotId>::const_iterator   rc2p_itr;
00262    typedef multimap<PlexPixelSpotId,PlexStripEndId>::const_iterator p2se_itr;
00263 
00264    pair<rc2p_itr,rc2p_itr> rc2p_limits = fChannelToPixel.equal_range(rcid0);
00265    for (rc2p_itr irc2p  = rc2p_limits.first; 
00266                  irc2p != rc2p_limits.second; ++irc2p) {
00267       pair<p2se_itr,p2se_itr> p2se_limits = 
00268          fPixelToStripEnd.equal_range(irc2p->second);
00269       for (p2se_itr ip2se  = p2se_limits.first;
00270                     ip2se != p2se_limits.second; ++ip2se) {
00271          PlexStripEndId seid = ip2se->second;
00272          if (seid.IsValid()) {
00273             // look to see if the spot is 0 signalling broken fiber
00274             PlexPixelSpotId spotid = fStripEndToSpot[seid];
00275             if (fgAltLHasBrokenFibers || spotid.GetSpot() != 0) {
00276                altlist.AddStripEndId(seid,spotid,0,calib,adc,time);
00277                //MSG("Plex",Msg::kVerbose)
00278                //    << "    add SEID=" << seid 
00279                //    << " " << seid.GetEncoded()
00280                //    << endl;
00281             }
00282             else {
00283                MSG("Plex",Msg::kVerbose)
00284                    << "    suppress broken fiber SEID=" << seid 
00285                    << " " << seid.GetEncoded()
00286                    << endl;
00287             }
00288          } // seid.IsValid()
00289       } // loop over Pixel->StripEnd
00290    } // loop over RawChannel->Pixel
00291 
00292 
00293    if ( fgAltLInitiallySortedBySEId )
00294      std::sort(altlist.begin(),altlist.end(),less_altl_seid());
00295 
00296    return altlist;
00297 }
00298 
00299 //_____________________________________________________________________________
00300 PlexStripEndId Plexus::GetStripEndId(const PlexPixelSpotId& psid) const
00301 { 
00302    // Convert PlexPixelSpotId into a PlexStripEndId (1:1)
00303 
00304    // this is a bit tricky because we've tossed the spot info
00305    // from the multimap fPixelToStripEnd for ease of building
00306    // AltL's, so we need to loop and test the round trip
00307 
00308    typedef multimap<PlexPixelSpotId,PlexStripEndId>::const_iterator p2se_itr;
00309 
00310    PlexPixelSpotId pixelid = psid;
00311    pixelid.SetSpot(0);  // zero out spot info for multimap pixel->seid(s)
00312 
00313    pair<p2se_itr,p2se_itr> p2se_limits = 
00314       fPixelToStripEnd.equal_range(pixelid);
00315    for (p2se_itr ip2se  = p2se_limits.first;
00316                  ip2se != p2se_limits.second; ++ip2se) {
00317       PlexStripEndId seid = ip2se->second;
00318       // check that this leads back to the *spot* we were given
00319 
00320       //was: PlexPixelSpotId testspot = fStripEndToSpot[seid];
00321       //     if (testspot == psid) return seid;
00322       //use find() to avoid adding null entries
00323       std::map<PlexStripEndId,PlexPixelSpotId>::const_iterator sepsItr = 
00324           fStripEndToSpot.find(seid);
00325       if (sepsItr->second == psid) return seid;
00326 
00327    }
00328 
00329    return PlexStripEndId();  // no match
00330 
00331 }
00332 
00333 //_____________________________________________________________________________
00334 vector<PlexPixelSpotId> Plexus::GetPixelSpotIdVector(const RawChannelId& rcid, 
00335                                                      bool uniquePixels) const
00336 { 
00337    // Convert RawChannelId into a vector of PlexPixelSpotId's 
00338    // if uniquePixels=true then set spot=0 (1:m) and return
00339    // a list of *pixels* not pixel-spots.
00340    //
00341    // RawChannelId may not map to single Pixel in the case of
00342    // near detector.  
00343 
00344    vector<PlexPixelSpotId> pixelspots;
00345  
00346   if (uniquePixels) {
00347 
00348      // the map has the {pedestal,spars,common} mode bits off
00349      RawChannelId rcid0 = rcid;
00350      rcid0.ClearModeBits();
00351      
00352      typedef multimap<RawChannelId,PlexPixelSpotId>::const_iterator   rc2p_itr;
00353      
00354      pair<rc2p_itr,rc2p_itr> rc2p_limits = fChannelToPixel.equal_range(rcid0);
00355      for (rc2p_itr irc2p  = rc2p_limits.first; 
00356           irc2p != rc2p_limits.second; ++irc2p) {
00357        PlexPixelSpotId aspot = irc2p->second;
00358        pixelspots.push_back(aspot);
00359      }
00360 
00361    }
00362    else {
00363      // return all spots, even if the pixel part isn't unique
00364      // take the easy road out and use existing mechanism
00365      PlexSEIdAltL altl = this->GetSEIdAltL(rcid);
00366      for (size_t i=0; i < altl.size(); ++i) 
00367        pixelspots.push_back(altl[i].GetPixelSpotId());
00368    }
00369 
00370   return pixelspots;
00371 }
00372 
00373 //_____________________________________________________________________________
00374 PlexPixelSpotId Plexus::GetPixelSpotId(const PlexStripEndId& seid) const
00375 { 
00376    // Convert PlexStripEndId into a PlexPixelSpotId (1:1)
00377 
00378   //was: return fStripEndToSpot[seid];
00379   //use find() to avoid adding null entries
00380   std::map<PlexStripEndId,PlexPixelSpotId>::const_iterator sepsItr = 
00381       fStripEndToSpot.find(seid);
00382   if (sepsItr == fStripEndToSpot.end()) return PlexPixelSpotId(); // not there!
00383 
00384   return sepsItr->second;
00385 }
00386 
00387 //_____________________________________________________________________________
00388 PlexPinDiodeId Plexus::GetPinDiodeId(const RawChannelId& rcid) const
00389 {
00390    // Convert RawChannelId into PlexPinDiodeId (if possible)
00391 
00392    // the map has the {pedestal,spars,common} mode bits off
00393    RawChannelId rcid0 = rcid;
00394    rcid0.ClearModeBits();
00395 
00396    return fChannelToPinDiode[rcid0];
00397 }
00398 
00399 //_____________________________________________________________________________
00400 ReadoutType::Readout_t Plexus::GetReadoutType(const RawChannelId& rcid) const
00401 { 
00402    // Determine what (eg. scint strip, pin diode, cerenkov, tof) 
00403    // is attached to raw channel
00404 
00405    if ( rcid == rcidNull ) return ReadoutType::kUnknown;
00406 
00407    // deal with special case of VA common mode rejection channels
00408    // no need to explicitly test for electronics type as unpacker does
00409    // (returns -1 if not a VA channel)
00410    switch (rcid.GetVaChannel()) {
00411    case  0:
00412    case  1:
00413    case 19:
00414    case 20:
00415    case 21:
00416       return ReadoutType::kVACommonMode;
00417       break;
00418    }
00419 
00420    // the map has the {pedestal,spars,common} mode bits off
00421    RawChannelId rcid0 = rcid;
00422    rcid0.ClearModeBits();
00423 
00424    // ideally this mapping would be to ReadoutType::Readout_t
00425    // but cint can't correctly handle enum as as second type of map
00426    // so use UShort_t (must be > 8 bits to correctly hold all Readout_t values)
00427 
00428    return (ReadoutType::Readout_t)fChannelToReadout[rcid0];
00429 
00430 }
00431 
00432 //_____________________________________________________________________________
00433 std::string Plexus::GetSpecialDescript(const RawChannelId& rcid) const
00434 {
00435    // if a special channel (Cerenkov, TOF, etc) from the 
00436    // PLEXRAWCHANNELREADOUTTYPE table return the associated string
00437    RawChannelId rcid0 = rcid;
00438    rcid0.ClearModeBits();
00439 
00440    return fSpecialDescript[rcid0];
00441 }
00442 //_____________________________________________________________________________
00443 RawChannelId Plexus::GetSpecialChannelContains(const std::string& key)const
00444 {
00445    // look for a special channel description string that contains
00446    // the passed key.  Allowing one to distinguish between different
00447    // special channels of the same readout type by extending what
00448    // is put in the PLEXRAWCHANNELREADOUTTYPE table
00449 
00450   typedef map<RawChannelId,std::string>::const_iterator rc2string_itr;
00451   for (rc2string_itr irc2s  = fSpecialDescript.begin();
00452                      irc2s != fSpecialDescript.end(); ++ irc2s) {
00453     // lazy approach ... use TString's Contains() to do work
00454     TString description(irc2s->second.c_str());
00455     if (description.Contains(key.c_str())) return irc2s->first;
00456   }
00457   return RawChannelId();
00458 
00459 }
00460 //_____________________________________________________________________________
00461 std::vector<PlexStripEndId> 
00462 Plexus::GetStripEndIdVector(const PlexLedId& ledid) const
00463 {
00464    // Convert PlexLedId into a vector of PlexStripEndId's (1:m)
00465 
00466    vector<PlexStripEndId> stripends;
00467 
00468    typedef map<PlexStripEndId,PlexLedId>::const_iterator se2led_itr;
00469 
00470    for (se2led_itr ise2led  = fStripEndToLed.begin();
00471                    ise2led != fStripEndToLed.end(); ++ise2led) {
00472       if (ise2led->second == ledid) stripends.push_back(ise2led->first);
00473    }
00474 
00475    return stripends;
00476 }
00477 
00478 //_____________________________________________________________________________
00479 std::pair<PlexPinDiodeId,PlexPinDiodeId> 
00480 Plexus::GetPinDiodeIds(const PlexLedId& ledid) const
00481 {
00482    // Convert PlexLedId into a pair of PlexPinDiodeId's (1:[1,2])
00483 
00484    pair<PlexPinDiodeId,PlexPinDiodeId> diodepair;
00485    PlexPinDiodeId high_gain;
00486    PlexPinDiodeId low_gain;
00487 
00488    typedef map<PlexPinDiodeId,PlexLedId>::const_iterator pd2led_itr;
00489 
00490    for (pd2led_itr ipd2led  = fPinDiodeToLed.begin();
00491                    ipd2led != fPinDiodeToLed.end(); ++ipd2led) {
00492       if (ipd2led->second == ledid) {
00493          PlexPinDiodeId pinid = ipd2led->first;
00494 
00495          // Gain:  1=LO, 0=HIGH     !Arghhh!
00496          if (pinid.IsHighGain()) {
00497             // high gain pin diode
00498             if (!high_gain.IsValid()) high_gain = pinid;
00499             else {
00500                // this shouldn't happen
00501                MSG("Plex",Msg::kError) 
00502                   << "GetPinDiodeIds already found high gain "
00503                   << high_gain.AsString()
00504                   << " before " << pinid.AsString() 
00505                   << ", ignore new " << endl;
00506             }
00507          }
00508          else {
00509             // low gain pin diode
00510             if (!low_gain.IsValid()) low_gain = pinid;
00511             else {
00512                // this shouldn't happen
00513                MSG("Plex",Msg::kError) 
00514                   << "GetPinDiodeIds already found low gain "
00515                   << low_gain.AsString()
00516                   << " before " << pinid.AsString() 
00517                   << ", ignore new " << endl;
00518             }
00519          }
00520       }
00521    }
00522 
00523    diodepair.first  = low_gain;
00524    diodepair.second = high_gain;
00525    return diodepair;
00526 }
00527 
00528 //_____________________________________________________________________________
00529 PlexLedId Plexus::GetLedId(const PlexStripEndId& seid) const
00530 {
00531    // Convert PlexStripEndId into a PlexLedId (N:1)
00532 
00533    return fStripEndToLed[seid];
00534 }
00535 
00536 //_____________________________________________________________________________
00537 PlexLedId Plexus::GetLedId(const PlexPinDiodeId& diodeid) const
00538 {
00539    // Convert PlexPinDiodeId into a PlexLedId (N:1)
00540 
00541    return fPinDiodeToLed[diodeid];
00542 }
00543 
00544 //_____________________________________________________________________________
00545 const std::vector<PlexStripEndId>&
00546 Plexus::GetAllStripEnds(StripEnd::StripEnd_t restrictEnd) const
00547 { 
00548   // Return (build if necessary) a list of legal PlexStripEndIds
00549   // If restrictEnd is kEast or kWest limit list to that end
00550   // If restrictEnd is kWhole force ids to be only for whole strip
00551   //     (and eliminate duplicates)
00552 
00553   std::vector<PlexStripEndId>* thevector = 0;
00554   switch (restrictEnd) {
00555   case StripEnd::kEast:  thevector = &fAllEastEnds;  break;
00556   case StripEnd::kWest:  thevector = &fAllWestEnds;  break;
00557   case StripEnd::kWhole: thevector = &fAllStrips;    break;
00558   default:               thevector = &fAllStripEnds; break;
00559   }
00560 
00561   if ( thevector->empty() ) {
00562 
00563     // we need to fill the vector
00564 
00565     typedef map<PlexStripEndId,PlexPixelSpotId>::const_iterator se2spot_itr;
00566     se2spot_itr seItr    = fStripEndToSpot.begin();
00567     se2spot_itr seItrEnd = fStripEndToSpot.end();
00568     
00569     PlexStripEndId seidLast;
00570     
00571     for ( ; seItr != seItrEnd; ++seItr) {
00572       PlexStripEndId seid = seItr->first;
00573       switch (restrictEnd) {
00574         // if a particular side is chosen only add those
00575       case StripEnd::kEast:
00576       case StripEnd::kWest:
00577         if ( seid.GetEnd() != restrictEnd ) continue;
00578         break;
00579       case StripEnd::kWhole:
00580         seid.SetEnd(StripEnd::kWhole);  // for whole-ness
00581         // this next test is under the assumption that the PlexStripEndId
00582         // sorts ends of the same strips to consecutive places in the map
00583         // otherwise we'd have to be constructing a std::set to guarentee
00584         // uniqueness of the strips (or do ever lengthening searches)
00585         if ( seid == seidLast ) continue;
00586         seidLast = seid;
00587         break;
00588       default:
00589         // just add it with no restrictions
00590         break;
00591       }
00592       // add to the list
00593       thevector->push_back(seid);
00594     }
00595     
00596   }
00597 
00598   return *thevector;
00599 }
00600 
00601 //_____________________________________________________________________________
00602 const std::vector<PlexPixelSpotId>& 
00603 Plexus::GetAllPixelSpotIds(Plexus::ETrimSpots trim) const
00604 {
00605   // Return (build if necessary) a list of legal spots, pixels, tubes
00606   // If restrictEnd is kEast or kWest limit list to that end
00607   // If restrictEnd is kWhole force ids to be only for whole strip
00608   //     (and eliminate duplicates)
00609 
00610   std::vector<PlexPixelSpotId>* thevector = 0;
00611   switch (trim) {
00612   case kIncludeTube:  thevector = &fAllTubes;   break;
00613   case kIncludePixel: thevector = &fAllPixels;  break;
00614   default:            thevector = &fAllSpots;   break;
00615   }
00616 
00617   if ( thevector->empty() ) {
00618 
00619     // we need to fill the vector
00620     // but use an intermediate set to force uniqueness and ordering
00621     // based on normal PlexPixelSpotId order
00622    
00623     typedef std::map<PlexStripEndId,PlexPixelSpotId>::const_iterator se2spot_itr;
00624     se2spot_itr seItr    = fStripEndToSpot.begin();
00625     se2spot_itr seItrEnd = fStripEndToSpot.end();
00626     
00627     std::set<PlexPixelSpotId> spotSet;
00628     
00629     for ( ; seItr != seItrEnd; ++seItr) {
00630       PlexPixelSpotId spot = seItr->second;
00631       switch (trim) {
00632         // rely on fall through
00633       case kIncludeTube:  spot.SetPixel(0);
00634       case kIncludePixel: spot.SetSpot(0);
00635       default:            break;
00636       }
00637       // add to the set, let it take care of uniqueness
00638       spotSet.insert(spot);
00639     }
00640 
00641     // copy set values into vector
00642     typedef std::set<PlexPixelSpotId>::iterator spotset_itr;
00643     spotset_itr spotItr    = spotSet.begin();
00644     spotset_itr spotItrEnd = spotSet.end();
00645     for ( ; spotItr != spotItrEnd; ++spotItr)
00646       thevector->push_back(*spotItr);
00647   }
00648 
00649   return *thevector;
00650 }
00651 
00652 
00653 //_____________________________________________________________________________
00654 const std::vector<RawChannelId>& 
00655 Plexus::GetAllRawChannelIds() const
00656 {
00657   // Return (build if necessary) a list of legal RawChannelIds
00658 
00659   if ( fAllChannels.empty() ) {
00660 
00661     // we need to fill the vector
00662     // but use an intermediate set to force uniqueness and ordering
00663     // base on normal RawChannelId order
00664 
00665     std::set<RawChannelId> rcidSet;
00666     
00667     // fill from mapping of channels to pixels
00668     typedef std::map<RawChannelId,PlexPixelSpotId>::const_iterator rc2pixel_itr;
00669     rc2pixel_itr rcpxItr    = fChannelToPixel.begin();
00670     rc2pixel_itr rcpxItrEnd = fChannelToPixel.end();
00671     for ( ; rcpxItr != rcpxItrEnd; ++rcpxItr) rcidSet.insert(rcpxItr->first);
00672 
00673     //
00674     typedef std::map<RawChannelId,PlexPinDiodeId>::const_iterator rc2pin_itr;
00675     rc2pin_itr rcpinItr    = fChannelToPinDiode.begin();
00676     rc2pin_itr rcpinItrEnd = fChannelToPinDiode.end();
00677     for ( ; rcpinItr != rcpinItrEnd; ++rcpinItr) rcidSet.insert(rcpinItr->first);
00678     // 
00679     typedef std::map<RawChannelId,UShort_t>::const_iterator rc2type_itr;
00680     rc2type_itr rctypeItr    = fChannelToReadout.begin();
00681     rc2type_itr rctypeItrEnd = fChannelToReadout.end();
00682     for ( ; rctypeItr != rctypeItrEnd; ++rctypeItr) rcidSet.insert(rctypeItr->first);
00683 
00684     //
00685     typedef std::map<RawChannelId,std::string>::const_iterator rc2desc_itr;
00686     rc2desc_itr rcdescItr    = fSpecialDescript.begin();
00687     rc2desc_itr rcdescItrEnd = fSpecialDescript.end();
00688     for ( ; rcdescItr != rcdescItrEnd; ++rcdescItr) rcidSet.insert(rcdescItr->first);
00689     
00690 
00691     // copy set values into vector
00692     typedef std::set<RawChannelId>::iterator rcidset_itr;
00693     rcidset_itr rcidItr    = rcidSet.begin();
00694     rcidset_itr rcidItrEnd = rcidSet.end();
00695     for ( ; rcidItr != rcidItrEnd; ++rcidItr)
00696       fAllChannels.push_back(*rcidItr);
00697 
00698   }
00699   return fAllChannels;
00700 }
00701 
00702 
00703 //_____________________________________________________________________________
00704 const std::vector<PlexPinDiodeId>& 
00705 Plexus::GetAllPinDiodes() const
00706 {
00707   // Return (build if necessary) a list of legal PlexPindDiodeIds
00708 
00709   if ( fAllPinDiodes.empty() ) {
00710 
00711     // we need to fill the vector
00712     // but use an intermediate set to force uniqueness and ordering
00713     // base on normal PlexPinDiodeId order
00714 
00715     std::set<PlexPinDiodeId> pindSet;
00716     
00717     // fill from list of raw channel list mapped to pin diodes
00718     typedef std::map<RawChannelId,PlexPinDiodeId>::const_iterator rc2pin_itr;
00719     rc2pin_itr rcpinItr    = fChannelToPinDiode.begin();
00720     rc2pin_itr rcpinItrEnd = fChannelToPinDiode.end();
00721     for ( ; rcpinItr != rcpinItrEnd; ++rcpinItr) pindSet.insert(rcpinItr->second);
00722 
00723     // fill fromlist of pin diodes mapped to leds
00724     typedef std::map<PlexPinDiodeId,PlexLedId>::const_iterator pin2led_itr;
00725     pin2led_itr pinledItr    = fPinDiodeToLed.begin();
00726     pin2led_itr pinledItrEnd = fPinDiodeToLed.end();
00727     for ( ; pinledItr != pinledItrEnd; ++pinledItr) pindSet.insert(pinledItr->first);
00728 
00729     // copy set values into vector
00730     typedef std::set<PlexPinDiodeId>::iterator pindset_itr;
00731     pindset_itr pindItr    = pindSet.begin();
00732     pindset_itr pindItrEnd = pindSet.end();
00733     for ( ; pindItr != pindItrEnd; ++pindItr)
00734       fAllPinDiodes.push_back(*pindItr);
00735 
00736   }
00737   return fAllPinDiodes;
00738 }
00739 
00740 
00741 //_____________________________________________________________________________
00742 const std::vector<PlexLedId>& 
00743 Plexus::GetAllLeds() const
00744 {
00745   // Return (build if necessary) a list of legal PlexLedIds
00746 
00747   if ( fAllLeds.empty() ) {
00748 
00749     // we need to fill the vector
00750     // but use an intermediate set to force uniqueness and ordering
00751     // base on normal PlexLedId order
00752 
00753     std::set<PlexLedId> ledSet;
00754     
00755     // fill from mapping of stripends to leds
00756     typedef std::map<PlexStripEndId,PlexLedId>::const_iterator seid2led_itr;
00757     seid2led_itr seledItr    = fStripEndToLed.begin();
00758     seid2led_itr seledItrEnd = fStripEndToLed.end();
00759     for ( ; seledItr != seledItrEnd; ++seledItr) ledSet.insert(seledItr->second);
00760 
00761     // fill from mapping of pindiodes to leds
00762     typedef std::map<PlexPinDiodeId,PlexLedId>::const_iterator pind2led_itr;
00763     pind2led_itr pinledItr    = fPinDiodeToLed.begin();
00764     pind2led_itr pinledItrEnd = fPinDiodeToLed.end();
00765     for ( ; pinledItr != pinledItrEnd; ++pinledItr) ledSet.insert(pinledItr->second);
00766 
00767     // copy set values into vector
00768     typedef std::set<PlexLedId>::iterator ledset_itr;
00769     ledset_itr ledItr    = ledSet.begin();
00770     ledset_itr ledItrEnd = ledSet.end();
00771     for ( ; ledItr != ledItrEnd; ++ledItr)
00772       fAllLeds.push_back(*ledItr);
00773 
00774   }
00775   return fAllLeds;
00776 }
00777 
00778 
00779 
00780 //_____________________________________________________________________________
00781 void Plexus::BuildPixelMaps(const VldContext& vldc) const
00782 { 
00783    // build the basic maps   RawChannel <--> PixelSpot <--> StripEnd
00784 
00785    if (kPixelMaps & fBuiltMaps) return;
00786    fBuiltMaps |= kPixelMaps;
00787 
00788    DbiCache* pstoseTblCache = 0;
00789    DbiCache* ptorcTblCache = 0;
00790 
00791    {
00792       // start of inner scope to that DbiResultPtr's will die, die, die
00793       // and thus Purge will see no remaining clients
00794       
00795       DbiResultPtr<PlexPixelSpotToStripEnd> pstoseResPtr(vldc);
00796       DbiResultPtr<PlexPixelToRawChannel>   ptorcResPtr(vldc);
00797 
00798       // update the fVldRange
00799       TrimVldRange("PlexPixelSpotToStripEnd",pstoseResPtr.GetValidityRec());
00800       TrimVldRange("PlexPixelToRawChannel",ptorcResPtr.GetValidityRec());
00801 
00802       // get a handle for the caches
00803       pstoseTblCache = pstoseResPtr.TableProxy().GetCache();
00804       ptorcTblCache = ptorcResPtr.TableProxy().GetCache();
00805 
00806       // how many rows did we get?
00807       UInt_t npstose = pstoseResPtr.GetNumRows();
00808       UInt_t nptorc  = ptorcResPtr.GetNumRows();
00809 
00810       // complain bitterly if either is zero
00811       // this is indicative of a serious database problem
00812       if (npstose == 0)
00813         MSG("Plex",Msg::kFatal)
00814           << "No entries retrieved from PlexPixelSpotToStripEnd table." 
00815           << endl;
00816       if (nptorc == 0)
00817         MSG("Plex",Msg::kFatal)
00818           << "No entries retrieved from PlexPixelToRawChannel table." 
00819           << endl;
00820 
00821       // build the maps:  PixelSpot <--> StripEnd 
00822       for (UInt_t irow = 0; irow < npstose; ++irow) {
00823          const PlexPixelSpotToStripEnd* pstose = pstoseResPtr.GetRow(irow);
00824          PlexPixelSpotId spotid = pstose->GetPlexPixelSpotId();
00825          PlexStripEndId    seid = pstose->GetPlexStripEndId();
00826 
00827          bool isokay_pstose = true;
00828          if ( paranoia ) { 
00829            if ( fStripEndToSpot.find(seid) != fStripEndToSpot.end() ) {
00830              isokay_pstose = false;
00831              if ( paranoia > 1 || seid.GetPlane() != 1023 ) 
00832                MSG("Plex",Msg::kInfo) 
00833                  << "BuildPixelMaps StripEnd "
00834                  << seid.AsString("c") 
00835                  << endl
00836                  << "   attached to PixelSpot "
00837                  << fStripEndToSpot[seid].AsString("c")
00838                  << endl
00839                  << "   new PixelSpot entry   "
00840                  << spotid.AsString("c")
00841                  << endl;
00842            }
00843          }
00844          
00845          if (isokay_pstose) {
00846            fStripEndToSpot[seid]   = spotid;
00847            // for multimap sake throw away the "spot" info in this direction
00848            PlexPixelSpotId pixelid = spotid;
00849            pixelid.SetSpot(0);
00850            fPixelToStripEnd.insert(make_pair(pixelid,seid));
00851          }
00852       }
00853 
00854       // build the maps:  PixelSpot <--> RawChannel
00855       for (UInt_t irow = 0; irow < nptorc; ++irow) {
00856          const PlexPixelToRawChannel* ptorc = ptorcResPtr.GetRow(irow);
00857          PlexPixelSpotId pixelid = ptorc->GetPlexPixelSpotId();
00858          RawChannelId       rcid = ptorc->GetRawChannelId();
00859          // the map has the {pedestal,spars,common} mode bits off
00860          rcid.ClearModeBits();
00861          
00862          // ensure that pixelid doesn't have "spot" field filled
00863          // in either direction
00864          pixelid.SetSpot(0);
00865          
00866          bool isokay_ptorc = true;
00867          if ( paranoia ) {
00868            if ( fPixelToChannel.find(pixelid) != fPixelToChannel.end() ) {
00869              isokay_ptorc = false;
00870              MSG("Plex",Msg::kInfo) 
00871                << "BuildPixelMaps Pixel "
00872                << pixelid.AsString("p") 
00873                << endl
00874                << "   attached to RawChannel "
00875                << fPixelToChannel[pixelid].AsString("ec")
00876                << endl
00877                << "   new RawChannel entry   "
00878                << rcid.AsString("ec")
00879                << endl;
00880            }
00881          }
00882 
00883          if (isokay_ptorc) {
00884            fPixelToChannel[pixelid] = rcid;
00885            fChannelToPixel.insert(make_pair(rcid,pixelid));
00886          }
00887       }
00888 
00889    }
00890 
00891    if ( PlexLoanPool::Instance()->PurgeDbiTableCache() ) {
00892      // now there should be no active clients so it should be
00893      // possible to purge to our heart's content
00894      if (pstoseTblCache) pstoseTblCache->Purge();
00895      if (ptorcTblCache) ptorcTblCache->Purge();
00896    }
00897 
00898    return;
00899 }
00900 
00901 //_____________________________________________________________________________
00902 void Plexus::BuildReadoutMap(const VldContext& vldc) const
00903 { 
00904    // build the basic map:  RawChannel --> ReadoutType
00905 
00906    if (kReadoutMap & fBuiltMaps) return;
00907    fBuiltMaps |= kReadoutMap;
00908 
00909    DbiCache* rcrtTblCache = 0;
00910 
00911    {
00912       // start of inner scope to that DbiResultPtr's will die, die, die
00913       // and thus Purge will see no remaining clients
00914 
00915       DbiResultPtr<PlexRawChannelReadoutType> rcrtResPtr(vldc);
00916 
00917       // update the fVldRange
00918       TrimVldRange("PlexRawChannelReadoutType",rcrtResPtr.GetValidityRec());
00919 
00920       // get a handle for the cache
00921       rcrtTblCache = rcrtResPtr.TableProxy().GetCache();
00922 
00923       // build the map:  RawChannel --> ReadoutType
00924       for (UInt_t irow = 0; irow < rcrtResPtr.GetNumRows(); ++irow) {
00925          const PlexRawChannelReadoutType* rcrt = rcrtResPtr.GetRow(irow);
00926          RawChannelId            rcid = rcrt->GetRawChannelId();
00927          ReadoutType::Readout_t rtype = rcrt->GetReadoutType();
00928          // the map has the {pedestal,spars,common} mode bits off
00929          rcid.ClearModeBits();
00930          
00931          fChannelToReadout[rcid] = rtype;
00932          fSpecialDescript[rcid] = rcrt->GetDescript();
00933       }
00934 
00935       // use RawChannel->Pixel to make additions
00936       BuildPixelMaps(vldc);
00937       typedef multimap<RawChannelId,PlexPixelSpotId>::const_iterator rc2ps_itr;
00938       for (rc2ps_itr irc2ps  = fChannelToPixel.begin();
00939            irc2ps != fChannelToPixel.end(); ++irc2ps) {
00940          RawChannelId rcid = irc2ps->first;
00941          // the map has the {pedestal,spars,common} mode bits off
00942          rcid.ClearModeBits();
00943          
00944          // Change NJT 29/8/03: Only set kScintStrip if there
00945          // is no previous type set. This ensures the DB always wins.
00946          // Useful for the 'UnconnectedPixel' type.
00947          if(fChannelToReadout.find(rcid)==fChannelToReadout.end()) 
00948            fChannelToReadout[rcid] = ReadoutType::kScintStrip;       
00949       }
00950 
00951    }
00952 
00953    if ( PlexLoanPool::Instance()->PurgeDbiTableCache() ) {
00954      // now there should be no active clients so it should be
00955      // possible to purge to our heart's content
00956      if (rcrtTblCache) rcrtTblCache->Purge();
00957    }
00958 
00959    // use RawChannel->PinDiode to make additions
00960    BuildPinDiodeMap(vldc);
00961    typedef map<RawChannelId,PlexPinDiodeId>::const_iterator rc2pd_itr;
00962    for (rc2pd_itr irc2pd  = fChannelToPinDiode.begin();
00963                   irc2pd != fChannelToPinDiode.end(); ++irc2pd) {
00964       RawChannelId rcid = irc2pd->first;
00965       // the map has the {pedestal,spars,common} mode bits off
00966       rcid.ClearModeBits();
00967 
00968       fChannelToReadout[rcid] = ReadoutType::kPinDiode;
00969    }
00970 
00971    return;
00972 }
00973 
00974 //_____________________________________________________________________________
00975 void Plexus::BuildPinDiodeMap(const VldContext& vldc) const
00976 { 
00977    // build the basic map:  RawChannel --> PinDiode
00978 
00979    if (kPinDiodeMap & fBuiltMaps) return;
00980    fBuiltMaps |= kPinDiodeMap;
00981 
00982    DbiCache* rc2pdTblCache = 0;
00983 
00984    {
00985       // start of inner scope to that DbiResultPtr's will die, die, die
00986       // and thus Purge will see no remaining clients
00987 
00988       DbiResultPtr<PlexRawChannelToPinDiode> rc2pdResPtr(vldc);
00989 
00990       // update the fVldRange
00991       TrimVldRange("PlexRawChannelToPinDiode",rc2pdResPtr.GetValidityRec());
00992 
00993       // get a handle for the cache
00994       rc2pdTblCache = rc2pdResPtr.TableProxy().GetCache();
00995 
00996       std::set<PlexPinDiodeId> pins_seen;  // local temp for paranoia checking
00997 
00998       // build the map:  RawChannel --> PinDiode
00999       for (UInt_t irow = 0; irow < rc2pdResPtr.GetNumRows(); ++irow) {
01000          const PlexRawChannelToPinDiode* rc2pd = rc2pdResPtr.GetRow(irow);
01001          RawChannelId    rcid = rc2pd->GetRawChannelId();
01002          PlexPinDiodeId pinid = rc2pd->GetPlexPinDiodeId();
01003 
01004          // the map has the {pedestal,spars,common} mode bits off
01005          rcid.ClearModeBits();
01006 
01007          // 
01008          if ( ! paranoia ) { fChannelToPinDiode[rcid] = pinid; }
01009          else {
01010            if ( fChannelToPinDiode.find(rcid) == fChannelToPinDiode.end() ) {
01011              if ( pins_seen.find(pinid) == pins_seen.end() ) {
01012                fChannelToPinDiode[rcid] = pinid;             
01013                pins_seen.insert(pinid);
01014              }
01015              else {
01016                RawChannelId rcid_already = GetRawChannelId(pinid);
01017                MSG("Plex",Msg::kInfo) 
01018                  << "BuildPinDiodeMap PinDiode "
01019                  << pinid.AsString("c") 
01020                  << endl
01021                  << "   attached to RawChannel "
01022                  << rcid_already.AsString("ec")
01023                  << endl
01024                  << "   new RawChannel entry   "
01025                  << rcid.AsString("ec")
01026                  << endl;
01027              }
01028            }
01029            else {
01030              MSG("Plex",Msg::kInfo) 
01031                << "BuildPinDiodeMap RawChannelId "
01032                << rcid.AsString("ec") 
01033                << endl
01034                << "    attached to PinDiode " 
01035                << fChannelToPinDiode[rcid].AsString("c")
01036                << endl
01037                << "    new PinDiode entry   "
01038                << pinid.AsString("c")
01039                << endl;
01040            }
01041          }
01042 
01043       }
01044 
01045    }
01046 
01047    if ( PlexLoanPool::Instance()->PurgeDbiTableCache() ) {
01048      // now there should be no active clients so it should be
01049      // possible to purge to our heart's content
01050      if (rc2pdTblCache) rc2pdTblCache->Purge();
01051    }
01052 
01053    return;
01054 }
01055 
01056 //_____________________________________________________________________________
01057 void Plexus::BuildLedMaps(const VldContext& vldc) const
01058 { 
01059    // build the basic map:  StripEndIds <--> LED <--> PinDiodes
01060 
01061    if (kLedMaps & fBuiltMaps) return;
01062    fBuiltMaps |= kLedMaps;
01063 
01064    DbiCache* pd2ledTblCache = 0;
01065    DbiCache* se2ledTblCache = 0;
01066 
01067    {
01068       // start of inner scope to that DbiResultPtr's will die, die, die
01069       // and thus Purge will see no remaining clients
01070 
01071       DbiResultPtr<PlexPinDiodeToLed> pd2ledResPtr(vldc);
01072       DbiResultPtr<PlexStripEndToLed> se2ledResPtr(vldc);
01073 
01074       // update the fVldRange
01075       TrimVldRange("PlexPinDiodeToLed",pd2ledResPtr.GetValidityRec());
01076       TrimVldRange("PlexStripEndToLed",se2ledResPtr.GetValidityRec());
01077 
01078       // get a handle for the cache
01079       pd2ledTblCache = pd2ledResPtr.TableProxy().GetCache();
01080       se2ledTblCache = se2ledResPtr.TableProxy().GetCache();
01081 
01082       // build the map:  PinDiode --> Led
01083       for (UInt_t irow = 0; irow < pd2ledResPtr.GetNumRows(); ++irow) {
01084          const PlexPinDiodeToLed* pd2led = pd2ledResPtr.GetRow(irow);
01085          PlexPinDiodeId pinid = pd2led->GetPlexPinDiodeId();
01086          PlexLedId      ledid = pd2led->GetPlexLedId();
01087          if ( ! paranoia ) { fPinDiodeToLed[pinid] = ledid; }
01088          else {
01089            if ( fPinDiodeToLed.find(pinid) == fPinDiodeToLed.end() ) {
01090              fPinDiodeToLed[pinid] = ledid;
01091            }
01092            else {
01093              MSG("Plex",Msg::kInfo) 
01094                << "BuildLedMaps PinDiode "
01095                << pinid.AsString("c") << " to Led "
01096                << fPinDiodeToLed[pinid].AsString("c")
01097                << ", new Led " << ledid.AsString("c")
01098                << endl;
01099            }
01100          }
01101       }
01102 
01103       // build the map:  StripEnd --> Led
01104       for (UInt_t irow = 0; irow < se2ledResPtr.GetNumRows(); ++irow) {
01105          const PlexStripEndToLed* se2led = se2ledResPtr.GetRow(irow);
01106          PlexStripEndId  seid = se2led->GetPlexStripEndId();
01107          PlexLedId      ledid = se2led->GetPlexLedId();
01108          if ( ! paranoia ) { fStripEndToLed[seid] = ledid; }
01109          else {
01110            if ( fStripEndToLed.find(seid) == fStripEndToLed.end() ) {
01111              fStripEndToLed[seid] = ledid;
01112            }
01113            else {
01114              if ( paranoia > 1 || seid.GetPlane() != 1023 )
01115                MSG("Plex",Msg::kInfo) 
01116                  << "BuildLedMaps StripEnd "
01117                  << seid.AsString("c") << " to Led "
01118                  << fStripEndToLed[seid].AsString("c")
01119                  << ", new Led " << ledid.AsString("c")
01120                  << endl;
01121            }
01122          }
01123       }
01124 
01125    }
01126 
01127    if ( PlexLoanPool::Instance()->PurgeDbiTableCache() ) {
01128      // now there should be no active clients so it should be
01129      // possible to purge to our heart's content
01130      if (pd2ledTblCache) pd2ledTblCache->Purge();
01131      if (se2ledTblCache) se2ledTblCache->Purge();
01132    }
01133 
01134    return;
01135 }
01136 
01137 //_____________________________________________________________________________
01138 void Plexus::PurgeComponents(UInt_t purgeMask)
01139 { 
01140   // clear out components of the plex 
01141   // generally done before writing it out to save space
01142 
01143   // clear both the map themselves and the flag bit indicating
01144   // whether the map is filled (used by lazy building)
01145 
01146 
01147   if (purgeMask & kPixelMaps) {
01148     fBuiltMaps &= ~kPixelMaps;
01149     fStripEndToSpot.clear();
01150     fPixelToStripEnd.clear();
01151     fPixelToChannel.clear();
01152     fChannelToPixel.clear();
01153   }
01154 
01155   if (purgeMask & kReadoutMap) {
01156     fBuiltMaps &= ~kReadoutMap;
01157     fChannelToReadout.clear();
01158     fSpecialDescript.clear();
01159   }
01160 
01161   if (purgeMask & kPinDiodeMap) {
01162     fBuiltMaps &= ~kPinDiodeMap;
01163     fChannelToPinDiode.clear();
01164   }
01165 
01166   if (purgeMask & kLedMaps) {
01167     fBuiltMaps &= ~kLedMaps;
01168     fPinDiodeToLed.clear();
01169     fStripEndToLed.clear();
01170   }
01171 
01172   if (purgeMask & kAllVectors) {
01173     fAllStripEnds.clear();
01174     fAllEastEnds.clear();
01175     fAllWestEnds.clear();
01176     fAllStrips.clear();
01177     fAllTubes.clear();
01178     fAllPixels.clear();
01179     fAllSpots.clear();
01180     fAllChannels.clear();
01181     fAllPinDiodes.clear();
01182     fAllLeds.clear();
01183   }
01184 
01185 }
01186 
01187 //_____________________________________________________________________________
01188 void Plexus::TrimVldRange(const char* tblName,
01189                           const DbiValidityRec* dbivrec) const
01190 { 
01191    // Trim VldRange based on DbiValidityRec range info
01192 
01193    if (dbivrec) {
01194       fVldRange.TrimTo(dbivrec->GetVldRange());
01195    } else {
01196       MSG("Plex",Msg::kWarning) 
01197          << "No DbiValidityRec for table " << tblName << endl;
01198    }
01199 }
01200 
01201 //_____________________________________________________________________________
01202 void Plexus::ValidateConsistency() const
01203 { 
01204    // Test tables for internal consistency
01205 
01206    typedef multimap<RawChannelId,PlexPixelSpotId>::const_iterator  rc2p_itr;
01207 
01208    RawChannelId rcid_last;
01209    rc2p_itr rcitr = fChannelToPixel.begin();
01210    rc2p_itr rcend = fChannelToPixel.end();
01211    while (rcitr != rcend) {
01212      RawChannelId rcid = rcitr->first;
01213      if (rcid != rcid_last) { // RawChannelId->PixelSpot is multimap
01214        PlexSEIdAltL altl = GetSEIdAltL(rcid,0,0,0);
01215        Bool_t printit = false;
01216 
01217        // make sure that far detector altl has 8 entries
01218        if (rcid.GetDetector() == Detector::kFar) {
01219          if ( altl.size() == 0 ) printit = true;
01220          else {
01221            PlexPlaneId plnid = altl.GetBestSEId();
01222            if ( altl.size() != 8 && !plnid.IsVetoShield() ) {
01223              MSG("Plex",Msg::kInfo) 
01224                << endl
01225                << " far detector PlexSEIdAltL.size() " << altl.size() 
01226                << " != 8" << endl;
01227              printit = true;
01228            }
01229          }
01230        }
01231 
01232        // test the alternative list for consistency
01233        Int_t error = altl.GetError(false);
01234        if (error) {
01235 
01236          printit = true;
01237          if (altl.empty()) {
01238            MSG("Plex",Msg::kInfo) 
01239              << " PlexSEIdAltL empty" 
01240              << endl;
01241            printit = false;
01242          }
01243          else {
01244            string etxt = " bad: ";
01245            if (error & PlexSEIdAltL::kBadDetector)  etxt += "detector ";
01246            if (error & PlexSEIdAltL::kBadEnd)       etxt += "end ";
01247            if (error & PlexSEIdAltL::kBadPlane)     etxt += "plane ";
01248            if (error & PlexSEIdAltL::kBadPlaneView) etxt += "view ";
01249            if (error & PlexSEIdAltL::kUnchecked)    etxt = " unchecked? ";
01250            MSG("Plex",Msg::kInfo) 
01251              << endl
01252              << " PlexSEIdAltL consistency error 0x"
01253              << hex << error << dec << etxt << endl;
01254          }
01255 
01256          pair<rc2p_itr,rc2p_itr> rc2p_limits =
01257            fChannelToPixel.equal_range(rcid);
01258          rc2p_itr next = rc2p_limits.first;  // range means 2nd is 1 too far
01259          if (++next == rc2p_limits.second) {
01260            // RawChannel only maps to one pixel
01261            MSG("Plex",Msg::kInfo)
01262              << " rcid " << rcid.AsString("ec") 
01263              << " single pixel: "
01264              << rc2p_limits.first->second.AsString("p") << endl;
01265          }
01266          else {
01267            // RawChannel maps to multiple pixels
01268            MSG("Plex",Msg::kInfo) 
01269              << " rcid " << rcid.AsString("ec") 
01270              << " pixel list: " << endl;
01271            for (rc2p_itr irc2p  = rc2p_limits.first;
01272                          irc2p != rc2p_limits.second; ++irc2p) {
01273              MSG("Plex",Msg::kInfo) 
01274                << "   " << irc2p->second.AsString("p") << endl;
01275            }
01276          }
01277 
01278        }
01279 
01280        if (printit) {
01281          // MSG("Plex",Msg::kInfo) << endl;
01282          altl.Print();
01283        }
01284 
01285      } // if new rcid
01286      // move along
01287      ++rcitr;
01288      rcid_last = rcid;
01289    } // while
01290 
01291    // test PinDiodes
01292    const std::vector<PlexPinDiodeId>& allpindiodes = GetAllPinDiodes();
01293    //if ( allpindiodes.size() != fChannelToPinDiode.size() )
01294    //  MSG("Plex",Msg::kInfo) 
01295    //    << "AllPinDiodes.size() = " << allpindiodes.size()
01296    //    << " vs. fChannelToPinDiode.size() = " << fChannelToPinDiode.size()
01297    //    << endl;
01298    if ( allpindiodes.size() != fPinDiodeToLed.size() )
01299      MSG("Plex",Msg::kInfo) 
01300        << "AllPinDiodes.size() = " << allpindiodes.size()
01301        << " vs. fPinDiodeToLed.size() = " << fPinDiodeToLed.size()
01302        << endl;
01303 
01304    // test Leds
01305    //const std::vector<PlexLedId>& allleds = GetAllLeds();
01306    //if ( allleds.size() != fStripEndToLed.size() )
01307    //  MSG("Plex",Msg::kInfo) 
01308    //    << "AllLeds.size() = " << allleds.size()
01309    //    << " vs. fStripEndToLed.size() = " << fStripEndToLed.size()
01310    //    << endl;
01311    //if ( allled.size() != fPinDiodeToLed.size() )
01312    //  MSG("Plex",Msg::kInfo) 
01313    //    << "AllLeds.size() = " << allleds.size()
01314    //    << " vs. fPinDiodeToLed.size() = " << fPinDiodeToLed.size()
01315    //    << endl;
01316 
01317 
01318 }
01319 
01320 //_____________________________________________________________________________

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