12 #include "TGDoubleSlider.h" 15 #include "TGListBox.h" 17 #include "TGTableLayout.h" 18 #include "TGTextEntry.h" 23 #include "cetlib/container_algorithms.h" 32 constexpr
unsigned int kWidth = 500 * 11 / 10;
33 constexpr
unsigned int kHeight = 500 * 11 / 10;
34 constexpr
unsigned int kRowW = kWidth - 150;
35 constexpr
unsigned int kRowH = 18;
39 constexpr
int kSINGLE_VALUED_PARAM = 1 << 0;
40 constexpr
int kVECTOR_PARAM = 1 << 1;
43 constexpr
int kHAVE_GUI_TAGS = 1 << 3;
44 constexpr
int kNO_GUI_TAGS = 1 << 4;
45 constexpr
int kINTEGER_PARAM = 1 << 5;
46 constexpr
int kPARAMETER_SET_PARAM = 1
52 std::string
const kTEXT_ENTRY =
"te";
53 std::string
const kLIST_BOX_SINGLE =
55 std::string
const kLIST_BOX_MULTI =
57 std::string
const kRADIO_BUTTONS =
"rb";
58 std::string
const kCHECK_BOX =
"cb";
59 std::string
const kSLIDER =
"sl";
60 std::string
const kSLIDER_INT =
"sli";
62 std::vector<std::string>
const gsGUITAG{kTEXT_ENTRY,
69 std::string maybe_quoted(std::string element)
73 if (element.find_first_of(
":[{}]@") != std::string::npos) {
74 return '"' + element +
'"';
85 TGHorizontalFrame* lhs,
86 TGHorizontalFrame* rhs,
88 const std::string& key)
89 : fFrame(frame), fKEY(key)
96 std::vector<std::string>
values;
105 auto const n =
size(values);
106 for (std::size_t i = 0; i <
n; ++i) {
121 fLeftLH =
new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0);
122 fRightLH =
new TGLayoutHints(kLHintsRight, 1, 1, 0, 0);
124 fLabel =
new TGTextButton(lhs,
127 TGButton::GetDefaultGC()(),
128 TGTextButton::GetDefaultFontStruct(),
132 fLabel->SetTextJustify(kTextRight);
134 if (tag == kTEXT_ENTRY) {
137 if (tag == kLIST_BOX_SINGLE) {
140 if (tag == kLIST_BOX_MULTI) {
143 if (tag == kRADIO_BUTTONS) {
146 if (tag == kCHECK_BOX) {
149 if (tag == kSLIDER) {
152 if (tag == kSLIDER_INT) {
162 cet::for_all(
fCheckButton, std::default_delete<TGCheckButton>{});
163 cet::for_all(
fRadioButton, std::default_delete<TGRadioButton>{});
176 const std::string& key,
179 std::vector<std::string>& choice,
180 std::vector<std::string>&
value,
188 gui = p.
get<std::string>(key +
".gui");
189 doc = p.
get<std::string>(key +
".doc");
190 flag |= kHAVE_GUI_TAGS;
196 doc =
"See .fcl file for documentation...";
197 flag |= kNO_GUI_TAGS;
208 std::string valkey = key;
209 if (flag & kHAVE_GUI_TAGS)
214 auto const v = p.
get<std::string>(valkey);
215 value.push_back(maybe_quoted(v));
216 flag |= kSINGLE_VALUED_PARAM;
224 auto tmp = p.
get<std::vector<std::string>>(valkey);
225 for (
auto& element :
tmp) {
226 element = maybe_quoted(element);
229 flag |= kVECTOR_PARAM;
239 std::vector<std::vector<std::string>> vv;
240 vv = p.
get<std::vector<std::vector<std::string>>>(valkey);
252 flag |= kVECTOR_PARAM;
253 for (std::size_t i = 0; i <
size(vv); ++i) {
255 auto const m =
size(vv[i]);
256 for (std::size_t j = 0; j < m; ++j) {
257 s += maybe_quoted(vv[i][j]);
266 value.push_back(
"[[]]");
275 flag |= kPARAMETER_SET_PARAM;
276 value.push_back(v.to_string());
283 MF_LOG_ERROR(
"ParameterSetEditDialog") <<
"Failed to parse " << key <<
"\n" 295 std::vector<std::string>& choice)
299 size_t icolon = guitag.find(
':');
300 if (icolon == std::string::npos)
303 frame = guitag.substr(0, icolon);
308 size_t icomma = icolon;
309 while (icomma != std::string::npos) {
310 size_t spos = icomma + 1;
311 size_t epos = guitag.find(
',', spos);
312 std::string s = guitag.substr(spos, epos - spos);
323 for (std::size_t i = 0; i < gsGUITAG.size(); ++i) {
324 if (s == gsGUITAG[i])
327 MF_LOG_ERROR(
"ParameterSetEditDialog") << s <<
" is not a legal GUI tag.";
336 const std::vector<std::string>&
value)
338 static TColor* c = gROOT->GetColor(41);
345 "evdb::ParameterSetEditRow",
347 "TextEntryReturnPressed()");
350 if (flags & kVECTOR_PARAM)
352 if (flags & kPARAMETER_SET_PARAM)
354 for (std::size_t i = 0; i <
size(value); ++i) {
356 if ((i + 1) !=
size(value))
359 if (flags & kVECTOR_PARAM)
361 if (flags & kPARAMETER_SET_PARAM)
371 const std::vector<std::string>& choice,
372 const std::vector<std::string>&
value,
380 for (
size_t i = 0; i < choice.size(); ++i) {
381 fListBox->AddEntry(choice[i].c_str(), i);
382 for (
size_t j = 0; j <
size(value); ++j) {
383 if (value[j] == choice[i])
388 fListBox->Connect(
"SelectionChanged()",
389 "evdb::ParameterSetEditRow",
391 "ListBoxSelectionChanged()");
392 fListBox->Connect(
"Selected(Int_t)",
393 "evdb::ParameterSetEditRow",
395 "ListBoxSelected(int)");
397 size_t h = kRowH * choice.size();
407 const std::vector<std::string>& choice,
408 const std::vector<std::string>&
value)
410 unsigned int v = atoi(value[0].c_str());
412 for (
size_t i = 0; i < choice.size(); ++i) {
413 TGRadioButton* b =
new TGRadioButton(f, choice[i].c_str(), i);
416 b->SetTextJustify(kTextLeft);
418 "Clicked()",
"evdb::ParameterSetEditRow",
this,
"RadioButtonClicked()");
421 b->SetState(kButtonDown);
431 const std::vector<std::string>& choice,
432 const std::vector<std::string>&
value)
435 unsigned int v = atoi(value[0].c_str());
436 for (
size_t i = 0; i < choice.size(); ++i) {
437 TGCheckButton* b =
new TGCheckButton(f, choice[i].c_str(), i);
440 "Clicked()",
"evdb::ParameterSetEditRow",
this,
"CheckButtonClicked()");
444 b->SetState(kButtonDown);
452 const std::vector<std::string>& choice,
453 const std::vector<std::string>&
value)
459 if (
size(value) == 1) {
462 if (
size(value) == 2) {
472 "evdb::ParameterSetEditRow",
474 "TextEntryReturnPressed()");
476 fSlider =
new TGDoubleHSlider(f, 100, kDoubleScaleBoth);
479 float min = atof(choice[0].c_str());
480 float max = atof(choice[1].c_str());
484 if (
size(value) == 1) {
485 pos1 = atof(value[0].c_str());
488 if (
size(value) == 2) {
489 pos1 = atof(value[0].c_str());
490 pos2 = atof(value[1].c_str());
494 fSlider->SetPosition(pos1, pos2);
496 fSlider->Connect(
"PositionChanged()",
497 "evdb::ParameterSetEditRow",
499 "SliderPositionChanged()");
502 fSlider->Resize(kRowW * 4 / 5, 10 * kRowH);
513 const char* text =
fTextEntry->GetBuffer()->GetString();
515 static TColor* c = gROOT->GetColor(1);
522 float f1 = 0,
f2 = 0;
523 n = sscanf(text,
"[%f, %f]", &f1, &
f2);
525 n = sscanf(text,
"%f", &f1);
541 if (
fListBox->GetMultipleSelections() ==
false)
546 fListBox->GetSelectedEntries(&selections);
549 for (
unsigned int i = 0;; ++i) {
550 sel = (TGLBEntry*)selections.At(i);
570 if (
fListBox->GetMultipleSelections())
580 unsigned int value = 0;
581 TGButton* b = (TGButton*)gTQSender;
582 int id = b->WidgetId();
590 sprintf(buff,
"%d", value);
606 sprintf(buff,
"%d", value);
620 float const ave = 0.5 * (mn + mx);
623 int const mni = rint(mn);
624 int const mxi = rint(mx);
625 int const avei = rint(ave);
627 sprintf(buff,
"[%d, %d]", mni, mxi);
629 sprintf(buff,
"%d", avei);
633 sprintf(buff,
"[%.1f, %.1f]", mn, mx);
635 sprintf(buff,
"%.1f", ave);
658 std::ostringstream s;
663 <<
"val:" <<
fValue <<
" " 664 <<
"gui:\"" <<
fGUI <<
"\" " 665 <<
"doc:\"" <<
fDOC <<
"\" " 677 : fParameterSetID(psetid), fIsModified(false)
679 fCanvas =
new TGCanvas(mother, kWidth - 6, kHeight - 50);
680 fCanvasH =
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY);
689 std::vector<std::string> keys = pset.
get_names();
690 std::size_t
const nkey =
size(keys);
694 unsigned int nparam = 0;
695 for (
auto const& key : keys) {
696 if (!((key ==
"service_type"s) || (key ==
"module_type"s) ||
697 (key ==
"module_label"s))) {
708 for (std::size_t i = 0, j = 0; i < nkey; ++i) {
709 if (!((keys[i] ==
"service_type") || (keys[i] ==
"module_type") ||
710 (keys[i] ==
"module_label"))) {
712 TGHorizontalFrame* lhs =
new TGHorizontalFrame(
fContainer);
713 TGHorizontalFrame* rhs =
new TGHorizontalFrame(
fContainer);
715 TGTableLayoutHints* lhsh =
new TGTableLayoutHints(0, 1, j, j + 1);
716 TGTableLayoutHints* rhsh =
new TGTableLayoutHints(1, 2, j, j + 1);
731 fCanvas->Connect(
"ProcessedEvent(Event_t*)",
732 "evdb::ParameterSetEditFrame",
734 "HandleMouseWheel(Event_t*)");
743 cet::for_all(
fRow, std::default_delete<ParameterSetEditRow>{});
744 cet::for_all(
fRHSHints, std::default_delete<TGTableLayoutHints>{});
745 cet::for_all(
fLHSHints, std::default_delete<TGTableLayoutHints>{});
746 cet::for_all(
fRHS, std::default_delete<TGHorizontalFrame>{});
747 cet::for_all(
fLHS, std::default_delete<TGHorizontalFrame>{});
763 if (event->fType != kButtonPress && event->fType != kButtonRelease)
767 if (event->fCode == kButton4 || event->fCode == kButton5) {
770 if (
fCanvas->GetContainer()->GetHeight())
771 page = Int_t(Float_t(
fCanvas->GetViewPort()->GetHeight() *
772 fCanvas->GetViewPort()->GetHeight()) /
773 fCanvas->GetContainer()->GetHeight());
776 if (event->fCode == kButton4) {
778 Int_t newpos =
fCanvas->GetVsbPosition() - page;
781 fCanvas->SetVsbPosition(newpos);
783 if (event->fCode == kButton5) {
785 Int_t newpos =
fCanvas->GetVsbPosition() + page;
786 fCanvas->SetVsbPosition(newpos);
801 for (
auto row :
fRow) {
811 std::ostringstream s;
812 for (
auto row :
fRow) {
813 s << row->AsFHICL() <<
"\n";
823 : TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 4, 4)
828 fButtons =
new TGHorizontalFrame(
this);
839 fApply->Connect(
"Clicked()",
"evdb::ParameterSetEditDialog",
this,
"Apply()");
841 "Clicked()",
"evdb::ParameterSetEditDialog",
this,
"Cancel()");
842 fDone->Connect(
"Clicked()",
"evdb::ParameterSetEditDialog",
this,
"Done()");
847 int which = st.
fServices[psetid].fCategory;
850 unsigned int top = 0, indx = 0;
851 for (i = 0; i < st.
fServices.size(); ++i) {
852 if (st.
fServices[i].fCategory == which) {
856 TGCompositeFrame*
f =
fTGTab->AddTab(tabnm.c_str());
865 this->SetWindowName(
"Drawing Services");
868 this->SetWindowName(
"Experiment Services");
871 this->SetWindowName(
"Services Configuration");
874 this->MapSubwindows();
875 this->Resize(kWidth, kHeight);
884 for (i = 0; i <
fFrames.size(); ++i)
905 if (frame->fIsModified) {
906 unsigned int psetid = frame->fParameterSetID;
909 std::string p = frame->AsFHICL();
911 p +=
"service_type:";
925 this->SendCloseMessage();
934 this->SendCloseMessage();
952 std::size_t
const n = s.find(
"DrawingOptions");
953 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)
TGCompositeFrame * fContainer
static ServiceTable & Instance()
void TextEntryReturnPressed()
void SliderPositionChanged()
std::vector< ParameterSetEditRow * > fRow
Collection of Services used in the event display.
Interface to services and their configurations.
std::string AsFHICL() const
#define MF_LOG_ERROR(category)
TGLayoutHints * fRightLH
Align to right.
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
std::vector< TGHorizontalFrame * > fLHS
decltype(auto) values(Coll &&coll)
Range-for loop helper iterating across the values of the specified collection.
T get(std::string const &key) const
Holds information about what action to take next.
static void ParseGUItag(const std::string &guitag, std::string &frame, std::vector< std::string > &choice)
A frame for editing a single paramter set.
~ParameterSetEditDialog()
Pop-up window for editing parameter sets.
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
TGHorizontalFrame * fButtons
void RadioButtonClicked()
std::vector< TGHorizontalFrame * > fRHS
std::string AsFHICL() const
A single row for editing a single parameter in a set.
std::vector< ParameterSetEditFrame * > fFrames
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)
std::vector< TGCheckButton * > fCheckButton
decltype(auto) constexpr empty(T &&obj)
ADL-aware version of std::empty.
Event finding and building.
std::string to_string() const
ParameterSetEditFrame(TGCompositeFrame *mother, unsigned int psetid)
TGTextButton * fLabel
Label on the left.
std::string TabName(const std::string &s)