00001 #include "CheezyPage.h"
00002
00003 #include <Midad/Base/Mint.h>
00004 #include <Midad/Base/Jint.h>
00005 #include <Midad/Base/PageProxy.h>
00006 #include <Midad/Base/PageDisplay.h>
00007 #include <Midad/Base/RegistryGui.h>
00008
00009 #include <Midad/Gui/GuiBox.h>
00010 #include <Midad/Gui/GuiMenu.h>
00011 #include <Midad/Gui/GuiButton.h>
00012 #include <Midad/Gui/GuiMainWindow.h>
00013
00014 #include <DataUtil/GetCandidate.h>
00015 #include <DataUtil/CDL2STL.h>
00016 #include <RerootExodus/CheezyDisplay.h>
00017 #include <MinosObjectMap/MomNavigator.h>
00018 #include <Plex/PlexStripEndId.h>
00019 #include <CandData/CandRecord.h>
00020 #include <CandDigit/CandDigitHandle.h>
00021 #include <CandDigit/CandDigitListHandle.h>
00022 #include <Record/RecMinos.h>
00023 #include <Record/RecMinosHdr.h>
00024
00025 #include <TCanvas.h>
00026
00027
00028 #include <MessageService/MsgService.h>
00029 CVSID("$Id: CheezyPage.cxx,v 1.5 2004/08/26 22:01:32 avva Exp $");
00030
00031
00032 #include <sigc++/sigc++.h>
00033 #include <sigc++/class_slot.h>
00034 using namespace SigC;
00035
00036 #include <cassert>
00037
00038
00039
00040
00041
00042
00043 static PageProxy<CheezyPage> gsCheezyPageProxy("Cheezy");
00044
00045 CheezyPage::CheezyPage()
00046 : fDisplay(0)
00047 , fMint(0)
00048 , fListPlex("canddigitlist")
00049 , fListTruth("candmcdigitlist")
00050 , fDrawEmpty(false)
00051 {
00052 this->InitConfig();
00053 }
00054 CheezyPage::~CheezyPage()
00055 {
00056 if (fDisplay) delete fDisplay; fDisplay=0;
00057 }
00058
00059
00060 TObject* CheezyPage::Init(Mint* mint, PageDisplay* pd, GuiBox& box)
00061 {
00062
00063 this->CanvasPage::Init(mint,pd,box);
00064
00065
00066 fMint = mint;
00067
00068
00069 TCanvas& canvas = this->GetCanvas();
00070
00071
00072 fDisplay = new CheezyDisplay("CheezyPage","CheezyPage display", &canvas);
00073
00074
00075 this->BuildMenus(pd);
00076
00077
00078
00079
00080 return 0;
00081 }
00082
00083 void CheezyPage::Clear()
00084 {
00085 fDisplay->ClearLists();
00086 }
00087
00088 void CheezyPage::Update()
00089 {
00090 TCanvas& canvas = this->GetCanvas();
00091 canvas.cd();
00092
00093 const MomNavigator* mom = fMint->GetJint().GetMom();
00094
00095
00096
00097
00098 RecMinos *rec = dynamic_cast<RecMinos *>(mom->GetFragment("RecMinos"));
00099 if ( ! rec ) {
00100 MSG("Cheezy", Msg::kWarning) << "CheezyPage: No RecMinos\n";
00101 return;
00102 }
00103
00104 this->ApplyConfig();
00105
00106 VldContext vldc = rec->GetHeader()->GetVldContext();
00107 fDisplay->SetVldContext(vldc);
00108
00109
00110
00111
00112
00113
00114
00115
00116 int ndigits = 0;
00117 const char* names[2] = {
00118 fListTruth.c_str(),
00119 fListPlex.c_str(),
00120 };
00121 bool is_mc[2] = { true, false };
00122 for (int n=0; n<2; ++n) {
00123 const CandDigitListHandle *cdlh =
00124 DataUtil::GetCandidate<CandDigitListHandle>
00125 (mom,"CandDigitListHandle",names[n]);
00126 if (!cdlh) {
00127 MSG("Cheezy", Msg::kWarning)
00128 << "CheezyPage: No CandDigitListHandle named "
00129 << names[n]
00130 << endl;
00131 continue;
00132 }
00133
00134 vector<const CandDigitHandle*> dv =
00135 DataUtil::CDL2STLvector<const CandDigitHandle>(*cdlh);
00136 int siz = dv.size();
00137 ndigits += siz;
00138 for (int ind = 0; ind < siz; ++ind) {
00139
00140 PlexSEIdAltL altlist = dv[ind]->GetPlexSEIdAltL();
00141 fDisplay->AddSEIdAltL(altlist,is_mc[n]);
00142 }
00143 }
00144
00145
00146
00147 if (ndigits || fDrawEmpty) fDisplay->Draw();
00148
00149 return;
00150 }
00151
00152
00153 void CheezyPage::BuildMenus(PageDisplay* pd)
00154 {
00155
00156
00157
00158
00159
00160
00161 GuiMenuBar& mb = pd->GetMenuBar();
00162 GuiMenu* pm = mb.GetMenu("Pages");
00163 assert(pm);
00164
00165
00166 GuiMenu* mymenu = manage(new GuiMenu);
00167 pm->Add("Cheezy",*mymenu);
00168
00169
00170
00171
00172
00173
00174 mymenu->Add("Configure",slot_class(*this,&CheezyPage::SpawnConfigurator));
00175
00176 }
00177
00178 void CheezyPage::Configure(const Registry& reg)
00179 {
00180 fConfig = reg;
00181 }
00182
00183
00184 void CheezyPage::InitConfig()
00185 {
00186 Registry r;
00187 r.Set("ListPlex",fListPlex.c_str());
00188 r.Set("ListTruth",fListTruth.c_str());
00189 r.Set("DrawEmpty",0);
00190 r.Set("DrawTruth",1);
00191 r.Set("OnlyBest",0);
00192 r.Set("WgtThresh",-1);
00193 fConfig = r;
00194
00195 Registry possibles;
00196
00197 Registry list_possibles;
00198 list_possibles.Set("MC list","candmcdigitlist");
00199 list_possibles.Set("Data list","canddigitlist");
00200
00201 list_possibles.SetName("Possible ListPlex types");
00202 possibles.Set("ListPlex",list_possibles);
00203 list_possibles.SetName("Possible ListTruth types");
00204 possibles.Set("ListTruth",list_possibles);
00205
00206 Registry tf_possibles;
00207 tf_possibles.Set("true",1);
00208 tf_possibles.Set("false",0);
00209
00210 tf_possibles.SetName("Possible DrawEmpty values");
00211 possibles.Set("DrawEmpty",tf_possibles);
00212 tf_possibles.SetName("Possible DrawTruth values");
00213 possibles.Set("DrawTruth",tf_possibles);
00214 tf_possibles.SetName("Possible OnlyBest values");
00215 possibles.Set("OnlyBest",tf_possibles);
00216
00217 fConfigPossibles = possibles;
00218 }
00219
00220 void CheezyPage::ApplyConfig()
00221 {
00222 const char* str = 0;
00223 int num = 0;
00224 double real = 0.0;
00225
00226 if (fConfig.Get("ListPlex",str)) fListPlex = str;
00227 if (fConfig.Get("ListTruth",str)) fListTruth = str;
00228 if (fConfig.Get("DrawEmpty",num)) fDrawEmpty = num != 0;
00229
00230
00231 if (!fDisplay) return;
00232
00233 if (fConfig.Get("DrawTruth",num)) fDisplay->SetDrawTruth(num != 0);
00234 if (fConfig.Get("OnlyBest",num)) fDisplay->SetDrawOnlyBest(num != 0);
00235 if (fConfig.Get("WgtThresh",real)) fDisplay->SetWgtThresh(real);
00236 }
00237
00238
00239 static void apply_reg_gui(CheezyPage* cp, RegistryGui* rg)
00240 {
00241 cp->Configure(rg->GetRegistry());
00242 cp->Update();
00243 }
00244
00245 void CheezyPage::SpawnConfigurator(void)
00246 {
00247 GuiMainWindow* mw = new GuiMainWindow(100,300);
00248 RegistryGui* rg = manage(new RegistryGui(*mw));
00249 mw->Add(*rg);
00250
00251 GuiBox* box = manage(new GuiBox(*mw,kHorizontalFrame));
00252 box->SetLayoutHints(kLHintsExpandX);
00253 mw->Add(*box);
00254
00255 GuiTextButton* apply = manage(new GuiTextButton(*box,"Apply"));
00256 box->Add(*apply);
00257 apply->clicked.connect(bind(slot(apply_reg_gui),this,rg));
00258
00259 GuiTextButton* okay = manage(new GuiTextButton(*box,"Okay"));
00260 box->Add(*okay);
00261 okay->clicked.connect(bind(slot(apply_reg_gui),this,rg));
00262 okay->clicked.connect(slot(*mw,&GuiMainWindow::SendCloseMessage));
00263
00264 GuiTextButton* cancel = manage(new GuiTextButton(*box,"Cancel"));
00265 box->Add(*cancel);
00266 cancel->clicked.connect(slot(*mw,&GuiMainWindow::SendCloseMessage));
00267
00268 rg->SetRegistry(fConfig);
00269 rg->SetPossibles(fConfigPossibles);
00270
00271 mw->ShowAll();
00272 mw->ConnectClose(true);
00273 mw->Resize(mw->GetDefaultWidth(),mw->GetDefaultHeight());
00274
00275 }