00001 #include "GfxStripList.h"
00002 #include "GfxStripListCfg.h"
00003 #include "GfxProxy.h"
00004 #include "GfxStripListMenu.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 <RecoBase/CandStripHandle.h>
00022 #include <RecoBase/CandStripListHandle.h>
00023 #include <Record/RecArrayAllocator.h>
00024
00025 #include <Buttons.h>
00026 #include <TClonesArray.h>
00027
00028 #include <sigc++/sigc++.h>
00029 #include <sigc++/class_slot.h>
00030 using namespace SigC;
00031
00032 #include <iostream>
00033 #include <string>
00034 using namespace std;
00035
00036
00037 GfxProxy<GfxStripList>
00038 gsGfxStripListProxy("StripList", new GfxStripListMenu());
00039
00040
00045 GfxStripList::GfxStripList()
00046 : fCfg(0)
00047 , fColorRange(0)
00048 , fMultiPage(0)
00049 , fMint(0)
00050 , fStripCA(0)
00051 , fHideStrips(false)
00052 {
00053 fCfg = new GfxStripListCfg();
00054 fCfg->modified_signal.connect
00055 (slot_class(*this,&GfxStripList::ReConfigure));
00056
00057 RecArrayAllocator& a = RecArrayAllocator::Instance();
00058 fStripCA = a.GetArray("GfxStrip");
00059 }
00060
00061 GfxStripList::~GfxStripList()
00062 {
00063 RecArrayAllocator& a = RecArrayAllocator::Instance();
00064 if (fStripCA) { a.ReleaseArray(fStripCA); fStripCA = 0; }
00065 }
00066
00067 void GfxStripList::Init(PageDisplay& pd, MultiPage& mp)
00068 {
00069 fColorRange = &mp.GetColorRangeControl(this->GetPlaneView()).GetRange();
00070 ViewState* vs = this->GetViewState();
00071 vs->color_semantic.connect(slot_class(*this,&GfxStripList::ReConfigure));
00072 vs->spatial_metric.connect(slot_class(*this,&GfxStripList::ReConfigure));
00073 fPageDisplay = &pd;
00074 fMultiPage = ∓
00075 }
00076
00077 static bool select_strip(const CandStripHandle* csh,
00078 PlaneView::PlaneView_t view,
00079 RangeDouble* time_range)
00080 {
00081 if (!csh) return false;
00082 return csh->GetPlaneView() == view && time_range->InRange(csh->GetTime());
00083 }
00084
00085 void GfxStripList::Configure(Mint& mint)
00086 {
00087 fMint = &mint;
00088
00089 const CandStripListHandle* cslh = mint.GetStrips();
00090 if (!cslh) {
00091 this->ClearStripList();
00092 return;
00093 }
00094
00095 RangeDouble& time_range =
00096 fPageDisplay->GetTimeSlider().GetRangeCtrl().GetRange();
00097
00098 Mint::StripVector_t sv = CDL2STLvector<CandStripHandle>(*cslh);
00099
00100 Mint::StripVector_t::iterator it, first = sv.begin(), middle, last = sv.end();
00101 Slot1<bool,const CandStripHandle*> s =
00102 bind(slot(select_strip),this->GetPlaneView(),&time_range);
00103 middle = std::partition(first,last,s);
00104
00105 this->ClearStripList();
00106
00107 for (it = first; it != middle; ++it) {
00108 int last = fStripCA->GetLast()+1;
00109 new ((*fStripCA)[last]) GfxStrip(**it,*this);
00110 GfxStrip* gs = dynamic_cast<GfxStrip*>(fStripCA->UncheckedAt(last));
00111 fStrips.push_back(gs);
00112 }
00113 this->ReConfigure();
00114
00115 }
00116
00117 void GfxStripList::ReConfigure(void)
00118 {
00119 if (!fMint) return;
00120 if (fHideStrips) return;
00121
00122
00123 GfxStripVector_t::iterator it, done = fStrips.end();
00124 for (it = fStrips.begin(); it != done; ++it) (*it)->Configure();
00125 }
00126
00127 void GfxStripList::Draw(Option_t *option)
00128 {
00130 GfxStripVector_t::iterator it, done = fStrips.end();
00131 for (it = fStrips.begin(); it != done; ++it)
00132 (*it)->Draw(option);
00133 }
00134
00135
00136
00137 void GfxStripList::ClearStripList()
00138 {
00139 fStrips.clear();
00140 fStripCA->Clear("C");
00141 }
00142
00143 void GfxStripList::ExecuteEventStrip(int event, int , int ,
00144 GfxStrip* gfx_strip)
00145 {
00146 switch (event) {
00147 case kMouseEnter: {
00148 const CandStripHandle& csh = gfx_strip->GetStrip();
00149 PlexStripEndId seid = csh.GetStripEndId();
00150 const char* s = Form("Strip: %d digit%s, plane=%d, demux charge=%.1f, t0=%.1f ns, <t>=%.1f ns (%s)",
00151 csh.GetNDigit(), csh.GetNDigit() == 1 ? "" : "s",
00152 csh.GetPlane(),
00153 csh.GetCharge(), csh.GetBegTime()/Munits::ns,
00154 csh.GetTime()/Munits::ns, seid.AsString());
00155 text_info.emit(s);
00156
00157 vector<const CandDigitHandle*> dv = CDL2STLvector<CandDigitHandle>(csh);
00158 int siz = dv.size();
00159 if (!siz) break;
00160
00161 DigitText* dt = fPageDisplay->GetDigitText();
00162 if (dt) {
00163 dt->Clear();
00164 for (int ind=0; ind < siz; ++ind)
00165 dt->AddCandDigitText(*dv[ind]);
00166 }
00167 if (fMint) {
00168 fMint->SetPickedStrip(csh);
00169 fMint->SetSelectedDigits(dv);
00170 }
00171
00172 break;
00173 }
00174 default:
00175 break;
00176 }
00177 }
00178
00179 bool GfxStripList::StripMasked(const CandStripHandle& csh) const
00180 {
00181 if (!fColorRange) return false;
00182
00183 double val=0;
00184 switch (this->GetViewState()->GetColorSemantic()) {
00185 case ViewState::color_is_time:
00186 val = csh.GetTime();
00187 break;
00188 case ViewState::color_is_charge:
00189 val = csh.GetCharge();
00190 break;
00191 default:
00192 return false;
00193 break;
00194 }
00195
00196 bool ret = fColorRange->InRange(val);
00197 return !ret;
00198 }
00199
00200 int GfxStripList::GetStripColor(const CandStripHandle& csh) const
00201 {
00202 if (!fColorRange) return false;
00203
00204 static Rainbow rainbow;
00205
00206 if (this->StripMasked(csh)) return 0;
00207
00208 double val=0;
00209 switch (this->GetViewState()->GetColorSemantic()) {
00210 case ViewState::color_is_time:
00211 val = csh.GetTime();
00212 break;
00213 case ViewState::color_is_charge:
00214 val = csh.GetCharge();
00215 break;
00216 default:
00217 return 0;
00218 break;
00219 }
00220 return rainbow.GetRelativeColor(fColorRange->Relative(val));
00221 }
00222 void GfxStripList::HideStrips(bool hide)
00223 {
00224 fHideStrips = hide;
00225 this->ReConfigure();
00226 fMultiPage->UpdateCanvas();
00227 }