CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
CmsShowSearchFiles Class Reference

#include <Fireworks/Core/interface/CmsShowSearchFiles.h>

Inheritance diagram for CmsShowSearchFiles:

Public Member Functions

std::string chooseFileFromURL ()
 This opens the dialog window and returns once the user has choosen, returns an empty string if canceled. More...
 
 ClassDefOverride (CmsShowSearchFiles, 0)
 
 CmsShowSearchFiles (const char *filename, const char *windowname, const TGWindow *p=nullptr, UInt_t w=1, UInt_t h=1)
 
void fileEntryChanged (const char *)
 
void hyperlinkClicked (const char *)
 
void openClicked ()
 
void prefixChoosen (Int_t)
 
void showPrefixes ()
 
void updateBrowser ()
 
 ~CmsShowSearchFiles () override
 

Private Member Functions

void readError ()
 
void readInfo ()
 
void sendToWebBrowser (std::string &iWebFile)
 

Private Attributes

TGTextButton * m_choosePrefix
 
TGTextEntry * m_file
 
TGTextButton * m_openButton
 
bool m_openCalled
 
std::vector< bool > m_prefixComplete
 
std::vector< std::string > m_prefixes
 
TGPopupMenu * m_prefixMenu
 
FWHtmlm_webFile
 

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 35 of file CmsShowSearchFiles.h.

Constructor & Destructor Documentation

CmsShowSearchFiles::CmsShowSearchFiles ( const char *  filename,
const char *  windowname,
const TGWindow *  p = nullptr,
UInt_t  w = 1,
UInt_t  h = 1 
)

Definition at line 51 of file CmsShowSearchFiles.cc.

References fwLog, fwlog::kInfo, m_choosePrefix, m_file, m_openButton, m_prefixMenu, m_webFile, fed_dqm_sourceclient-live_cfg::path, sendToWebBrowser(), AlCaHLTBitMon_QueryRunRegistry::string, and fireworks::supportedDataFormatsVersion().

53  : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h) {
54  TGVerticalFrame* vf = new TGVerticalFrame(this);
55  this->AddFrame(vf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
56  TGHorizontalFrame* urlFrame = new TGHorizontalFrame(this);
57  vf->AddFrame(urlFrame, new TGLayoutHints(kLHintsExpandX, 5, 0, 5, 5));
58 
59  TGLabel* urlLabel = new TGLabel(urlFrame, "URL");
60  urlFrame->AddFrame(urlLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1));
61  m_choosePrefix = new TGTextButton(urlFrame, "Choose Prefix");
62  urlFrame->AddFrame(m_choosePrefix, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
63 
64  m_file = new TGTextEntry(urlFrame);
65  urlFrame->AddFrame(m_file, new TGLayoutHints(kLHintsExpandX, 1, 0, 1, 1));
66  m_file->Connect("TextChanged(const char*)", "CmsShowSearchFiles", this, "fileEntryChanged(const char*)");
67  m_file->Connect("ReturnPressed()", "CmsShowSearchFiles", this, "updateBrowser()");
68 
69  m_webFile = new FWHtml(vf, 1, 1);
70  m_webFile->Connect("MouseDown(const char*)", "CmsShowSearchFiles", this, "hyperlinkClicked(const char*)");
71  vf->AddFrame(m_webFile, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 1, 1, 1, 1));
72 
73  TGHorizontalFrame* buttonFrame = new TGHorizontalFrame(vf);
74  vf->AddFrame(buttonFrame, new TGLayoutHints(kLHintsExpandX, 1, 10, 1, 10));
75 
76  m_openButton = new TGTextButton(buttonFrame, "Open");
77  buttonFrame->AddFrame(m_openButton, new TGLayoutHints(kLHintsRight, 5, 5, 1, 1));
78  m_openButton->SetEnabled(kFALSE);
79  m_openButton->Connect("Clicked()", "CmsShowSearchFiles", this, "openClicked()");
80 
81  TGTextButton* cancel = new TGTextButton(buttonFrame, "Cancel");
82  buttonFrame->AddFrame(cancel, new TGLayoutHints(kLHintsRight, 5, 5, 1, 1));
83  cancel->Connect("Clicked()", "CmsShowSearchFiles", this, "UnmapWindow()");
84 
85  SetWindowName(windowname);
86 
88  Form("http://cmsshow-rels.web.cern.ch/cmsShow-rels/samples/%d/", fireworks::supportedDataFormatsVersion()[0]);
89 
90  if (!path.empty())
91  fwLog(fwlog::kInfo) << "Search files at " << path << "." << std::endl;
92 
93  sendToWebBrowser(path);
94 
95  MapSubwindows();
96  Layout();
97  m_prefixMenu = nullptr;
98  m_choosePrefix->Connect("Clicked()", "CmsShowSearchFiles", this, "showPrefixes()");
99 }
const double w
Definition: UKUtility.cc:23
TGTextButton * m_choosePrefix
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:35
TGPopupMenu * m_prefixMenu
TGTextButton * m_openButton
#define fwLog(_level_)
Definition: fwLog.h:45
void sendToWebBrowser(std::string &iWebFile)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
CmsShowSearchFiles::~CmsShowSearchFiles ( )
override

Definition at line 101 of file CmsShowSearchFiles.cc.

References m_prefixMenu.

101 { delete m_prefixMenu; }
TGPopupMenu * m_prefixMenu

Member Function Documentation

std::string CmsShowSearchFiles::chooseFileFromURL ( )

This opens the dialog window and returns once the user has choosen, returns an empty string if canceled.

Definition at line 318 of file CmsShowSearchFiles.cc.

References m_file, m_openCalled, and AlCaHLTBitMon_QueryRunRegistry::string.

318  {
319  DontCallClose();
320  Connect("CloseWindow()", "CmsShowSearchFiles", this, "UnmapWindow()");
321  m_openCalled = false;
322  MapWindow();
323  gClient->WaitForUnmap(this);
324 
325  if (!m_openCalled) {
326  return std::string();
327  }
328  return m_file->GetText();
329 }
CmsShowSearchFiles::ClassDefOverride ( CmsShowSearchFiles  ,
 
)
void CmsShowSearchFiles::fileEntryChanged ( const char *  iFileName)

Definition at line 124 of file CmsShowSearchFiles.cc.

References MillePedeFileConverter_cfg::fileName, m_openButton, s_rootPostfix(), and AlCaHLTBitMon_QueryRunRegistry::string.

124  {
125  std::string fileName = iFileName;
126  size_t index = fileName.find_last_of('.');
127  std::string postfix;
128  if (index != std::string::npos) {
129  postfix = fileName.substr(index, std::string::npos);
130  }
131  if (postfix == s_rootPostfix) {
132  m_openButton->SetEnabled(kTRUE);
133  } else {
134  m_openButton->SetEnabled(kFALSE);
135  }
136 }
TGTextButton * m_openButton
static const std::string s_rootPostfix(".root")
void CmsShowSearchFiles::hyperlinkClicked ( const char *  iLink)

Definition at line 147 of file CmsShowSearchFiles.cc.

References FWHtml::addToVisited(), MillePedeFileConverter_cfg::fileName, m_file, m_webFile, openClicked(), s_rootPostfix(), AlCaHLTBitMon_QueryRunRegistry::string, and updateBrowser().

147  {
148  m_file->SetText(iLink, kTRUE);
149 
150  m_webFile->addToVisited(iLink);
151  std::string fileName = iLink;
152  size_t index = fileName.find_last_of('.');
153  std::string postfix = fileName.substr(index, std::string::npos);
154 
155  if (postfix != s_rootPostfix) {
156  updateBrowser();
157  } else {
158  openClicked();
159  }
160 }
void addToVisited(const char *iToVisit)
static const std::string s_rootPostfix(".root")
void CmsShowSearchFiles::openClicked ( )

Definition at line 164 of file CmsShowSearchFiles.cc.

References m_openCalled.

Referenced by hyperlinkClicked().

164  {
165  m_openCalled = true;
166  this->UnmapWindow();
167 }
void CmsShowSearchFiles::prefixChoosen ( Int_t  iIndex)

Definition at line 105 of file CmsShowSearchFiles.cc.

References m_choosePrefix, m_file, m_openButton, m_prefixComplete, m_prefixes, m_webFile, AlCaHLTBitMon_ParallelJobs::p, sendToWebBrowser(), AlCaHLTBitMon_QueryRunRegistry::string, and updateBrowser().

105  {
106  // printf ("pref chosen %d \n", iIndex);
107  m_file->SetText(m_prefixes[iIndex].c_str(), kFALSE);
108  m_openButton->SetEnabled(kFALSE);
109 
110  if (m_prefixComplete[iIndex]) {
111  //gClient->NeedRedraw(this);
112  gClient->NeedRedraw(m_choosePrefix);
113  gClient->NeedRedraw(m_webFile);
114  gClient->ProcessEventsFor(this);
115  updateBrowser();
116  } else {
117  std::string p;
118  sendToWebBrowser(p);
119  }
120 }
std::vector< bool > m_prefixComplete
TGTextButton * m_choosePrefix
TGTextButton * m_openButton
std::vector< std::string > m_prefixes
void sendToWebBrowser(std::string &iWebFile)
void CmsShowSearchFiles::readError ( )
private

Definition at line 269 of file CmsShowSearchFiles.cc.

References mps_fire::i, and m_webFile.

Referenced by sendToWebBrowser().

269  {
270  const static char* s_readError[] = {
271  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
272  "\"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd\"> ",
273  "<HTML><HEAD><TITLE>HTTP Read Error</TITLE> ",
274  "<META http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></HEAD> ",
275  "<BODY> ",
276  "<P>Unknown error while trying to get file via http</P>",
277  "</BODY></HTML> ",
278  nullptr};
279 
280  m_webFile->SetBaseUri("");
281  for (int i = 0; s_readError[i]; i++) {
282  m_webFile->ParseText(const_cast<char*>(s_readError[i]));
283  }
284 }
void CmsShowSearchFiles::readInfo ( )
private

Definition at line 286 of file CmsShowSearchFiles.cc.

References mps_fire::i, m_webFile, and fireworks::supportedDataFormatsVersion().

Referenced by sendToWebBrowser().

286  {
287  const static char* s_noBrowserMessage[] = {
288  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
289  "\"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd\"> ",
290  "<HTML><HEAD><TITLE>No Browser Available</TITLE> ",
291  "<META http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></HEAD> ",
292  "<BODY> ",
293  //"No file browser is available for this prefix. You can still type the full URL into the above text box to open the EDM ROOT file.<BR>",
294  //"Only a prefix beginning in <STRONG>http:</STRONG> which contains a site name (e.g. http://www.site.org) is supported for browsing."
295  "<b>Welcome....</b><BR>",
296  "<BR>",
297  "<b>You may look at examples:</b><BR>",
298  "If you are in Europe, open example data files at CERN : ",
299  " <a href=",
300  Form("http://fireworks.web.cern.ch/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]),
301  "> http://fireworks.web.cern.ch/fireworks/ </a><BR>",
302  "If you are in US, open example data files at UCSD: ",
303  " <a href=",
304  Form("http://uaf-2.t2.ucsd.edu/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]),
305  ">http://uaf-2.t2.ucsd.edu/fireworks/ </a><BR>",
306  "<BR>"
307  "<b>You also may load files with Choose Prefix </b><BR>"
308  "</BODY></HTML> ",
309  nullptr};
310 
311  m_webFile->SetBaseUri("");
312  for (int i = 0; s_noBrowserMessage[i]; i++) {
313  m_webFile->ParseText((char*)s_noBrowserMessage[i]);
314  }
315 }
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:35
void CmsShowSearchFiles::sendToWebBrowser ( std::string &  iWebFile)
private

Definition at line 232 of file CmsShowSearchFiles.cc.

References edmScanValgrind::buffer, m_webFile, PostProcessorHGCAL_cfi::prefix, readError(), readInfo(), readRemote(), s_httpPrefix(), AlCaHLTBitMon_QueryRunRegistry::string, and relmon_authenticated_wget::url.

Referenced by CmsShowSearchFiles(), prefixChoosen(), and updateBrowser().

232  {
233  // std::cout << "CmsShowSearchFiles::sendToWebBrowser " << fileName << std::endl ;
234 
235  size_t index = fileName.find_first_of(':');
236  if (index != std::string::npos) {
237  ++index;
238  } else {
239  index = 0;
240  }
241  std::string prefix = fileName.substr(0, index);
242 
243  m_webFile->Clear();
244  if (prefix == s_httpPrefix) {
245  gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
246  //If you clicked a hyperlink then the cursor is still a hand but we now
247  // want it to be a watch
248  gVirtualX->SetCursor(m_webFile->GetId(), gVirtualX->CreateCursor(kWatch));
249  //If we don't call ProcessEventsFor then the cursor will not be updated
250  gClient->ProcessEventsFor(this);
251  TUrl url(fileName.c_str());
252  std::string buffer = readRemote(url.GetUrl());
253 
254  if (!buffer.empty()) {
255  m_webFile->SetBaseUri(url.GetUrl());
256  m_webFile->ParseText(const_cast<char*>(buffer.c_str()));
257  } else {
258  readError();
259  }
260  gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
261  gVirtualX->SetCursor(m_webFile->GetId(), gVirtualX->CreateCursor(kPointer));
262  } else {
263  readInfo();
264  }
265  m_webFile->Layout();
266 }
static const std::string s_httpPrefix("http:")
static std::string readRemote(const char *url)
void CmsShowSearchFiles::showPrefixes ( )

Definition at line 171 of file CmsShowSearchFiles.cc.

References m_choosePrefix, m_prefixComplete, m_prefixes, m_prefixMenu, PostProcessorHGCAL_cfi::prefix, s_columns, s_filePrefix(), s_httpPrefix(), s_prefixes, and AlCaHLTBitMon_QueryRunRegistry::string.

171  {
172  if (nullptr == m_prefixMenu) {
173  m_prefixMenu = new TGPopupMenu(this);
174  const char* const(*itEnd)[s_columns] = s_prefixes + sizeof(s_prefixes) / sizeof(const char* [3]);
175  int index = 0;
176  for (const char* const(*it)[s_columns] = s_prefixes; it != itEnd; ++it, ++index) {
177  //only add the protocols this version of the code actually can load
178  std::string prefix = std::string((*it)[0]).substr(0, std::string((*it)[0]).find_first_of(':') + 1);
179  if (s_httpPrefix == prefix || s_filePrefix == prefix ||
180  (gPluginMgr->FindHandler("TSystem", prefix.c_str()) &&
181  gPluginMgr->FindHandler("TSystem", prefix.c_str())->CheckPlugin() != -1)) {
182  m_prefixMenu->AddEntry((std::string((*it)[0]) + " (" + ((*it)[1]) + ")").c_str(), index);
183  m_prefixes.push_back((*it)[0]);
184  m_prefixComplete.push_back(nullptr != (*it)[2]);
185  }
186  }
187  m_prefixMenu->Connect("Activated(Int_t)", "CmsShowSearchFiles", this, "prefixChoosen(Int_t)");
188  }
189  m_prefixMenu->PlaceMenu(m_choosePrefix->GetX(), m_choosePrefix->GetY(), true, true);
190 }
std::vector< bool > m_prefixComplete
static const char *const s_prefixes[][s_columns]
TGTextButton * m_choosePrefix
static const std::string s_filePrefix("file:")
TGPopupMenu * m_prefixMenu
static const std::string s_httpPrefix("http:")
std::vector< std::string > m_prefixes
static const unsigned int s_columns
void CmsShowSearchFiles::updateBrowser ( )

Member Data Documentation

TGTextButton* CmsShowSearchFiles::m_choosePrefix
private

Definition at line 60 of file CmsShowSearchFiles.h.

Referenced by CmsShowSearchFiles(), prefixChoosen(), and showPrefixes().

TGTextEntry* CmsShowSearchFiles::m_file
private
TGTextButton* CmsShowSearchFiles::m_openButton
private

Definition at line 66 of file CmsShowSearchFiles.h.

Referenced by CmsShowSearchFiles(), fileEntryChanged(), and prefixChoosen().

bool CmsShowSearchFiles::m_openCalled
private

Definition at line 67 of file CmsShowSearchFiles.h.

Referenced by chooseFileFromURL(), and openClicked().

std::vector<bool> CmsShowSearchFiles::m_prefixComplete
private

Definition at line 65 of file CmsShowSearchFiles.h.

Referenced by prefixChoosen(), and showPrefixes().

std::vector<std::string> CmsShowSearchFiles::m_prefixes
private

Definition at line 64 of file CmsShowSearchFiles.h.

Referenced by prefixChoosen(), and showPrefixes().

TGPopupMenu* CmsShowSearchFiles::m_prefixMenu
private

Definition at line 61 of file CmsShowSearchFiles.h.

Referenced by CmsShowSearchFiles(), showPrefixes(), and ~CmsShowSearchFiles().

FWHtml* CmsShowSearchFiles::m_webFile
private