6 #include "nutools/EventDisplayBase/ParameterSetEditDialog.h" 13 #include "TGTableLayout.h" 16 #include "TGTextEntry.h" 17 #include "TGListBox.h" 18 #include "TGDoubleSlider.h" 20 #include "nutools/EventDisplayBase/NavState.h" 21 #include "nutools/EventDisplayBase/ServiceTable.h" 28 static const unsigned int kWidth = 500*11/10;
29 static const unsigned int kHeight = 500*11/10;
31 static const unsigned int kRowH = 18;
48 #define GUITAG static const std::string 57 static const std::vector<std::string>
gsGUITAG = {
72 TGHorizontalFrame* lhs,
73 TGHorizontalFrame* rhs,
90 std::vector<std::string>
values;
99 for (
unsigned int i=0; i<values.size(); ++i) {
101 if (i+1<values.size())
fValue +=
",";
114 fLeftLH =
new TGLayoutHints(kLHintsLeft, 1,1,0,0);
115 fRightLH =
new TGLayoutHints(kLHintsRight,1,1,0,0);
117 fLabel =
new TGTextButton(lhs,
120 TGButton::GetDefaultGC()(),
121 TGTextButton::GetDefaultFontStruct(),
125 fLabel->SetTextJustify(kTextRight);
176 std::vector<std::string>& choice,
177 std::vector<std::string>&
value,
200 doc =
"See .fcl file for documentation...";
231 value = p.
get< std::vector<std::string> >(valkey);
233 if (value.size()==0) value.push_back(
"");
240 std::vector< std::vector <std::string> > vv;
241 vv = p.
get<std::vector<std::vector<std::string> > >(valkey);
255 for (i=0; i<vv.size(); ++i) {
258 for (j=0; j<vv[i].size(); ++j) {
260 if (j+2<vv[i].
size()) s +=
",";
265 if (vv.size()==0) value.push_back(
"[[]]");
278 MF_LOG_ERROR(
"ParameterSetEditDialog") <<
"Failed to parse " << key
293 std::vector<std::string>& choice)
299 size_t icolon = guitag.find(
':');
300 if (icolon == std::string::npos) frame = guitag;
301 else frame = guitag.substr(0,icolon);
307 size_t icomma = icolon;
309 while (icomma!=std::string::npos) {
311 epos = guitag.find(
',',spos);
322 for(
unsigned int i=0; i<gsGUITAG.size(); ++i) {
323 if (s==gsGUITAG[i])
return true;
325 MF_LOG_ERROR(
"ParameterSetEditDialog") << s <<
" is not a legal GUI tag.";
333 const std::vector<std::string>&
value)
335 static TColor*
c = gROOT->GetColor(41);
342 "evdb::ParameterSetEditRow",
344 "TextEntryReturnPressed()");
349 for (
unsigned int i=0; i<value.size(); ++i) {
351 if ((i+1)!=value.size()) buff +=
",";
353 if (flags&kVECTOR_PARAM) buff +=
"]";
354 if (flags&kPARAMETER_SET_PARAM) buff +=
"}";
362 const std::vector<std::string>& choice,
363 const std::vector<std::string>&
value,
368 if (ismulti)
fListBox->SetMultipleSelections();
370 for (
size_t i=0; i<choice.size(); ++i) {
371 fListBox->AddEntry(choice[i].c_str(), i);
372 for (
size_t j=0; j<value.size(); ++j) {
373 if (value[j]==choice[i])
fListBox->Select(i);
377 fListBox->Connect(
"SelectionChanged()",
378 "evdb::ParameterSetEditRow",
380 "ListBoxSelectionChanged()");
381 fListBox->Connect(
"Selected(Int_t)",
382 "evdb::ParameterSetEditRow",
384 "ListBoxSelected(int)");
386 size_t h =
kRowH*choice.size();
394 const std::vector<std::string>& choice,
395 const std::vector<std::string>&
value)
397 unsigned int v = atoi(value[0].c_str());
399 for (
size_t i=0; i<choice.size(); ++i) {
400 TGRadioButton*
b =
new TGRadioButton(f, choice[i].c_str(), i);
403 b->SetTextJustify(kTextLeft);
404 b->Connect(
"Clicked()",
405 "evdb::ParameterSetEditRow",
407 "RadioButtonClicked()");
409 if (i==v) b->SetState(kButtonDown);
418 const std::vector<std::string>& choice,
419 const std::vector<std::string>&
value)
422 unsigned int v = atoi(value[0].c_str());
423 for (
size_t i=0; i<choice.size(); ++i) {
424 TGCheckButton*
b =
new TGCheckButton(f, choice[i].c_str(), i);
426 b->Connect(
"Clicked()",
427 "evdb::ParameterSetEditRow",
429 "CheckButtonClicked()");
432 if (v&mask) b->SetState(kButtonDown);
439 const std::vector<std::string>& choice,
440 const std::vector<std::string>&
value)
446 if (value.size()==1) { t = value[0]; }
447 if (value.size()==2) {
448 t =
"["; t += value[0]; t +=
","; t += value[1]; t +=
"]";
453 "evdb::ParameterSetEditRow",
455 "TextEntryReturnPressed()");
457 fSlider =
new TGDoubleHSlider(f, 100, kDoubleScaleBoth);
460 float min = atof(choice[0].c_str());
461 float max = atof(choice[1].c_str());
465 if (value.size()==1) {
466 pos1 = atof(value[0].c_str());
469 if (value.size()==2) {
470 pos1 = atof(value[0].c_str());
471 pos2 = atof(value[1].c_str());
475 fSlider->SetPosition(pos1, pos2);
477 fSlider->Connect(
"PositionChanged()",
478 "evdb::ParameterSetEditRow",
480 "SliderPositionChanged()");
492 const char* text =
fTextEntry->GetBuffer()->GetString();
494 static TColor*
c = gROOT->GetColor(1);
504 n = sscanf(text,
"[%f, %f]", &f1, &
f2);
506 n = sscanf(text,
"%f", &f1);
523 if (
fListBox->GetMultipleSelections()==0)
return;
527 fListBox->GetSelectedEntries(&selections);
530 for (
unsigned int i=0;;++i) {
531 sel = (TGLBEntry*)selections.At(i);
533 if (!isfirst)
fValue +=
",";
548 if (
fListBox->GetMultipleSelections())
return;
556 unsigned int value = 0;
557 TGButton*
b = (TGButton*)gTQSender;
558 int id = b->WidgetId();
566 sprintf(buff,
"%d", value);
580 sprintf(buff,
"%d", value);
598 int avei = rint(ave);
600 sprintf(buff,
"[%d, %d]",mni,mxi);
603 sprintf(buff,
"%d",avei);
608 sprintf(buff,
"[%.1f, %.1f]",mn,mx);
611 sprintf(buff,
"%.1f",ave);
634 std::ostringstream
s;
641 <<
"val:" <<
fValue <<
" " 642 <<
"gui:\"" <<
fGUI <<
"\" " 643 <<
"doc:\"" <<
fDOC <<
"\" " 654 unsigned int psetid) :
655 fParameterSetID(psetid),
661 fCanvasH =
new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
673 unsigned int nkey = key.size();
679 unsigned int nparam = 0;
680 for (i=0; i<nkey; ++i) {
681 if (!((key[i]==
"service_type") ||
682 (key[i]==
"module_type") ||
683 (key[i]==
"module_label"))) {
694 for (i=0, j=0; i<nkey; ++i) {
695 if (!((key[i]==
"service_type") ||
696 (key[i]==
"module_type") ||
697 (key[i]==
"module_label"))) {
699 TGHorizontalFrame* lhs =
new TGHorizontalFrame(
fContainer);
700 TGHorizontalFrame* rhs =
new TGHorizontalFrame(
fContainer);
702 TGTableLayoutHints* lhsh =
new TGTableLayoutHints(0,1,j,j+1);
703 TGTableLayoutHints* rhsh =
new TGTableLayoutHints(1,2,j,j+1);
708 fLHS. push_back(lhs);
709 fRHS. push_back(rhs);
718 fCanvas->Connect(
"ProcessedEvent(Event_t*)",
"evdb::ParameterSetEditFrame",
720 "HandleMouseWheel(Event_t*)");
730 for (i=0; i<
fRow.size(); ++i)
delete fRow[i];
733 for (i=0; i<
fRHS.size(); ++i)
delete fRHS[i];
734 for (i=0; i<
fLHS.size(); ++i)
delete fLHS[i];
749 if (event->fType != kButtonPress && event->fType != kButtonRelease)
753 if (event->fCode == kButton4 || event->fCode == kButton5) {
755 if (
fCanvas->GetContainer()->GetHeight())
756 page = Int_t(Float_t(
fCanvas->GetViewPort()->GetHeight() *
757 fCanvas->GetViewPort()->GetHeight()) /
758 fCanvas->GetContainer()->GetHeight());
761 if (event->fCode == kButton4) {
763 Int_t newpos =
fCanvas->GetVsbPosition() - page;
764 if (newpos < 0) newpos = 0;
765 fCanvas->SetVsbPosition(newpos);
767 if (event->fCode == kButton5) {
769 Int_t newpos =
fCanvas->GetVsbPosition() + page;
770 fCanvas->SetVsbPosition(newpos);
791 std::ostringstream
s;
792 for (i=0; i<
fRow.size(); ++i) {
793 s <<
fRow[i]->AsFHICL() <<
"\n";
803 TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 4, 4)
808 fButtons =
new TGHorizontalFrame(
this);
819 fApply-> Connect(
"Clicked()",
"evdb::ParameterSetEditDialog",
this,
"Apply()");
820 fCancel->Connect(
"Clicked()",
"evdb::ParameterSetEditDialog",
this,
"Cancel()");
821 fDone-> Connect(
"Clicked()",
"evdb::ParameterSetEditDialog",
this,
"Done()");
828 int which = st.
fServices[psetid].fCategory;
831 unsigned int top=0, indx=0;
834 if (i==psetid) top = indx;
836 TGCompositeFrame*
f =
fTGTab->AddTab(tabnm.c_str());
845 this->SetWindowName(
"Drawing Services");
848 this->SetWindowName(
"Experiment Services");
851 this->SetWindowName(
"Services Configuration");
854 this->MapSubwindows();
884 for (i=0; i<
fFrames.size(); ++i) {
886 unsigned int psetid =
fFrames[i]->fParameterSetID;
891 p +=
"service_type:";
910 this->SendCloseMessage();
925 n = s.find(
"DrawingOptions");
926 if (n!=std::string::npos)
return s.substr(0,n);
static constexpr int kDRAWING_SERVICE
void CheckButtonClicked()
std::vector< TGRadioButton * > fRadioButton
static void Set(int which)
void SetupListBox(TGCompositeFrame *f, const std::vector< std::string > &choice, const std::vector< std::string > &value, bool ismulti)
static const unsigned int kHeight
TGCompositeFrame * fContainer
static ServiceTable & Instance()
void TextEntryReturnPressed()
void SliderPositionChanged()
std::vector< ParameterSetEditRow * > fRow
Collection of Services used in the event display.
std::string AsFHICL() const
#define MF_LOG_ERROR(category)
TGLayoutHints * fRightLH
Align to right.
static const int kSINGLE_VALUED_PARAM
Manage all things related to colors for the event display.
ParameterSetEditFrame * fFrame
The parent frame.
void SetupSlider(TGCompositeFrame *f, const std::vector< std::string > &choice, const std::vector< std::string > &value)
std::vector< std::string > fChoice
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
void SetupTextEntry(TGCompositeFrame *f, unsigned int flags, const std::vector< std::string > &value)
static constexpr int kEXPERIMENT_SERVICE
TGLayoutHints * fLeftLH
Align to left.
std::vector< TGTableLayoutHints * > fRHSHints
static const int kNO_GUI_TAGS
static const unsigned int kRowH
std::vector< TGHorizontalFrame * > fLHS
static const int kINTEGER_PARAM
static const std::vector< std::string > gsGUITAG
T get(std::string const &key) const
static const int kPARAMETER_SET_PARAM
static void ParseGUItag(const std::string &guitag, std::string &frame, std::vector< std::string > &choice)
static int max(int a, int b)
A frame for editing a single paramter set.
static const unsigned int kRowW
~ParameterSetEditDialog()
static void UnpackParameter(const fhicl::ParameterSet &ps, const std::string &key, unsigned int &flags, std::string &tag, std::vector< std::string > &choice, std::vector< std::string > &value, std::string &gui, std::string &doc)
void ListBoxSelectionChanged()
std::vector< TGTableLayoutHints * > fLHSHints
std::vector< ServiceTableEntry > fServices
static const int kVECTOR_PARAM
TGHorizontalFrame * fButtons
static const int kHAVE_GUI_TAGS
void RadioButtonClicked()
std::vector< TGHorizontalFrame * > fRHS
std::string AsFHICL() const
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
A single row for editing a single parameter in a set.
std::vector< ParameterSetEditFrame * > fFrames
const GenericPointer< typename T::ValueType > T2 value
void SetupRadioButtons(TGCompositeFrame *f, const std::vector< std::string > &choice, const std::vector< std::string > &value)
std::vector< std::string > get_names() const
void ListBoxSelected(int id)
fhicl::ParameterSet const & GetParameterSet(unsigned int i) const
ParameterSetEditRow(ParameterSetEditFrame *frame, TGHorizontalFrame *lhs, TGHorizontalFrame *rhs, const fhicl::ParameterSet &ps, const std::string &key)
static bool IsLegalGUItag(const std::string &s)
void SetupCheckButton(TGCompositeFrame *f, const std::vector< std::string > &choice, const std::vector< std::string > &value)
void HandleMouseWheel(Event_t *event)
ParameterSetEditDialog(unsigned int psetid)
static const unsigned int kWidth
std::vector< TGCheckButton * > fCheckButton
Event finding and building.
h
training ###############################
std::string to_string() const
ParameterSetEditFrame(TGCompositeFrame *mother, unsigned int psetid)
TGTextButton * fLabel
Label on the left.
std::string TabName(const std::string &s)