11 #include "TGTextEntry.h" 12 #include "TPluginManager.h" 16 #include "TVirtualX.h" 24 FWHtml(
const TGWindow*
p,
int w,
int h,
int id = -1) : TGHtml(p, w, h,
id) {}
40 {
"file:",
"Local file [you must type full path name]",
nullptr},
41 {
"dcap://",
"dCache [FNAL]",
nullptr},
42 {
"rfio://",
"Castor [CERN]",
nullptr}
51 float getURLResponseTime(
const char*
url) {
52 TString com =
"ping -q -c 1 -n " + TString(url) +
"| tail -n 1";
53 FILE*
p = gSystem->OpenPipe(com,
"r");
56 gSystem->ClosePipe(p);
58 TPMERegexp re(
"([\\d\\.]+)");
67 const char*
filename,
const char* windowname,
const TGWindow*
p, UInt_t
w, UInt_t
h)
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));
74 TGLabel* urlLabel =
new TGLabel(urlFrame,
"URL");
75 urlFrame->AddFrame(urlLabel,
new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 1, 1, 1, 1));
77 urlFrame->AddFrame(
m_choosePrefix,
new TGLayoutHints(kLHintsLeft, 1, 1, 1, 1));
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()");
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));
88 TGHorizontalFrame* buttonFrame =
new TGHorizontalFrame(vf);
89 vf->AddFrame(buttonFrame,
new TGLayoutHints(kLHintsExpandX, 1, 10, 1, 10));
92 buttonFrame->AddFrame(
m_openButton,
new TGLayoutHints(kLHintsRight, 5, 5, 1, 1));
94 m_openButton->Connect(
"Clicked()",
"CmsShowSearchFiles",
this,
"openClicked()");
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()");
100 SetWindowName(windowname);
101 float x1 = getURLResponseTime(
"lxplus.cern.ch");
102 float x2 = getURLResponseTime(
"uaf.t2.ucsd.edu");
106 if (x1 > 0 && x1 < x2)
119 m_choosePrefix->Connect(
"Clicked()",
"CmsShowSearchFiles",
this,
"showPrefixes()");
135 gClient->ProcessEventsFor(
this);
147 size_t index = fileName.find_last_of(
".");
149 if (index != std::string::npos) {
150 postfix = fileName.substr(index, std::string::npos);
169 m_file->SetText(iLink, kTRUE);
173 size_t index = fileName.find_last_of(
".");
174 std::string postfix = fileName.substr(index, std::string::npos);
201 (gPluginMgr->FindHandler(
"TSystem", prefix.c_str()) &&
202 gPluginMgr->FindHandler(
"TSystem", prefix.c_str())->CheckPlugin() != -1)) {
208 m_prefixMenu->Connect(
"Activated(Int_t)",
"CmsShowSearchFiles",
this,
"prefixChoosen(Int_t)");
222 TString
msg =
"GET ";
223 msg += fUrl.GetProtocol();
225 msg += fUrl.GetHost();
227 msg += fUrl.GetPort();
229 msg += fUrl.GetFile();
233 if (!uri.BeginsWith(
"http://"))
235 TSocket
s(fUrl.GetHost(), fUrl.GetPort());
238 if (
s.SendRaw(msg.Data(), msg.Length()) == -1)
240 Int_t
size = 1024 * 1024;
241 buf = (
char*)calloc(size,
sizeof(
char));
242 if (
s.RecvRaw(buf, size) == -1) {
256 size_t index = fileName.find_first_of(
":");
257 if (index != std::string::npos) {
266 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
269 gVirtualX->SetCursor(
m_webFile->GetId(), gVirtualX->CreateCursor(kWatch));
271 gClient->ProcessEventsFor(
this);
272 TUrl
url(fileName.c_str());
275 if (!buffer.empty()) {
277 m_webFile->ParseText(const_cast<char*>(buffer.c_str()));
281 gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
282 gVirtualX->SetCursor(
m_webFile->GetId(), gVirtualX->CreateCursor(kPointer));
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> ",
297 "<P>Unknown error while trying to get file via http</P>",
302 for (
int i = 0; s_readError[
i];
i++) {
303 m_webFile->ParseText(const_cast<char*>(s_readError[
i]));
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> ",
316 "<b>Welcome....</b><BR>",
318 "<b>You may look at examples:</b><BR>",
319 "If you are in Europe, open example data files at CERN : ",
322 "> http://fireworks.web.cern.ch/fireworks/ </a><BR>",
323 "If you are in US, open example data files at UCSD: ",
326 ">http://uaf-2.t2.ucsd.edu/fireworks/ </a><BR>",
328 "<b>You also may load files with Choose Prefix </b><BR>" 333 for (
int i = 0; s_noBrowserMessage[
i];
i++) {
334 m_webFile->ParseText((
char*)s_noBrowserMessage[
i]);
341 Connect(
"CloseWindow()",
"CmsShowSearchFiles",
this,
"UnmapWindow()");
344 gClient->WaitForUnmap(
this);
void prefixChoosen(Int_t)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void addToVisited(const char *iToVisit)
~CmsShowSearchFiles() override
std::vector< bool > m_prefixComplete
static const char *const s_prefixes[][s_columns]
TGTextButton * m_choosePrefix
static const std::string s_filePrefix("file:")
void fileEntryChanged(const char *)
int * supportedDataFormatsVersion()
FWHtml(const TGWindow *p, int w, int h, int id=-1)
TGPopupMenu * m_prefixMenu
int IsVisited(const char *iCheck) override
TGTextButton * m_openButton
static const std::string s_httpPrefix("http:")
std::vector< std::string > m_prefixes
static const unsigned int s_columns
std::set< std::string > m_visited
CmsShowSearchFiles(const char *filename, const char *windowname, const TGWindow *p=nullptr, UInt_t w=1, UInt_t h=1)
void sendToWebBrowser(std::string &iWebFile)
void hyperlinkClicked(const char *)
static std::string readRemote(const char *url)
std::string chooseFileFromURL()
This opens the dialog window and returns once the user has choosen, returns an empty string if cancel...
static const std::string s_rootPostfix(".root")