CMS 3D CMS Logo

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" }, { "CommonPreferences", "Colors" }, { "EventNavigator" , "EventFilters" }, { "EventItems" , "Collections" } };
22 
23  std::string realName(std::string btnName)
24  {
25  for (std::vector< std::pair<std::string, std::string> >::iterator i = names.begin(); i!= names.end(); ++i) {
26  if (i->second == btnName)
27  return i->first;
28  }
29  return btnName;
30  }
31 
32 
33  std::string btnName(const std::string& rlName)
34  {
35 
36  for (std::vector< std::pair<std::string, std::string> >::iterator i = names.begin(); i!= names.end(); ++i) {
37  if (i->first == rlName)
38  return i->second;
39  }
40  return rlName;
41  }
42 };
43 
44  MyNameMap nmm;
45 }
46 
48  TGTransientFrame(gClient->GetRoot(), FWGUIManager::getGUIManager()->getMainFrame(), 200, 140), m_cfgMng(iCfg)
49 {
50  if (path) {
51  std::ifstream g(path);
53  parser.parse();
54  parser.config()->swap(m_origConfig);
55  }
56  else {
57  FWConfiguration curr;
58  m_cfgMng->to(curr);
59  curr.swap(m_origConfig);
60  }
61 
62  TGVerticalFrame* vf = new TGVerticalFrame(this);
63  AddFrame(vf, new TGLayoutHints(kLHintsNormal, 2, 2, 4, 4));
64 
65  // can do a cast to non-const since we own the configuration
67  std::sort(kv->begin(), kv->end(),
68  [](const std::pair<std::string, FWConfiguration>& lhs, const std::pair<std::string, FWConfiguration>& rhs) -> bool {
69  return nmm.btnName(lhs.first) < nmm.btnName(rhs.first); } );
70 
71  for(FWConfiguration::KeyValues::const_iterator it = m_origConfig.keyValues()->begin(); it != m_origConfig.keyValues()->end(); ++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 {
84  // AMT Is this eniugh. Should there be a destroy ?
85  UnmapWindow();
86 }
87 
88 //---------------------------------------------------------------------
89 //---------------------------------------------------------------------
90 //---------------------------------------------------------------------
91 //---------------------------------------------------------------------
92 
94  FWPartialConfigGUI(path, iCfg), m_eiMng(iEiMng)
95 {
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 {
113 }
114 
116 {
117  bool resetViews = true;
118  bool resetEI = true;
119 
121 
122  for (auto i = m_entries.begin(); i != m_entries.end(); i++) {
123  if (!((*i)->IsOn())) {
124  std::string key = nmm.realName((*i)->GetText()->GetString());
125  if (key == "EventItems") resetEI = false;
126  if (key == "GUI") resetViews = false;
127 
128  for(FWConfiguration::KeyValues::iterator it = kv->begin(); it != kv->end(); ++it)
129  {
130  if ( key == it->first) {
131  kv->erase(it);
132  break;
133  }
134  }
135  }
136  }
137 
138  if (resetEI)
139  m_eiMng->clearItems();
140 
141  if (resetViews)
143 
144  gEve->DisableRedraw();
146  gEve->EnableRedraw();
147 
148  UnmapWindow();
149 }
150 
151 //---------------------------------------------------------------------
152 //---------------------------------------------------------------------
153 //---------------------------------------------------------------------
154 //---------------------------------------------------------------------
155 
156 FWPartialConfigSaveGUI::FWPartialConfigSaveGUI( const char* path_out, const char* path_in, FWConfigurationManager* iCfg):
157  FWPartialConfigGUI(nullptr, iCfg), m_outFileName(path_out), m_currFileName(path_in)
158 {
159  TGHorizontalFrame* hf = new TGHorizontalFrame(this);
160  AddFrame(hf, new TGLayoutHints( kLHintsRight| kLHintsBottom, 1, 1, 2, 4));
161 
162  TGTextButton* write = new TGTextButton(hf, " Write ");
163  write->Connect("Clicked()", "FWPartialConfigSaveGUI", this, "WriteConfig()");
164  hf->AddFrame(write, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
165 
166  TGTextButton* cancel = new TGTextButton(hf, " Cancel ");
167  cancel->Connect("Clicked()", "FWPartialConfigGUI", this, "Cancel()");
168  hf->AddFrame(cancel, new TGLayoutHints(kLHintsExpandX, 2, 2, 0, 0));
169 
170  AddFrame(new TGLabel(this, Form("Output file: %s", gSystem->BaseName(path_out))), new TGLayoutHints(kLHintsLeft, 8,2,3,3));
171 
172  SetWindowName("Save Config");
173 
174  MapSubwindows();
175  Layout();
176  MapWindow();
177 }
178 
179 
180 void
182 {
184  {
185  m_currFileName = gSystem->Which(TROOT::GetMacroPath(), m_currFileName.c_str(), kReadPermission);
186  // printf("going to parse m_currFileName %s\n", m_currFileName.c_str());
187  std::ifstream g(m_currFileName.c_str());
188  if (g.peek() == (int) '<') {
190  parser.parse();
191  parser.config()->swap(destination);
192  // printf("parsed %s ......... \n",m_currFileName.c_str() );
193  }
194  }
195 
196  FWConfiguration curr;
197  m_cfgMng->to(curr);
198 
201 
202  for (auto i = m_entries.begin(); i != m_entries.end(); i++) {
203  if ((*i)->IsOn()) {
204  std::string key = nmm.realName((*i)->GetText()->GetString());
205  // printf("ON check key %s\n", key.c_str());
206  for(FWConfiguration::KeyValues::iterator it = cur_kv->begin(); it != cur_kv->end(); ++it)
207  {
208  if ( key == it->first) {
209  bool replace = false;
210  if (old_kv) {
211  for(FWConfiguration::KeyValues::iterator oldit = old_kv->begin(); oldit != old_kv->end(); ++oldit) {
212  if ( key == oldit->first) {
213  replace = true;
214  oldit->second.swap(it->second);
215  break;
216  }
217  }
218  }
219 
220  if (!replace)
221  destination.addKeyValue(it->first, it->second);
222 
223  break;
224  }
225  }
226  }
227  }
228 
229  // Dump content in the file
230  std::ofstream file(m_outFileName.c_str());
231  if(not file) {
232  fwLog(fwlog::kError) << "FWPartialConfigSaveGUI::Write, can't open output file.!\n";
233  return;
234  }
235  fwLog(fwlog::kInfo) << "Writing configuration to " << m_outFileName << std::endl;
236  FWConfiguration::streamTo(file, destination, "top");
237  UnmapWindow();
238 }
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
void to(FWConfiguration &) const
const KeyValues * keyValues() const
FWEventItemsManager * m_eiMng
static const HistoName names[]
FWConfigurationManager * m_cfgMng
~FWPartialConfigLoadGUI() override
void subviewDestroyAll()
def replace(string, replacements)
#define nullptr
FWConfiguration * config(void)
std::vector< TGCheckButton * > m_entries
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
void swap(FWConfiguration &)
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:50
def load(fileName)
Definition: svgfig.py:546
FWConfiguration m_origConfig
def write(self, setup)
static void streamTo(std::ostream &oTo, const FWConfiguration &iConfig, const std::string &name)