CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWPartialConfig.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
4 #include "TGButton.h"
5 #include "TEveManager.h"
6 #include "TGString.h"
7 #include "TGLabel.h"
8 #include "TSystem.h"
9 #include "TROOT.h"
10 
18 
19 namespace {
20  struct MyNameMap {
21  std::vector<std::pair<std::string, std::string> > names = {{"GUI", "Windows"},
22  {"CommonPreferences", "Colors"},
23  {"EventNavigator", "EventFilters"},
24  {"EventItems", "Collections"}};
25 
26  std::string realName(std::string btnName) {
27  for (std::vector<std::pair<std::string, std::string> >::iterator i = names.begin(); i != names.end(); ++i) {
28  if (i->second == btnName)
29  return i->first;
30  }
31  return btnName;
32  }
33 
34  std::string btnName(const std::string& rlName) {
35  for (std::vector<std::pair<std::string, std::string> >::iterator i = names.begin(); i != names.end(); ++i) {
36  if (i->first == rlName)
37  return i->second;
38  }
39  return rlName;
40  }
41  };
42 
43  MyNameMap nmm;
44 } // namespace
45 
47  : TGTransientFrame(gClient->GetRoot(), FWGUIManager::getGUIManager()->getMainFrame(), 200, 140), m_cfgMng(iCfg) {
48  if (path) {
49  std::ifstream g(path);
51  parser.parse();
52  parser.config()->swap(m_origConfig);
53  } else {
54  FWConfiguration curr;
55  m_cfgMng->to(curr);
56  curr.swap(m_origConfig);
57  }
58 
59  TGVerticalFrame* vf = new TGVerticalFrame(this);
60  AddFrame(vf, new TGLayoutHints(kLHintsNormal, 2, 2, 4, 4));
61 
62  // can do a cast to non-const since we own the configuration
64  std::sort(kv->begin(),
65  kv->end(),
66  [](const std::pair<std::string, FWConfiguration>& lhs, const std::pair<std::string, FWConfiguration>& rhs)
67  -> bool { return nmm.btnName(lhs.first) < nmm.btnName(rhs.first); });
68 
69  for (FWConfiguration::KeyValues::const_iterator it = m_origConfig.keyValues()->begin();
70  it != m_origConfig.keyValues()->end();
71  ++it) {
72  if (it->second.keyValues()) {
73  std::string nb = nmm.btnName(it->first);
74  TGCheckButton* cb = new TGCheckButton(vf, nb.c_str());
75  vf->AddFrame(cb);
76 
77  m_entries.push_back(cb);
78  }
79  }
80 }
81 
83  // AMT Is this eniugh. Should there be a destroy ?
84  UnmapWindow();
85 }
86 
87 //---------------------------------------------------------------------
88 //---------------------------------------------------------------------
89 //---------------------------------------------------------------------
90 //---------------------------------------------------------------------
91 
94  FWEventItemsManager* iEiMng)
95  : FWPartialConfigGUI(path, iCfg), m_eiMng(iEiMng) {
96  TGHorizontalFrame* hf = new TGHorizontalFrame(this);
97  AddFrame(hf, new TGLayoutHints(kLHintsRight | kLHintsBottom, 1, 1, 2, 4));
98  TGTextButton* load = new TGTextButton(hf, " Load ");
99  load->Connect("Clicked()", "FWPartialConfigLoadGUI", this, "Load()");
100  hf->AddFrame(load, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
101  TGTextButton* cancel = new TGTextButton(hf, " Cancel ");
102  cancel->Connect("Clicked()", "FWPartialConfigGUI", this, "Cancel()");
103  hf->AddFrame(cancel, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
104 
105  SetWindowName("Load Config");
106  MapSubwindows();
107  Layout();
108  MapWindow();
109 }
110 
112 
114  bool resetViews = true;
115  bool resetEI = true;
116 
118 
119  for (auto i = m_entries.begin(); i != m_entries.end(); i++) {
120  if (!((*i)->IsOn())) {
121  std::string key = nmm.realName((*i)->GetText()->GetString());
122  if (key == "EventItems")
123  resetEI = false;
124  if (key == "GUI")
125  resetViews = false;
126 
127  for (FWConfiguration::KeyValues::iterator it = kv->begin(); it != kv->end(); ++it) {
128  if (key == it->first) {
129  kv->erase(it);
130  break;
131  }
132  }
133  }
134  }
135 
136  if (resetEI)
137  m_eiMng->clearItems();
138 
139  if (resetViews)
141 
142  gEve->DisableRedraw();
144  gEve->EnableRedraw();
145 
146  UnmapWindow();
147 }
148 
149 //---------------------------------------------------------------------
150 //---------------------------------------------------------------------
151 //---------------------------------------------------------------------
152 //---------------------------------------------------------------------
153 
154 FWPartialConfigSaveGUI::FWPartialConfigSaveGUI(const char* path_out, const char* path_in, FWConfigurationManager* iCfg)
155  : FWPartialConfigGUI(nullptr, iCfg), m_outFileName(path_out), m_currFileName(path_in) {
156  TGHorizontalFrame* hf = new TGHorizontalFrame(this);
157  AddFrame(hf, new TGLayoutHints(kLHintsRight | kLHintsBottom, 1, 1, 2, 4));
158 
159  TGTextButton* write = new TGTextButton(hf, " Write ");
160  write->Connect("Clicked()", "FWPartialConfigSaveGUI", this, "WriteConfig()");
161  hf->AddFrame(write, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
162 
163  TGTextButton* cancel = new TGTextButton(hf, " Cancel ");
164  cancel->Connect("Clicked()", "FWPartialConfigGUI", this, "Cancel()");
165  hf->AddFrame(cancel, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
166 
167  AddFrame(new TGLabel(this, Form("Output file: %s", gSystem->BaseName(path_out))),
168  new TGLayoutHints(kLHintsLeft, 8, 2, 3, 3));
169 
170  SetWindowName("Save Config");
171 
172  MapSubwindows();
173  Layout();
174  MapWindow();
175 }
176 
179  {
180  m_currFileName = gSystem->Which(TROOT::GetMacroPath(), m_currFileName.c_str(), kReadPermission);
181  // printf("going to parse m_currFileName %s\n", m_currFileName.c_str());
182  std::ifstream g(m_currFileName.c_str());
183  if (g.peek() == (int)'<') {
185  parser.parse();
186  parser.config()->swap(destination);
187  // printf("parsed %s ......... \n",m_currFileName.c_str() );
188  }
189  }
190 
191  FWConfiguration curr;
192  m_cfgMng->to(curr);
193 
196 
197  for (auto i = m_entries.begin(); i != m_entries.end(); i++) {
198  if ((*i)->IsOn()) {
199  std::string key = nmm.realName((*i)->GetText()->GetString());
200  // printf("ON check key %s\n", key.c_str());
201  for (FWConfiguration::KeyValues::iterator it = cur_kv->begin(); it != cur_kv->end(); ++it) {
202  if (key == it->first) {
203  bool replace = false;
204  if (old_kv) {
205  for (FWConfiguration::KeyValues::iterator oldit = old_kv->begin(); oldit != old_kv->end(); ++oldit) {
206  if (key == oldit->first) {
207  replace = true;
208  oldit->second.swap(it->second);
209  break;
210  }
211  }
212  }
213 
214  if (!replace)
215  destination.addKeyValue(it->first, it->second);
216 
217  break;
218  }
219  }
220  }
221  }
222 
223  // Dump content in the file
224  std::ofstream file(m_outFileName.c_str());
225  if (not file) {
226  fwLog(fwlog::kError) << "FWPartialConfigSaveGUI::Write, can't open output file.!\n";
227  return;
228  }
229  fwLog(fwlog::kInfo) << "Writing configuration to " << m_outFileName << std::endl;
230  FWConfiguration::streamTo(file, destination, "top");
231  UnmapWindow();
232 }
void to(FWConfiguration &) const
const KeyValues * keyValues() const
FWEventItemsManager * m_eiMng
FWConfigurationManager * m_cfgMng
~FWPartialConfigLoadGUI() override
void subviewDestroyAll()
FWConfiguration * config(void)
std::vector< TGCheckButton * > m_entries
const std::string names[nVars_]
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
void setFrom(const FWConfiguration &) const
def load
Definition: svgfig.py:547
void swap(FWConfiguration &)
tuple key
prepare the HTCondor submission files and eventually submit them
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
FWPartialConfigLoadGUI(const char *path, FWConfigurationManager *, FWEventItemsManager *)
FWPartialConfigGUI(const char *path, FWConfigurationManager *)
FWPartialConfigSaveGUI(const char *path_out, const char *path_in, FWConfigurationManager *)
static FWGUIManager * getGUIManager()
#define fwLog(_level_)
Definition: fwLog.h:45
FWConfiguration m_origConfig
static void streamTo(std::ostream &oTo, const FWConfiguration &iConfig, const std::string &name)