CMS 3D CMS Logo

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 66 of file CmsShowSearchFiles.cc.

References fwLog, fwlog::kInfo, m_choosePrefix, m_file, m_openButton, m_prefixMenu, m_webFile, castor_dqm_sourceclient_file_cfg::path, sendToWebBrowser(), AlCaHLTBitMon_QueryRunRegistry::string, fireworks::supportedDataFormatsVersion(), testProducerWithPsetDescEmpty_cfi::x1, and testProducerWithPsetDescEmpty_cfi::x2.

68  : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h) {
69  TGVerticalFrame* vf = new TGVerticalFrame(this);
70  this->AddFrame(vf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
71  TGHorizontalFrame* urlFrame = new TGHorizontalFrame(this);
72  vf->AddFrame(urlFrame, new TGLayoutHints(kLHintsExpandX, 5, 0, 5, 5));
73 
74  TGLabel* urlLabel = new TGLabel(urlFrame, "URL");
75  urlFrame->AddFrame(urlLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1));
76  m_choosePrefix = new TGTextButton(urlFrame, "Choose Prefix");
77  urlFrame->AddFrame(m_choosePrefix, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
78 
79  m_file = new TGTextEntry(urlFrame);
80  urlFrame->AddFrame(m_file, new TGLayoutHints(kLHintsExpandX, 1, 0, 1, 1));
81  m_file->Connect("TextChanged(const char*)", "CmsShowSearchFiles", this, "fileEntryChanged(const char*)");
82  m_file->Connect("ReturnPressed()", "CmsShowSearchFiles", this, "updateBrowser()");
83 
84  m_webFile = new FWHtml(vf, 1, 1);
85  m_webFile->Connect("MouseDown(const char*)", "CmsShowSearchFiles", this, "hyperlinkClicked(const char*)");
86  vf->AddFrame(m_webFile, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 1, 1, 1, 1));
87 
88  TGHorizontalFrame* buttonFrame = new TGHorizontalFrame(vf);
89  vf->AddFrame(buttonFrame, new TGLayoutHints(kLHintsExpandX, 1, 10, 1, 10));
90 
91  m_openButton = new TGTextButton(buttonFrame, "Open");
92  buttonFrame->AddFrame(m_openButton, new TGLayoutHints(kLHintsRight, 5, 5, 1, 1));
93  m_openButton->SetEnabled(kFALSE);
94  m_openButton->Connect("Clicked()", "CmsShowSearchFiles", this, "openClicked()");
95 
96  TGTextButton* cancel = new TGTextButton(buttonFrame, "Cancel");
97  buttonFrame->AddFrame(cancel, new TGLayoutHints(kLHintsRight, 5, 5, 1, 1));
98  cancel->Connect("Clicked()", "CmsShowSearchFiles", this, "UnmapWindow()");
99 
100  SetWindowName(windowname);
101  float x1 = getURLResponseTime("lxplus.cern.ch");
102  float x2 = getURLResponseTime("uaf.t2.ucsd.edu");
103  // printf("timtes %f %f \n", x1, x2); fflush(stdout);
104 
106  if (x1 > 0 && x1 < x2)
107  path = Form("http://fireworks.web.cern.ch/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]);
108  else if (x2 > 0)
109  path = Form("http://uaf.t2.ucsd.edu/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]);
110 
111  if (!path.empty())
112  fwLog(fwlog::kInfo) << "Search files at " << path << "." << std::endl;
113 
114  sendToWebBrowser(path);
115 
116  MapSubwindows();
117  Layout();
118  m_prefixMenu = nullptr;
119  m_choosePrefix->Connect("Clicked()", "CmsShowSearchFiles", this, "showPrefixes()");
120 }
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
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)
CmsShowSearchFiles::~CmsShowSearchFiles ( )
override

Definition at line 122 of file CmsShowSearchFiles.cc.

References m_prefixMenu.

122 { 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 339 of file CmsShowSearchFiles.cc.

References m_file, m_openCalled, and AlCaHLTBitMon_QueryRunRegistry::string.

339  {
340  DontCallClose();
341  Connect("CloseWindow()", "CmsShowSearchFiles", this, "UnmapWindow()");
342  m_openCalled = false;
343  MapWindow();
344  gClient->WaitForUnmap(this);
345 
346  if (!m_openCalled) {
347  return std::string();
348  }
349  return m_file->GetText();
350 }
CmsShowSearchFiles::ClassDefOverride ( CmsShowSearchFiles  ,
 
)
void CmsShowSearchFiles::fileEntryChanged ( const char *  iFileName)

Definition at line 145 of file CmsShowSearchFiles.cc.

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

145  {
146  std::string fileName = iFileName;
147  size_t index = fileName.find_last_of(".");
148  std::string postfix;
149  if (index != std::string::npos) {
150  postfix = fileName.substr(index, std::string::npos);
151  }
152  if (postfix == s_rootPostfix) {
153  m_openButton->SetEnabled(kTRUE);
154  } else {
155  m_openButton->SetEnabled(kFALSE);
156  }
157 }
TGTextButton * m_openButton
static const std::string s_rootPostfix(".root")
void CmsShowSearchFiles::hyperlinkClicked ( const char *  iLink)

Definition at line 168 of file CmsShowSearchFiles.cc.

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

168  {
169  m_file->SetText(iLink, kTRUE);
170 
171  m_webFile->addToVisited(iLink);
172  std::string fileName = iLink;
173  size_t index = fileName.find_last_of(".");
174  std::string postfix = fileName.substr(index, std::string::npos);
175 
176  if (postfix != s_rootPostfix) {
177  updateBrowser();
178  } else {
179  openClicked();
180  }
181 }
void addToVisited(const char *iToVisit)
static const std::string s_rootPostfix(".root")
void CmsShowSearchFiles::openClicked ( )

Definition at line 185 of file CmsShowSearchFiles.cc.

References m_openCalled.

Referenced by hyperlinkClicked().

185  {
186  m_openCalled = true;
187  this->UnmapWindow();
188 }
void CmsShowSearchFiles::prefixChoosen ( Int_t  iIndex)

Definition at line 126 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().

126  {
127  // printf ("pref chosen %d \n", iIndex);
128  m_file->SetText(m_prefixes[iIndex].c_str(), kFALSE);
129  m_openButton->SetEnabled(kFALSE);
130 
131  if (m_prefixComplete[iIndex]) {
132  //gClient->NeedRedraw(this);
133  gClient->NeedRedraw(m_choosePrefix);
134  gClient->NeedRedraw(m_webFile);
135  gClient->ProcessEventsFor(this);
136  updateBrowser();
137  } else {
138  std::string p;
139  sendToWebBrowser(p);
140  }
141 }
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 290 of file CmsShowSearchFiles.cc.

References mps_fire::i, and m_webFile.

Referenced by sendToWebBrowser().

290  {
291  const static char* s_readError[] = {
292  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
293  "\"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd\"> ",
294  "<HTML><HEAD><TITLE>HTTP Read Error</TITLE> ",
295  "<META http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></HEAD> ",
296  "<BODY> ",
297  "<P>Unknown error while trying to get file via http</P>",
298  "</BODY></HTML> ",
299  nullptr};
300 
301  m_webFile->SetBaseUri("");
302  for (int i = 0; s_readError[i]; i++) {
303  m_webFile->ParseText(const_cast<char*>(s_readError[i]));
304  }
305 }
void CmsShowSearchFiles::readInfo ( )
private

Definition at line 307 of file CmsShowSearchFiles.cc.

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

Referenced by sendToWebBrowser().

307  {
308  const static char* s_noBrowserMessage[] = {
309  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
310  "\"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd\"> ",
311  "<HTML><HEAD><TITLE>No Browser Available</TITLE> ",
312  "<META http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></HEAD> ",
313  "<BODY> ",
314  //"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>",
315  //"Only a prefix beginning in <STRONG>http:</STRONG> which contains a site name (e.g. http://www.site.org) is supported for browsing."
316  "<b>Welcome....</b><BR>",
317  "<BR>",
318  "<b>You may look at examples:</b><BR>",
319  "If you are in Europe, open example data files at CERN : ",
320  " <a href=",
321  Form("http://fireworks.web.cern.ch/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]),
322  "> http://fireworks.web.cern.ch/fireworks/ </a><BR>",
323  "If you are in US, open example data files at UCSD: ",
324  " <a href=",
325  Form("http://uaf-2.t2.ucsd.edu/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]),
326  ">http://uaf-2.t2.ucsd.edu/fireworks/ </a><BR>",
327  "<BR>"
328  "<b>You also may load files with Choose Prefix </b><BR>"
329  "</BODY></HTML> ",
330  nullptr};
331 
332  m_webFile->SetBaseUri("");
333  for (int i = 0; s_noBrowserMessage[i]; i++) {
334  m_webFile->ParseText((char*)s_noBrowserMessage[i]);
335  }
336 }
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:35
void CmsShowSearchFiles::sendToWebBrowser ( std::string &  iWebFile)
private

Definition at line 253 of file CmsShowSearchFiles.cc.

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

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

253  {
254  // std::cout << "CmsShowSearchFiles::sendToWebBrowser " << fileName << std::endl ;
255 
256  size_t index = fileName.find_first_of(":");
257  if (index != std::string::npos) {
258  ++index;
259  } else {
260  index = 0;
261  }
262  std::string prefix = fileName.substr(0, index);
263 
264  m_webFile->Clear();
265  if (prefix == s_httpPrefix) {
266  gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
267  //If you clicked a hyperlink then the cursor is still a hand but we now
268  // want it to be a watch
269  gVirtualX->SetCursor(m_webFile->GetId(), gVirtualX->CreateCursor(kWatch));
270  //If we don't call ProcessEventsFor then the cursor will not be updated
271  gClient->ProcessEventsFor(this);
272  TUrl url(fileName.c_str());
273  std::string buffer = readRemote(url.GetUrl());
274 
275  if (!buffer.empty()) {
276  m_webFile->SetBaseUri(url.GetUrl());
277  m_webFile->ParseText(const_cast<char*>(buffer.c_str()));
278  } else {
279  readError();
280  }
281  gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
282  gVirtualX->SetCursor(m_webFile->GetId(), gVirtualX->CreateCursor(kPointer));
283  } else {
284  readInfo();
285  }
286  m_webFile->Layout();
287 }
static const std::string s_httpPrefix("http:")
static std::string readRemote(const char *url)
void CmsShowSearchFiles::showPrefixes ( )

Definition at line 192 of file CmsShowSearchFiles.cc.

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

192  {
193  if (nullptr == m_prefixMenu) {
194  m_prefixMenu = new TGPopupMenu(this);
195  const char* const(*itEnd)[s_columns] = s_prefixes + sizeof(s_prefixes) / sizeof(const char * [3]);
196  int index = 0;
197  for (const char* const(*it)[s_columns] = s_prefixes; it != itEnd; ++it, ++index) {
198  //only add the protocols this version of the code actually can load
199  std::string prefix = std::string((*it)[0]).substr(0, std::string((*it)[0]).find_first_of(":") + 1);
200  if (s_httpPrefix == prefix || s_filePrefix == prefix ||
201  (gPluginMgr->FindHandler("TSystem", prefix.c_str()) &&
202  gPluginMgr->FindHandler("TSystem", prefix.c_str())->CheckPlugin() != -1)) {
203  m_prefixMenu->AddEntry((std::string((*it)[0]) + " (" + ((*it)[1]) + ")").c_str(), index);
204  m_prefixes.push_back((*it)[0]);
205  m_prefixComplete.push_back(nullptr != (*it)[2]);
206  }
207  }
208  m_prefixMenu->Connect("Activated(Int_t)", "CmsShowSearchFiles", this, "prefixChoosen(Int_t)");
209  }
210  m_prefixMenu->PlaceMenu(m_choosePrefix->GetX(), m_choosePrefix->GetY(), true, true);
211 }
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