00001 #include "GfxDigitList.h"
00002 #include "GfxDigitListCfg.h"
00003 #include "GfxProxy.h"
00004 #include "GfxDigitListMenu.h"
00005 #include "MultiPage.h"
00006 #include "ViewState.h"
00007
00008 #include <Midad/Base/PageDisplay.h>
00009 #include <Midad/Base/Mint.h>
00010 #include <Midad/Base/Rainbow.h>
00011 #include <Midad/Base/DigitText.h>
00012 #include <Midad/Util/Range.h>
00013 #include <Midad/Gui/GuiSlider.h>
00014
00015
00016 #include <Conventions/Munits.h>
00017
00018 #include <DataUtil/CDL2STL.h>
00019 using namespace DataUtil;
00020
00021 #include <CandDigit/CandDigitHandle.h>
00022 #include <CandDigit/CandDigitListHandle.h>
00023
00024 #include <Conventions/PlaneView.h>
00025
00026 #include <Plex/PlexSEIdAltL.h>
00027 #include <Plex/PlexSEIdAltLItem.h>
00028 #include <Plex/PlexStripEndId.h>
00029 #include <Record/RecArrayAllocator.h>
00030
00031 #include <MessageService/MsgService.h>
00032 CVSID("$Id: GfxDigitList.cxx,v 1.14 2003/10/27 20:32:16 bv Exp $");
00033
00034 #include <Buttons.h>
00035 #include <TClonesArray.h>
00036
00037 #include <sigc++/sigc++.h>
00038 #include <sigc++/class_slot.h>
00039 using namespace SigC;
00040
00041 #include <iostream>
00042 #include <string>
00043 using namespace std;
00044
00045
00046 GfxProxy<GfxDigitList>
00047 gsGfxDigitListProxy("DigitList", new GfxDigitListMenu());
00048
00049
00054 GfxDigitList::GfxDigitList()
00055 : fCfg(0)
00056 , fColorRange(0)
00057 , fMultiPage(0)
00058 , fMint(0)
00059 , fDigitCA(0)
00060 , fHideDigits(false)
00061 {
00062 fCfg = new GfxDigitListCfg();
00063 fCfg->modified_signal.connect
00064 (SigC::slot_class(*this,&GfxDigitList::ReConfigure));
00065
00066 RecArrayAllocator& a = RecArrayAllocator::Instance();
00067 fDigitCA = a.GetArray("GfxDigit");
00068 }
00069
00070 GfxDigitList::~GfxDigitList()
00071 {
00072 if (!fDigitCA) return;
00073 RecArrayAllocator& a = RecArrayAllocator::Instance();
00074 a.ReleaseArray(fDigitCA);
00075 fDigitCA = 0;
00076 }
00077
00078 void GfxDigitList::Init(PageDisplay& pd, MultiPage& mp)
00079 {
00080 fColorRange = &mp.GetColorRangeControl(this->GetPlaneView()).GetRange();
00081 ViewState* vs = this->GetViewState();
00082 vs->color_semantic.connect(slot_class(*this,&GfxDigitList::ReConfigure));
00083 vs->spatial_metric.connect(slot_class(*this,&GfxDigitList::ReConfigure));
00084 fPageDisplay = &pd;
00085 fMultiPage = ∓
00086 }
00087
00088 static bool select_digit(const CandDigitHandle* cdh,
00089 PlaneView::PlaneView_t view,
00090 RangeDouble* time_range)
00091 {
00092 if (!cdh) return false;
00093 return cdh->GetPlexSEIdAltL().GetPlaneView() == view
00094 && time_range->InRange(cdh->GetPlexSEIdAltL().GetBestItem().GetTime());
00095 }
00096
00097 void GfxDigitList::Configure(Mint& mint)
00098 {
00099 fMint = &mint;
00100
00101 const CandDigitListHandle* cslh = mint.GetDigits();
00102 if (!cslh || !cslh->GetNDaughters()) {
00103 this->ClearDigitList();
00104 return;
00105 }
00106
00107 RangeDouble& time_range =
00108 fPageDisplay->GetTimeSlider().GetRangeCtrl().GetRange();
00109
00110 Mint::DigitVector_t sv = CDL2STLvector<CandDigitHandle>(*cslh);
00111
00112 Mint::DigitVector_t::iterator it, first = sv.begin(), middle, last = sv.end();
00113
00114 Slot1<bool,const CandDigitHandle*> s =
00115 bind(slot(select_digit),this->GetPlaneView(),&time_range);
00116 middle = std::partition(first,last,s);
00117
00118 this->ClearDigitList();
00119
00120 bool show_mux = this->GetViewState()->ShowMultiplex();
00121
00122 int count = 0;
00123 for (it = first; it != middle; ++it) {
00124 const PlexSEIdAltL& altl = (*it)->GetPlexSEIdAltL();
00125 if (show_mux) {
00126 int siz = altl.size();
00127 for (int ind = 0; ind < siz; ++ind) {
00128 int last = fDigitCA->GetLast()+1;
00129 new ((*fDigitCA)[last]) GfxDigit(**it,altl[ind],*this);
00130 GfxDigit* gs = dynamic_cast<GfxDigit*>(fDigitCA->UncheckedAt(last));
00131 fDigits.push_back(gs);
00132 count++;
00133 }
00134 }
00135 else {
00136 const PlexSEIdAltLItem& item = altl.GetBestItem();
00137 if (item.IsZeroWeight()) continue;
00138 int last = fDigitCA->GetLast()+1;
00139 new ((*fDigitCA)[last]) GfxDigit(**it,item,*this);
00140 GfxDigit* gs = dynamic_cast<GfxDigit*>(fDigitCA->UncheckedAt(last));
00141 fDigits.push_back(gs);
00142 count++;
00143 }
00144 }
00145 MSG("Midad",Msg::kVerbose) << "Configure: Count = " << count << endl;
00146 this->ReConfigure();
00147
00148 }
00149
00150 void GfxDigitList::ReConfigure(void)
00151 {
00152 if (!fMint) return;
00153 if (fHideDigits) return;
00154
00155
00156 int count = 0;
00157 GfxDigitVector_t::iterator it, done = fDigits.end();
00158 for (it = fDigits.begin(); it != done; ++it) {
00159 (*it)->Configure();
00160 count++;
00161 }
00162 MSG("Midad",Msg::kVerbose) << "Reconfig: Count = " << count << endl;
00163 }
00164
00165 void GfxDigitList::Draw(Option_t *option)
00166 {
00168 GfxDigitVector_t::iterator it, done = fDigits.end();
00169 for (it = fDigits.begin(); it != done; ++it)
00170 (*it)->Draw(option);
00171 }
00172
00173
00174
00175 void GfxDigitList::ClearDigitList()
00176 {
00177 fDigits.clear();
00178 fDigitCA->Clear("C");
00179 }
00180
00181 void GfxDigitList::ExecuteEventDigit(int event, int , int ,
00182 GfxDigit* gfx_digit)
00183 {
00184 switch (event) {
00185 case kMouseEnter: {
00186 PlexStripEndId seid;
00187 const PlexSEIdAltLItem* itm;
00188 const CandDigitHandle& cdh = gfx_digit->GetDigit();
00189 const PlexSEIdAltLItem& item = gfx_digit->GetItem();
00190
00191 itm = &item;
00192 if (itm) {
00193 seid = itm->GetSEId();
00194 }
00195 else {
00196 const PlexSEIdAltL& altl = cdh.GetPlexSEIdAltL();
00197 PlexStripEndId best = altl.GetBestSEId();
00198
00199 altl.SetFirst();
00200 while(altl.IsValid()) {
00201 seid = altl.GetCurrentSEId();
00202 if (seid == best) {
00203 const PlexSEIdAltLItem& curr = altl.GetCurrentItem();
00204 itm = &curr;
00205 }
00206 altl.Next();
00207 }
00208 }
00209
00210 const char* s = Form("Digit: strip=%d, plane=%d, charge=%.1f, t=%.1f ns (%s)",
00211 seid.GetStrip(),
00212 seid.GetPlane(),
00213 itm->GetPE(),
00214 itm->GetTime()/Munits::ns, seid.AsString());
00215 text_info.emit(s);
00216
00217 DigitText* dt = fPageDisplay->GetDigitText();
00218 if (dt) {
00219 dt->Clear();
00220 dt->AddCandDigitText(cdh);
00221 }
00222 if (fMint) {
00223 fMint->SetPickedDigit(cdh);
00224 }
00225
00226 break;
00227 }
00228 default:
00229 break;
00230 }
00231 }
00232
00233 bool GfxDigitList::DigitMasked(const CandDigitHandle& cdh) const
00234 {
00235 if (!fColorRange) return false;
00236
00237 double val=0;
00238 switch (this->GetViewState()->GetColorSemantic()) {
00239 case ViewState::color_is_time:
00240 val = cdh.GetTime();
00241 break;
00242 case ViewState::color_is_charge:
00243 val = cdh.GetCharge();
00244 break;
00245 default:
00246 return false;
00247 break;
00248 }
00249
00250 bool ret = fColorRange->InRange(val);
00251 return !ret;
00252 }
00253
00254 bool GfxDigitList::DigitMasked(const CandDigitHandle& ,
00255 const PlexSEIdAltLItem& itm) const
00256 {
00257 if (!fColorRange) return false;
00258
00259 double val=0;
00260 switch (this->GetViewState()->GetColorSemantic()) {
00261 case ViewState::color_is_time:
00262 val = itm.GetTime();
00263 break;
00264 case ViewState::color_is_charge:
00265 val = itm.GetPE();
00266 break;
00267 default:
00268 return false;
00269 break;
00270 }
00271
00272 bool ret = fColorRange->InRange(val);
00273 return !ret;
00274 }
00275
00276 int GfxDigitList::GetDigitColor(const CandDigitHandle& cdh) const
00277 {
00278 if (!fColorRange) return false;
00279
00280 static Rainbow rainbow;
00281
00282 if (this->DigitMasked(cdh)) return 0;
00283
00284 double val=0;
00285 switch (this->GetViewState()->GetColorSemantic()) {
00286 case ViewState::color_is_time:
00287 val = cdh.GetTime();
00288 break;
00289 case ViewState::color_is_charge:
00290 val = cdh.GetCharge();
00291 break;
00292 default:
00293 return 0;
00294 break;
00295 }
00296
00297 return rainbow.GetRelativeColor(fColorRange->Relative(val));
00298 }
00299
00300 int GfxDigitList::GetDigitColor(const CandDigitHandle& cdh,
00301 const PlexSEIdAltLItem& itm) const
00302 {
00303 if (!fColorRange) return false;
00304
00305 static Rainbow rainbow;
00306
00307 if (this->DigitMasked(cdh,itm)) return 0;
00308
00309 double val=0;
00310 switch (this->GetViewState()->GetColorSemantic()) {
00311 case ViewState::color_is_time:
00312 val = itm.GetTime();
00313 break;
00314 case ViewState::color_is_charge:
00315 val = itm.GetPE();
00316 break;
00317 default:
00318 return 0;
00319 break;
00320 }
00321
00322 return rainbow.GetRelativeColor(fColorRange->Relative(val));
00323 }
00324 void GfxDigitList::HideDigits(bool hide)
00325 {
00326 fHideDigits = hide;
00327 this->ReConfigure();
00328 fMultiPage->UpdateCanvas();
00329 }