00001
00002
00003
00004
00005
00006
00007
00008
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.58 2009/07/13 21:28:45 rhatcher 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 = true;
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
00054 return x.GetSEId() < y.GetSEId();
00055 }
00056 };
00057
00058
00059 Plexus::Plexus()
00060 : fRef(0), fVldRange(), fBuiltMaps(0)
00061 {
00062
00063 MSG("Plex",Msg::kVerbose) << "default ctor " << endl;
00064 }
00065
00066
00067 Plexus::Plexus(const VldContext& vldc)
00068 : fRef(0), fBuiltMaps(0)
00069 {
00070
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
00087
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
00097 BuildReadoutMap(vldc);
00098 BuildLedMaps(vldc);
00099 }
00100
00101
00102 Plexus::~Plexus()
00103 {
00104
00105
00106 }
00107
00108
00109 Bool_t Plexus::IsCompatible(const VldContext &vldc)
00110 {
00111
00112
00113 return fVldRange.IsCompatible(vldc);
00114
00115 }
00116
00117
00118 Bool_t Plexus::IsCompatible(const VldContext *vldc)
00119 {
00120
00121
00122 return fVldRange.IsCompatible(vldc);
00123
00124 }
00125
00126
00127 void Plexus::Print(Option_t *option) const
00128 {
00129
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
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
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
00195
00196 std::map<PlexStripEndId,PlexPixelSpotId>::const_iterator sepsItr =
00197 fStripEndToSpot.find(seid);
00198 if (sepsItr == fStripEndToSpot.end()) return RawChannelId();
00199
00200 return GetRawChannelId(sepsItr->second);
00201 }
00202
00203
00204 RawChannelId Plexus::GetRawChannelId(const PlexPixelSpotId& psid) const
00205 {
00206
00207
00208
00209 PlexPixelSpotId psid_nospot = psid;
00210 psid_nospot.SetSpot(0);
00211
00212
00213
00214 std::map<PlexPixelSpotId,RawChannelId>::const_iterator psrcItr =
00215 fPixelToChannel.find(psid_nospot);
00216 if (psrcItr == fPixelToChannel.end()) return RawChannelId();
00217
00218 return psrcItr->second;
00219 }
00220
00221
00222 RawChannelId Plexus::GetRawChannelId(const PlexPinDiodeId& diodeid) const
00223 {
00224
00225
00226
00227
00228
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
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
00247
00248
00249
00250
00251 PlexSEIdAltL altlist;
00252
00253
00254 RawChannelId rcid0 = rcid;
00255 rcid0.ClearModeBits();
00256
00257
00258
00259
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
00274 PlexPixelSpotId spotid = fStripEndToSpot[seid];
00275 if (fgAltLHasBrokenFibers || spotid.GetSpot() != 0) {
00276 altlist.AddStripEndId(seid,spotid,0,calib,adc,time);
00277
00278
00279
00280
00281 }
00282 else {
00283 MSG("Plex",Msg::kVerbose)
00284 << " suppress broken fiber SEID=" << seid
00285 << " " << seid.GetEncoded()
00286 << endl;
00287 }
00288 }
00289 }
00290 }
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
00303
00304
00305
00306
00307
00308 typedef multimap<PlexPixelSpotId,PlexStripEndId>::const_iterator p2se_itr;
00309
00310 PlexPixelSpotId pixelid = psid;
00311 pixelid.SetSpot(0);
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
00319
00320
00321
00322
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();
00330
00331 }
00332
00333
00334 vector<PlexPixelSpotId> Plexus::GetPixelSpotIdVector(const RawChannelId& rcid,
00335 bool uniquePixels) const
00336 {
00337
00338
00339
00340
00341
00342
00343
00344 vector<PlexPixelSpotId> pixelspots;
00345
00346 if (uniquePixels) {
00347
00348
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
00364
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
00377
00378
00379
00380 std::map<PlexStripEndId,PlexPixelSpotId>::const_iterator sepsItr =
00381 fStripEndToSpot.find(seid);
00382 if (sepsItr == fStripEndToSpot.end()) return PlexPixelSpotId();
00383
00384 return sepsItr->second;
00385 }
00386
00387
00388 PlexPinDiodeId Plexus::GetPinDiodeId(const RawChannelId& rcid) const
00389 {
00390
00391
00392
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
00403
00404
00405 if ( rcid == rcidNull ) return ReadoutType::kUnknown;
00406
00407
00408
00409
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
00421 RawChannelId rcid0 = rcid;
00422 rcid0.ClearModeBits();
00423
00424
00425
00426
00427
00428 return (ReadoutType::Readout_t)fChannelToReadout[rcid0];
00429
00430 }
00431
00432
00433 std::string Plexus::GetSpecialDescript(const RawChannelId& rcid) const
00434 {
00435
00436
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
00446
00447
00448
00449
00450 typedef map<RawChannelId,std::string>::const_iterator rc2string_itr;
00451 for (rc2string_itr irc2s = fSpecialDescript.begin();
00452 irc2s != fSpecialDescript.end(); ++ irc2s) {
00453
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
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
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
00496 if (pinid.IsHighGain()) {
00497
00498 if (!high_gain.IsValid()) high_gain = pinid;
00499 else {
00500
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
00510 if (!low_gain.IsValid()) low_gain = pinid;
00511 else {
00512
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
00532
00533 return fStripEndToLed[seid];
00534 }
00535
00536
00537 PlexLedId Plexus::GetLedId(const PlexPinDiodeId& diodeid) const
00538 {
00539
00540
00541 return fPinDiodeToLed[diodeid];
00542 }
00543
00544
00545 const std::vector<PlexStripEndId>&
00546 Plexus::GetAllStripEnds(StripEnd::StripEnd_t restrictEnd) const
00547 {
00548
00549
00550
00551
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
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
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);
00581
00582
00583
00584
00585 if ( seid == seidLast ) continue;
00586 seidLast = seid;
00587 break;
00588 default:
00589
00590 break;
00591 }
00592
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
00606
00607
00608
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
00620
00621
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
00633 case kIncludeTube: spot.SetPixel(0);
00634 case kIncludePixel: spot.SetSpot(0);
00635 default: break;
00636 }
00637
00638 spotSet.insert(spot);
00639 }
00640
00641
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
00658
00659 if ( fAllChannels.empty() ) {
00660
00661
00662
00663
00664
00665 std::set<RawChannelId> rcidSet;
00666
00667
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
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
00708
00709 if ( fAllPinDiodes.empty() ) {
00710
00711
00712
00713
00714
00715 std::set<PlexPinDiodeId> pindSet;
00716
00717
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
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
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
00746
00747 if ( fAllLeds.empty() ) {
00748
00749
00750
00751
00752
00753 std::set<PlexLedId> ledSet;
00754
00755
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
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
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
00784
00785 if (kPixelMaps & fBuiltMaps) return;
00786 fBuiltMaps |= kPixelMaps;
00787
00788 DbiCache* pstoseTblCache = 0;
00789 DbiCache* ptorcTblCache = 0;
00790
00791 {
00792
00793
00794
00795 DbiResultPtr<PlexPixelSpotToStripEnd> pstoseResPtr(vldc);
00796 DbiResultPtr<PlexPixelToRawChannel> ptorcResPtr(vldc);
00797
00798
00799 TrimVldRange("PlexPixelSpotToStripEnd",pstoseResPtr.GetValidityRec());
00800 TrimVldRange("PlexPixelToRawChannel",ptorcResPtr.GetValidityRec());
00801
00802
00803 pstoseTblCache = pstoseResPtr.TableProxy().GetCache();
00804 ptorcTblCache = ptorcResPtr.TableProxy().GetCache();
00805
00806
00807 UInt_t npstose = pstoseResPtr.GetNumRows();
00808 UInt_t nptorc = ptorcResPtr.GetNumRows();
00809
00810
00811
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
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
00848 PlexPixelSpotId pixelid = spotid;
00849 pixelid.SetSpot(0);
00850 fPixelToStripEnd.insert(make_pair(pixelid,seid));
00851 }
00852 }
00853
00854
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
00860 rcid.ClearModeBits();
00861
00862
00863
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
00893
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
00905
00906 if (kReadoutMap & fBuiltMaps) return;
00907 fBuiltMaps |= kReadoutMap;
00908
00909 DbiCache* rcrtTblCache = 0;
00910
00911 {
00912
00913
00914
00915 DbiResultPtr<PlexRawChannelReadoutType> rcrtResPtr(vldc);
00916
00917
00918 TrimVldRange("PlexRawChannelReadoutType",rcrtResPtr.GetValidityRec());
00919
00920
00921 rcrtTblCache = rcrtResPtr.TableProxy().GetCache();
00922
00923
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
00929 rcid.ClearModeBits();
00930
00931 fChannelToReadout[rcid] = rtype;
00932 fSpecialDescript[rcid] = rcrt->GetDescript();
00933 }
00934
00935
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
00942 rcid.ClearModeBits();
00943
00944
00945
00946
00947 if(fChannelToReadout.find(rcid)==fChannelToReadout.end())
00948 fChannelToReadout[rcid] = ReadoutType::kScintStrip;
00949 }
00950
00951 }
00952
00953 if ( PlexLoanPool::Instance()->PurgeDbiTableCache() ) {
00954
00955
00956 if (rcrtTblCache) rcrtTblCache->Purge();
00957 }
00958
00959
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
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
00978
00979 if (kPinDiodeMap & fBuiltMaps) return;
00980 fBuiltMaps |= kPinDiodeMap;
00981
00982 DbiCache* rc2pdTblCache = 0;
00983
00984 {
00985
00986
00987
00988 DbiResultPtr<PlexRawChannelToPinDiode> rc2pdResPtr(vldc);
00989
00990
00991 TrimVldRange("PlexRawChannelToPinDiode",rc2pdResPtr.GetValidityRec());
00992
00993
00994 rc2pdTblCache = rc2pdResPtr.TableProxy().GetCache();
00995
00996 std::set<PlexPinDiodeId> pins_seen;
00997
00998
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
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
01049
01050 if (rc2pdTblCache) rc2pdTblCache->Purge();
01051 }
01052
01053 return;
01054 }
01055
01056
01057 void Plexus::BuildLedMaps(const VldContext& vldc) const
01058 {
01059
01060
01061 if (kLedMaps & fBuiltMaps) return;
01062 fBuiltMaps |= kLedMaps;
01063
01064 DbiCache* pd2ledTblCache = 0;
01065 DbiCache* se2ledTblCache = 0;
01066
01067 {
01068
01069
01070
01071 DbiResultPtr<PlexPinDiodeToLed> pd2ledResPtr(vldc);
01072 DbiResultPtr<PlexStripEndToLed> se2ledResPtr(vldc);
01073
01074
01075 TrimVldRange("PlexPinDiodeToLed",pd2ledResPtr.GetValidityRec());
01076 TrimVldRange("PlexStripEndToLed",se2ledResPtr.GetValidityRec());
01077
01078
01079 pd2ledTblCache = pd2ledResPtr.TableProxy().GetCache();
01080 se2ledTblCache = se2ledResPtr.TableProxy().GetCache();
01081
01082
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
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
01129
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
01141
01142
01143
01144
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
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
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) {
01214 PlexSEIdAltL altl = GetSEIdAltL(rcid,0,0,0);
01215 Bool_t printit = false;
01216
01217
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
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;
01259 if (++next == rc2p_limits.second) {
01260
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
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
01282 altl.Print();
01283 }
01284
01285 }
01286
01287 ++rcitr;
01288 rcid_last = rcid;
01289 }
01290
01291
01292 const std::vector<PlexPinDiodeId>& allpindiodes = GetAllPinDiodes();
01293
01294
01295
01296
01297
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
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318 }
01319
01320