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"},
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;
231  UnmapWindow();
232 }
FWPartialConfigSaveGUI::m_outFileName
std::string m_outFileName
Definition: FWPartialConfig.h:50
FWPartialConfigGUI::m_cfgMng
FWConfigurationManager * m_cfgMng
Definition: FWPartialConfig.h:20
fwLog
#define fwLog(_level_)
Definition: fwLog.h:45
mps_fire.i
i
Definition: mps_fire.py:355
FWGUIManager
Definition: FWGUIManager.h:94
FWPartialConfigLoadGUI::FWPartialConfigLoadGUI
FWPartialConfigLoadGUI(const char *path, FWConfigurationManager *, FWEventItemsManager *)
Definition: FWPartialConfig.cc:92
FWConfiguration::streamTo
static void streamTo(std::ostream &oTo, const FWConfiguration &iConfig, const std::string &name)
Definition: FWConfiguration.cc:192
FWPartialConfigSaveGUI::FWPartialConfigSaveGUI
FWPartialConfigSaveGUI(const char *path_out, const char *path_in, FWConfigurationManager *)
Definition: FWPartialConfig.cc:154
FWEventItemsManager::clearItems
void clearItems()
Definition: FWEventItemsManager.cc:117
FWXMLConfigParser.h
FWEventItemsManager
Definition: FWEventItemsManager.h:44
FWConfiguration::swap
void swap(FWConfiguration &)
Definition: FWConfiguration.cc:105
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
FWPartialConfigLoadGUI::Load
void Load()
Definition: FWPartialConfig.cc:113
FWConfiguration::KeyValues
std::vector< std::pair< std::string, FWConfiguration > > KeyValues
Definition: FWConfiguration.h:40
FWGUIManager::subviewDestroyAll
void subviewDestroyAll()
Definition: FWGUIManager.cc:465
FWPartialConfigGUI::Cancel
void Cancel()
Definition: FWPartialConfig.cc:82
FWPartialConfig.h
FWConfigurationManager
Definition: FWConfigurationManager.h:32
photonIsolationHIProducer_cfi.hf
hf
Definition: photonIsolationHIProducer_cfi.py:9
FWXMLConfigParser
Definition: FWXMLConfigParser.h:32
FWPartialConfigGUI::m_origConfig
FWConfiguration m_origConfig
Definition: FWPartialConfig.h:19
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
svgfig.load
def load(fileName)
Definition: svgfig.py:547
FWConfigurationManager::to
void to(FWConfiguration &) const
Definition: FWConfigurationManager.cc:86
FWPartialConfigSaveGUI::m_currFileName
std::string m_currFileName
Definition: FWPartialConfig.h:51
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWPartialConfigGUI::FWPartialConfigGUI
FWPartialConfigGUI(const char *path, FWConfigurationManager *)
Definition: FWPartialConfig.cc:46
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
FWPartialConfigLoadGUI::m_eiMng
FWEventItemsManager * m_eiMng
Definition: FWPartialConfig.h:35
fwLog.h
FWPartialConfigLoadGUI::~FWPartialConfigLoadGUI
~FWPartialConfigLoadGUI() override
Definition: FWPartialConfig.cc:111
FWGUIManager::getGUIManager
static FWGUIManager * getGUIManager()
Definition: FWGUIManager.cc:685
FWPartialConfigGUI
Definition: FWPartialConfig.h:11
HLTMuonOfflineAnalyzer_cff.destination
destination
Definition: HLTMuonOfflineAnalyzer_cff.py:50
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48
FWConfigurationManager::setFrom
void setFrom(const FWConfiguration &) const
Definition: FWConfigurationManager.cc:75
fwlog::kInfo
Definition: fwLog.h:35
FWPartialConfigGUI::m_entries
std::vector< TGCheckButton * > m_entries
Definition: FWPartialConfig.h:18
FWConfiguration::keyValues
const KeyValues * keyValues() const
Definition: FWConfiguration.h:51
CmsShowMainFrame.h
FWEventItemsManager.h
FWPartialConfigSaveGUI::WriteConfig
void WriteConfig()
Definition: FWPartialConfig.cc:177
fwlog::kError
Definition: fwLog.h:35
FWConfiguration
Definition: FWConfiguration.h:31
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
FWConfigurationManager.h
SimpleSAXParser.h
crabWrapper.key
key
Definition: crabWrapper.py:19
g
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
FWGUIManager.h
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444