CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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...
 
 ClassDef (CmsShowSearchFiles, 0)
 
 CmsShowSearchFiles (const char *filename, const char *windowname, const TGWindow *p=0, 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 ()
 
virtual ~CmsShowSearchFiles ()
 

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 = 0,
UInt_t  w = 1,
UInt_t  h = 1 
)

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

75  : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h)
76 {
77  TGVerticalFrame* vf = new TGVerticalFrame(this);
78  this->AddFrame(vf,new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,5,5,5,5));
79  TGHorizontalFrame* urlFrame = new TGHorizontalFrame(this);
80  vf->AddFrame(urlFrame,new TGLayoutHints(kLHintsExpandX,5,0,5,5));
81 
82  TGLabel* urlLabel = new TGLabel(urlFrame,"URL");
83  urlFrame->AddFrame(urlLabel, new TGLayoutHints(kLHintsLeft|kLHintsCenterY,1,1,1,1));
84  m_choosePrefix = new TGTextButton(urlFrame,"Choose Prefix");
85  urlFrame->AddFrame(m_choosePrefix, new TGLayoutHints(kLHintsLeft,1,1,1,1));
86 
87  m_file= new TGTextEntry(urlFrame);
88  urlFrame->AddFrame(m_file, new TGLayoutHints(kLHintsExpandX,1,0,1,1));
89  m_file->Connect("TextChanged(const char*)", "CmsShowSearchFiles",this,"fileEntryChanged(const char*)");
90  m_file->Connect("ReturnPressed()", "CmsShowSearchFiles",this,"updateBrowser()");
91 
92  m_webFile = new FWHtml(vf,1,1);
93  m_webFile->Connect("MouseDown(const char*)","CmsShowSearchFiles",this,"hyperlinkClicked(const char*)");
94  vf->AddFrame(m_webFile, new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,1,1,1,1));
95 
96  TGHorizontalFrame* buttonFrame = new TGHorizontalFrame(vf);
97  vf->AddFrame(buttonFrame, new TGLayoutHints(kLHintsExpandX,1,10,1,10));
98 
99  m_openButton = new TGTextButton(buttonFrame,"Open");
100  buttonFrame->AddFrame(m_openButton, new TGLayoutHints(kLHintsRight,5,5,1,1));
101  m_openButton->SetEnabled(kFALSE);
102  m_openButton->Connect("Clicked()","CmsShowSearchFiles",this,"openClicked()");
103 
104  TGTextButton* cancel = new TGTextButton(buttonFrame,"Cancel");
105  buttonFrame->AddFrame(cancel, new TGLayoutHints(kLHintsRight,5,5,1,1));
106  cancel->Connect("Clicked()","CmsShowSearchFiles",this,"UnmapWindow()");
107 
108  SetWindowName(windowname);
109  float x1 = getURLResponseTime("lxplus.cern.ch");
110  float x2 = getURLResponseTime("uaf.t2.ucsd.edu");
111  // printf("timtes %f %f \n", x1, x2); fflush(stdout);
112 
114  if (x1 > 0 && x1 < x2)
115  path = Form("http://fireworks.web.cern.ch/fireworks/%d/",fireworks::supportedDataFormatsVersion()[0] );
116  else if (x2 > 0)
117  path = Form("http://uaf.t2.ucsd.edu/fireworks/%d/", fireworks::supportedDataFormatsVersion()[0]);
118 
119  if (!path.empty())
120  fwLog(fwlog::kInfo) << "Search files at " << path << "." << std::endl;
121 
122  sendToWebBrowser(path);
123 
124 
125  MapSubwindows();
126  Layout();
127  m_prefixMenu=0;
128  m_choosePrefix->Connect("Clicked()","CmsShowSearchFiles",this,"showPrefixes()");
129 }
const double w
Definition: UKUtility.cc:23
TGTextButton * m_choosePrefix
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:43
TGPopupMenu * m_prefixMenu
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
TGTextButton * m_openButton
#define fwLog(_level_)
Definition: fwLog.h:50
void sendToWebBrowser(std::string &iWebFile)
CmsShowSearchFiles::~CmsShowSearchFiles ( )
virtual

Definition at line 131 of file CmsShowSearchFiles.cc.

References m_prefixMenu.

132 {
133  delete m_prefixMenu;
134 }
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 375 of file CmsShowSearchFiles.cc.

References m_file, m_openCalled, and AlCaHLTBitMon_QueryRunRegistry::string.

376 {
377  DontCallClose();
378  Connect("CloseWindow()","CmsShowSearchFiles",this,"UnmapWindow()");
379  m_openCalled = false;
380  MapWindow();
381  gClient->WaitForUnmap(this);
382 
383  if(!m_openCalled) {
384  return std::string();
385  }
386  return m_file->GetText();
387 }
CmsShowSearchFiles::ClassDef ( CmsShowSearchFiles  ,
 
)
void CmsShowSearchFiles::fileEntryChanged ( const char *  iFileName)

Definition at line 161 of file CmsShowSearchFiles.cc.

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

162 {
163  std::string fileName =iFileName;
164  size_t index = fileName.find_last_of(".");
165  std::string postfix;
166  if(index != std::string::npos) {
167  postfix=fileName.substr(index,std::string::npos);
168  }
169  if(postfix ==s_rootPostfix) {
170  m_openButton->SetEnabled(kTRUE);
171  } else {
172  m_openButton->SetEnabled(kFALSE);
173  }
174 }
TGTextButton * m_openButton
static const std::string s_rootPostfix(".root")
void CmsShowSearchFiles::hyperlinkClicked ( const char *  iLink)

Definition at line 189 of file CmsShowSearchFiles.cc.

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

190 {
191  m_file->SetText(iLink,kTRUE);
192 
193  m_webFile->addToVisited(iLink);
194  std::string fileName =iLink;
195  size_t index = fileName.find_last_of(".");
196  std::string postfix = fileName.substr(index,std::string::npos);
197 
198  if(postfix !=s_rootPostfix) {
199  updateBrowser();
200  } else {
201  openClicked();
202  }
203 }
void addToVisited(const char *iToVisit)
static const std::string s_rootPostfix(".root")
void CmsShowSearchFiles::openClicked ( )

Definition at line 208 of file CmsShowSearchFiles.cc.

References m_openCalled.

Referenced by hyperlinkClicked().

209 {
210  m_openCalled=true;
211  this->UnmapWindow();
212 }
void CmsShowSearchFiles::prefixChoosen ( Int_t  iIndex)

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

140 {
141  // printf ("pref chosen %d \n", iIndex);
142  m_file->SetText(m_prefixes[iIndex].c_str(),kFALSE);
143  m_openButton->SetEnabled(kFALSE);
144 
145  if(m_prefixComplete[iIndex]) {
146  //gClient->NeedRedraw(this);
147  gClient->NeedRedraw(m_choosePrefix);
148  gClient->NeedRedraw(m_webFile);
149  gClient->ProcessEventsFor(this);
150  updateBrowser();
151  } else {
152  std::string p;
153  sendToWebBrowser(p);
154  }
155 }
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 326 of file CmsShowSearchFiles.cc.

References i, and m_webFile.

Referenced by sendToWebBrowser().

327 {
328 
329  const static char *s_readError[] = {
330  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd\"> ",
331  "<HTML><HEAD><TITLE>HTTP Read Error</TITLE> ",
332  "<META http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></HEAD> ",
333  "<BODY> ",
334  "<P>Unknown error while trying to get file via http</P>",
335  "</BODY></HTML> ",
336  0
337  };
338 
339  m_webFile->SetBaseUri("");
340  for (int i=0; s_readError[i]; i++) {
341  m_webFile->ParseText(const_cast<char *>(s_readError[i]));
342  }
343 }
int i
Definition: DBlmapReader.cc:9
void CmsShowSearchFiles::readInfo ( )
private

Definition at line 346 of file CmsShowSearchFiles.cc.

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

Referenced by sendToWebBrowser().

347 {
348  const static char *s_noBrowserMessage[] = {
349  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd\"> ",
350  "<HTML><HEAD><TITLE>No Browser Available</TITLE> ",
351  "<META http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></HEAD> ",
352  "<BODY> ",
353  //"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>",
354  //"Only a prefix beginning in <STRONG>http:</STRONG> which contains a site name (e.g. http://www.site.org) is supported for browsing."
355  "<b>Welcome....</b><BR>",
356  "<BR>",
357  "<b>You may look at examples:</b><BR>",
358  "If you are in Europe, open example data files at CERN : ", " <a href=" , Form("http://fireworks.web.cern.ch/fireworks/%d/",fireworks::supportedDataFormatsVersion()[0] ),"> http://fireworks.web.cern.ch/fireworks/ </a><BR>",
359  "If you are in US, open example data files at UCSD: ", " <a href=" , Form("http://uaf-2.t2.ucsd.edu/fireworks/%d/",fireworks::supportedDataFormatsVersion()[0] ),">http://uaf-2.t2.ucsd.edu/fireworks/ </a><BR>",
360  "<BR>"
361  "<b>You also may load files with Choose Prefix </b><BR>"
362  "</BODY></HTML> ",
363  0
364  };
365 
366  m_webFile->SetBaseUri("");
367  for (int i=0; s_noBrowserMessage[i]; i++) {
368  m_webFile->ParseText((char *)s_noBrowserMessage[i]);
369  }
370 
371 }
int i
Definition: DBlmapReader.cc:9
int * supportedDataFormatsVersion()
Definition: fwPaths.cc:43
void CmsShowSearchFiles::sendToWebBrowser ( std::string &  iWebFile)
private

Definition at line 286 of file CmsShowSearchFiles.cc.

References cmsHarvester::index, m_webFile, prof2calltree::prefix, readError(), readInfo(), readRemote(), s_httpPrefix(), AlCaHLTBitMon_QueryRunRegistry::string, and relmon_authenticated_wget::url.

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

287 {
288  // std::cout << "CmsShowSearchFiles::sendToWebBrowser " << fileName << std::endl ;
289 
290  size_t index = fileName.find_first_of(":");
291  if(index != std::string::npos) {
292  ++index;
293  } else {
294  index = 0;
295  }
296  std::string prefix = fileName.substr(0,index);
297 
298  m_webFile->Clear();
299  if(prefix == s_httpPrefix) {
300  gVirtualX->SetCursor(GetId(),gVirtualX->CreateCursor(kWatch));
301  //If you clicked a hyperlink then the cursor is still a hand but we now
302  // want it to be a watch
303  gVirtualX->SetCursor(m_webFile->GetId(),gVirtualX->CreateCursor(kWatch));
304  //If we don't call ProcessEventsFor then the cursor will not be updated
305  gClient->ProcessEventsFor(this);
306  TUrl url(fileName.c_str());
307  std::string buffer = readRemote(url.GetUrl());
308 
309  if (buffer.size()) {
310  m_webFile->SetBaseUri(url.GetUrl());
311  m_webFile->ParseText(const_cast<char*>(buffer.c_str()));
312  }
313  else {
314  readError();
315  }
316  gVirtualX->SetCursor(GetId(),gVirtualX->CreateCursor(kPointer));
317  gVirtualX->SetCursor(m_webFile->GetId(),gVirtualX->CreateCursor(kPointer));
318  } else {
319  readInfo();
320  }
321  m_webFile->Layout();
322 }
static const std::string s_httpPrefix("http:")
static std::string readRemote(const char *url)
void CmsShowSearchFiles::showPrefixes ( )

Definition at line 217 of file CmsShowSearchFiles.cc.

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

218 {
219  if(0==m_prefixMenu) {
220  m_prefixMenu = new TGPopupMenu(this);
221  const char* const (*itEnd)[s_columns] = s_prefixes+sizeof(s_prefixes)/sizeof(const char*[3]);
222  int index = 0;
223  for(const char* const (*it)[s_columns] = s_prefixes;
224  it != itEnd;
225  ++it,++index) {
226  //only add the protocols this version of the code actually can load
227  std::string prefix = std::string((*it)[0]).substr(0,std::string((*it)[0]).find_first_of(":")+1);
228  if(s_httpPrefix==prefix ||
229  s_filePrefix==prefix ||
230  (gPluginMgr->FindHandler("TSystem",prefix.c_str()) &&
231  gPluginMgr->FindHandler("TSystem",prefix.c_str())->CheckPlugin() != -1)) {
232  m_prefixMenu->AddEntry((std::string((*it)[0])+" ("+((*it)[1])+")").c_str(),index);
233  m_prefixes.push_back((*it)[0]);
234  m_prefixComplete.push_back(0!=(*it)[2]);
235  }
236  }
237  m_prefixMenu->Connect("Activated(Int_t)","CmsShowSearchFiles",this,"prefixChoosen(Int_t)");
238  }
239  m_prefixMenu->PlaceMenu(m_choosePrefix->GetX(),m_choosePrefix->GetY(),true,true);
240 }
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 ( )

Definition at line 179 of file CmsShowSearchFiles.cc.

References m_file, gen::n, sendToWebBrowser(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by hyperlinkClicked(), and prefixChoosen().

180 {
181  std::string n = m_file->GetText();
182  sendToWebBrowser(n);
183 }
void sendToWebBrowser(std::string &iWebFile)

Member Data Documentation

TGTextButton* CmsShowSearchFiles::m_choosePrefix
private

Definition at line 63 of file CmsShowSearchFiles.h.

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

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

Definition at line 69 of file CmsShowSearchFiles.h.

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

bool CmsShowSearchFiles::m_openCalled
private

Definition at line 70 of file CmsShowSearchFiles.h.

Referenced by chooseFileFromURL(), and openClicked().

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

Definition at line 68 of file CmsShowSearchFiles.h.

Referenced by prefixChoosen(), and showPrefixes().

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

Definition at line 67 of file CmsShowSearchFiles.h.

Referenced by prefixChoosen(), and showPrefixes().

TGPopupMenu* CmsShowSearchFiles::m_prefixMenu
private

Definition at line 64 of file CmsShowSearchFiles.h.

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

FWHtml* CmsShowSearchFiles::m_webFile
private