CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CmsShowMain.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : CmsShowMain
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Mon Dec 3 08:38:38 PST 2007
11 //
12 
13 // system include files
14 #include <sstream>
15 #include <boost/bind.hpp>
16 #include <boost/program_options.hpp>
17 #include <string.h>
18 
19 #include "TSystem.h"
20 #include "TGLWidget.h"
21 #include "TTimer.h"
22 #include "TROOT.h"
23 #include "TGFileDialog.h"
24 #include "TGMsgBox.h"
25 #include "TMonitor.h"
26 #include "TServerSocket.h"
27 #include "TEveLine.h"
28 #include "TEveManager.h"
29 #include "TFile.h"
30 #include "TGClient.h"
31 #include <KeySymbols.h>
32 
34 
36 
50 
55 
57 
61 
63 
65 
66 #if defined(R__LINUX)
67 #include "TGX11.h" // !!!! AMT has to be at the end to pass build
68 #include "X11/Xlib.h"
69 #endif
70 //
71 // constants, enums and typedefs
72 //
73 
74 static const char* const kInputFilesOpt = "input-files";
75 static const char* const kInputFilesCommandOpt = "input-files,i";
76 static const char* const kConfigFileOpt = "config-file";
77 static const char* const kConfigFileCommandOpt = "config-file,c";
78 static const char* const kGeomFileOpt = "geom-file";
79 static const char* const kGeomFileCommandOpt = "geom-file,g";
80 static const char* const kSimGeomFileOpt = "sim-geom-file";
81 static const char* const kSimGeomFileCommandOpt= "sim-geom-file";
82 static const char* const kNoConfigFileOpt = "noconfig";
83 static const char* const kNoConfigFileCommandOpt = "noconfig,n";
84 static const char* const kPlayOpt = "play";
85 static const char* const kPlayCommandOpt = "play,p";
86 static const char* const kLoopOpt = "loop";
87 static const char* const kLoopCommandOpt = "loop";
88 static const char* const kLogLevelCommandOpt = "log";
89 static const char* const kLogLevelOpt = "log";
90 static const char* const kEveOpt = "eve";
91 static const char* const kEveCommandOpt = "eve";
92 static const char* const kAdvancedRenderOpt = "shine";
93 static const char* const kAdvancedRenderCommandOpt = "shine,s";
94 static const char* const kHelpOpt = "help";
95 static const char* const kHelpCommandOpt = "help,h";
96 static const char* const kSoftCommandOpt = "soft";
97 static const char* const kExpertCommandOpt = "expert";
98 static const char* const kPortCommandOpt = "port";
99 static const char* const kPlainRootCommandOpt = "prompt";
100 static const char* const kRootInteractiveCommandOpt = "root-interactive,r";
101 static const char* const kChainCommandOpt = "chain";
102 static const char* const kLiveCommandOpt = "live";
103 static const char* const kFieldCommandOpt = "field";
104 static const char* const kFreePaletteCommandOpt = "free-palette";
105 static const char* const kAutoSaveAllViews = "auto-save-all-views";
106 static const char* const kAutoSaveType = "auto-save-type";
107 static const char* const kAutoSaveHeight = "auto-save-height";
108 static const char* const kSyncAllViews = "sync-all-views";
109 static const char* const kEnableFPE = "enable-fpe";
110 static const char* const kZeroWinOffsets = "zero-window-offsets";
111 static const char* const kNoVersionCheck = "no-version-check";
112 
113 
114 //
115 // constructors and destructor
116 //
118  : CmsShowMainBase(),
119  m_navigator(new CmsShowNavigator(*this)),
120  m_metadataManager(new FWLiteJobMetadataManager()),
121  m_context(new fireworks::Context(changeManager(),
122  selectionManager(),
123  eiManager(),
124  colorManager(),
125  m_metadataManager.get())),
126  m_loadedAnyInputFile(false),
127  m_openFile(0),
128  m_live(false),
129  m_liveTimer(new SignalTimer()),
130  m_liveTimeout(600000),
131  m_lastXEventSerial(0),
132  m_noVersionCheck(false)
133 {
134  try {
135  TGLWidget* w = TGLWidget::Create(gClient->GetDefaultRoot(), kTRUE, kTRUE, 0, 10, 10);
136  delete w;
137  }
138  catch (std::exception& iException) {
139  fwLog(fwlog::kError) << "Failed creating an OpenGL window: " << iException.what() << "\n"
140  "Things to check:\n"
141  "- Is DISPLAY environment variable set?\n"
142  "- Are OpenGL libraries installed?\n"
143  "- If running remotely, make sure you use 'ssh -X' or 'ssh -Y'.\n"
144  "See also: https://twiki.cern.ch/twiki/bin/viewauth/CMS/WorkBookFireworks\n";
145  gSystem->Exit(1);
146  }
147 
148  eiManager()->setContext(m_context.get());
149 
150 
151  std::string descString(argv[0]);
152  descString += " [options] <data file>\nGeneral";
153 
154  namespace po = boost::program_options;
155  po::options_description desc(descString);
156  desc.add_options()
157  (kInputFilesCommandOpt, po::value< std::vector<std::string> >(), "Input root files")
158  (kConfigFileCommandOpt, po::value<std::string>(), "Include configuration file")
159  (kNoConfigFileCommandOpt, "Empty configuration")
160  (kNoVersionCheck, "No file version check")
161  (kGeomFileCommandOpt, po::value<std::string>(), "Reco geometry file. Default is cmsGeom10.root")
162  (kSimGeomFileCommandOpt,po::value<std::string>(), "Geometry file for browsing in table view. Default is CmsSimGeom-14.root. Can be simulation or reco geometry in TGeo format")
163  (kFieldCommandOpt, po::value<double>(), "Set magnetic field value explicitly. Default is auto-field estimation")
164  (kRootInteractiveCommandOpt, "Enable root interactive prompt")
165  (kSoftCommandOpt, "Try to force software rendering to avoid problems with bad hardware drivers")
166  (kExpertCommandOpt, "Enable PF user plugins.")
167  (kHelpCommandOpt, "Display help message");
168 
169  po::options_description livedesc("Live Event Display");
170  livedesc.add_options()
171  (kPlayCommandOpt, po::value<float>(), "Start in play mode with given interval between events in seconds")
172  (kPortCommandOpt, po::value<unsigned int>(), "Listen to port for new data files to open")
173  (kLoopCommandOpt, "Loop events in play mode")
174  (kChainCommandOpt, po::value<unsigned int>(), "Chain up to a given number of recently open files. Default is 1 - no chain")
175  (kLiveCommandOpt, "Enforce playback mode if a user is not using display")
176  (kAutoSaveAllViews, po::value<std::string>(), "Auto-save all views with given prefix (run_event_lumi_view.<auto-save-type> is appended)")
177  (kAutoSaveType, po::value<std::string>(), "Image type of auto-saved views, png or jpg (png is default)")
178  (kAutoSaveHeight, po::value<int>(), "Screenshots height when auto-save-all-views is enabled")
179  (kSyncAllViews, "Synchronize all views on new event");
180 
181  po::options_description debugdesc("Debug");
182  debugdesc.add_options()
183  (kLogLevelCommandOpt, po::value<unsigned int>(), "Set log level starting from 0 to 4 : kDebug, kInfo, kWarning, kError")
184  (kEveCommandOpt, "Show TEveBrowser to help debug problems")
185  (kEnableFPE, "Enable detection of floating-point exceptions");
186 
187 
188  po::options_description rnrdesc("Appearance");
189  rnrdesc.add_options()
190  (kFreePaletteCommandOpt, "Allow free color selection (requires special configuration!)")
191  (kZeroWinOffsets, "Disable auto-detection of window position offsets")
192  (kAdvancedRenderCommandOpt, "Enable line anti-aliasing");
193  po::positional_options_description p;
194  p.add(kInputFilesOpt, -1);
195 
196 
197  po::options_description hiddendesc("hidden");
198  hiddendesc.add_options();
199 
200  po::options_description all("");
201  all.add(desc).add(rnrdesc).add(livedesc).add(debugdesc);
202 
203 
204  int newArgc = argc;
205  char **newArgv = argv;
206  po::variables_map vm;
207  try{
208  po::store(po::command_line_parser(newArgc, newArgv).
209  options(all).positional(p).run(), vm);
210 
211  po::notify(vm);
212  }
213  catch ( const std::exception& e)
214  {
215  // Return with exit status 0 to avoid generating crash reports
216 
217  fwLog(fwlog::kError) << e.what() << std::endl;
218  std::cout << all <<std::endl;
219  exit(0);
220  }
221 
222  if(vm.count(kHelpOpt)) {
223  std::cout << all <<std::endl;
224  exit(0);
225  }
226 
227  if(vm.count(kLogLevelOpt)) {
228  fwlog::LogLevel level = (fwlog::LogLevel)(vm[kLogLevelOpt].as<unsigned int>());
230  }
231 
232  if(vm.count(kPlainRootCommandOpt)) {
233  fwLog(fwlog::kInfo) << "Plain ROOT prompt requested" << std::endl;
234  return;
235  }
236 
237  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
238  if(0 == cmspath) {
239  throw std::runtime_error("CMSSW_BASE environment variable not set");
240  }
241 
242  // input file
243  if (vm.count(kInputFilesOpt)) {
244  m_inputFiles = vm[kInputFilesOpt].as< std::vector<std::string> >();
245  }
246 
247  if (!m_inputFiles.size())
248  fwLog(fwlog::kInfo) << "No data file given." << std::endl;
249  else if (m_inputFiles.size() == 1)
250  fwLog(fwlog::kInfo) << "Input " << m_inputFiles.front() << std::endl;
251  else
252  fwLog(fwlog::kInfo) << m_inputFiles.size() << " input files; first: " << m_inputFiles.front() << ", last: " << m_inputFiles.back() << std::endl;
253 
254  // configuration file
255  if (vm.count(kConfigFileOpt)) {
256  setConfigFilename(vm[kConfigFileOpt].as<std::string>());
257  if (access(configFilename(), R_OK) == -1)
258  {
259  fwLog(fwlog::kError) << "Specified configuration file does not exist. Quitting.\n";
260  exit(1);
261  }
262 
263  fwLog(fwlog::kInfo) << "Config " << configFilename() << std::endl;
264  } else {
265  if (vm.count(kNoConfigFileOpt)) {
266  fwLog(fwlog::kInfo) << "No configuration is loaded.\n";
268  }
269  }
270 
271  // geometry
272  if (vm.count(kGeomFileOpt)) {
273  setGeometryFilename(vm[kGeomFileOpt].as<std::string>());
274  fwLog(fwlog::kInfo) << "Geometry file " << geometryFilename() << "\n";
275  } else {
276  // fwLog(fwlog::kInfo) << "No geom file name. Choosing default.\n";
277  setGeometryFilename("cmsGeom10.root");
278  }
279 
280  if (vm.count(kSimGeomFileOpt)) {
281  setSimGeometryFilename(vm[kSimGeomFileOpt].as<std::string>());
282  } else {
283  setSimGeometryFilename("cmsSimGeom-14.root");
284  }
285  // Free-palette palette
286  if (vm.count(kFreePaletteCommandOpt)) {
288  fwLog(fwlog::kInfo) << "Palette restriction removed on user request!\n";
289  }
290  bool eveMode = vm.count(kEveOpt);
291 
292  //Delay creating guiManager and enabling autoloading until here so that if we have a 'help' request we don't
293  // open any graphics or build dictionaries
295 
296  TEveManager::Create(kFALSE, eveMode ? "FIV" : "FI");
297 
298  if(vm.count(kExpertCommandOpt))
299  {
300  m_context->setHidePFBuilders(false);
301  }
302  else {
303  m_context->setHidePFBuilders(true);
304  }
305 
306  setup(m_navigator.get(), m_context.get(), m_metadataManager.get());
307 
308  if (vm.count(kZeroWinOffsets))
309  {
311  fwLog(fwlog::kInfo) << "Window offsets reset on user request!\n";
312  }
313 
314  if ( vm.count(kAdvancedRenderOpt) )
315  {
316  TEveLine::SetDefaultSmooth(kTRUE);
317  }
318 
319  //figure out where to find macros
320  //tell ROOT where to find our macros
322  // first check if port is not occupied
323  if (vm.count(kPortCommandOpt)) {
324  f=boost::bind(&CmsShowMain::setupSocket, this, vm[kPortCommandOpt].as<unsigned int>());
325  startupTasks()->addTask(f);
326  }
327 
328  f=boost::bind(&CmsShowMainBase::loadGeometry,this);
329  startupTasks()->addTask(f);
330  f=boost::bind(&CmsShowMainBase::setupViewManagers,this);
331  startupTasks()->addTask(f);
332 
333 
334 
335  if(vm.count(kLiveCommandOpt))
336  {
337  f = boost::bind(&CmsShowMain::setLiveMode, this);
338  startupTasks()->addTask(f);
339  }
340 
341  if(vm.count(kFieldCommandOpt))
342  {
343  m_context->getField()->setSource(FWMagField::kUser);
344  m_context->getField()->setUserField(vm[kFieldCommandOpt].as<double>());
345  }
346 
347  if ( m_inputFiles.empty()) {
348  f=boost::bind(&CmsShowMainBase::setupConfiguration,this);
349  startupTasks()->addTask(f);
350  f=boost::bind(&CmsShowMain::setupDataHandling,this);
351  startupTasks()->addTask(f);
352  }
353  else {
354  f=boost::bind(&CmsShowMain::setupDataHandling,this);
355  startupTasks()->addTask(f);
356  f=boost::bind(&CmsShowMainBase::setupConfiguration,this);
357  startupTasks()->addTask(f);
358  }
359 
360  if (vm.count(kLoopOpt))
361  setPlayLoop();
362 
363  if (eveMode) {
364  f = boost::bind(&CmsShowMainBase::setupDebugSupport,this);
365  startupTasks()->addTask(f);
366  }
367  if(vm.count(kChainCommandOpt)) {
368  f = boost::bind(&CmsShowNavigator::setMaxNumberOfFilesToChain, m_navigator.get(), vm[kChainCommandOpt].as<unsigned int>());
369  startupTasks()->addTask(f);
370  }
371  if (vm.count(kPlayOpt)) {
372  f = boost::bind(&CmsShowMainBase::setupAutoLoad, this, vm[kPlayOpt].as<float>());
373  startupTasks()->addTask(f);
374  }
375 
376  if(vm.count(kAutoSaveAllViews)) {
377  std::string type = "png";
378  if(vm.count(kAutoSaveType)) {
379  type = vm[kAutoSaveType].as<std::string>();
380  if (type != "png" && type != "jpg")
381  {
382  fwLog(fwlog::kError) << "Specified auto-save type not supported. Quitting.\n";
383  exit(1);
384  }
385  }
387  fmt += "%u_%u_%llu_%s.";
388  fmt += type;
390  }
391  if (vm.count(kAutoSaveHeight)) {
393  }
394  if (vm.count(kSyncAllViews)) {
396  }
397  if(vm.count(kNoVersionCheck)) {
398  m_noVersionCheck=true;
399  }
400  if(vm.count(kEnableFPE)) {
401  gSystem->SetFPEMask();
402  }
403 
404  if (vm.count(kPortCommandOpt)) {
405  f=boost::bind(&CmsShowMain::connectSocket, this);
406  startupTasks()->addTask(f);
407  }
408 
410 }
411 
412 //
413 // Destruction
414 //
415 
417 {
418  //avoids a seg fault from eve which happens if eve is terminated after the GUI is gone
420 }
421 
422 class DieTimer : public TTimer
423 {
424 protected:
426 public:
427  DieTimer(CmsShowMain* app) : TTimer(), fApp(app)
428  {
429  Start(0, kTRUE);
430  }
431 
432  virtual Bool_t Notify() override
433  {
434  TurnOff();
435  fApp->doExit();
436  delete this;
437  return kFALSE;
438  }
439 };
440 
442 {
443  new DieTimer(this);
444 }
445 
447 {
448  // pre terminate eve
449  m_context->deleteEveElements();
451 
452  // sleep at least 150 ms
453  // windows in ROOT GUI are destroyed in 150 ms timeout after
454  gSystem->Sleep(151);
455  gSystem->ProcessEvents();
456  gSystem->ExitLoop();
457 }
458 
459 //
460 // assignment operators
461 //
462 // const CmsShowMain& CmsShowMain::operator=(const CmsShowMain& rhs)
463 // {
464 // //An exception safe implementation is
465 // CmsShowMain temp(rhs);
466 // swap(rhs);
467 //
468 // return *this;
469 // }
470 
471 //
472 // member functions
473 //
474 
475 const fwlite::Event*
477 {
478  if (m_navigator.get())
479  return static_cast<const fwlite::Event*>(m_navigator->getCurrentEvent());
480  return 0;
481 }
482 
483 void
485 {
486  m_openFile = file;
487  if (file)
488  guiManager()->titleChanged(m_navigator->frameTitle());
489 
491 }
492 
493 void
495 {
497  guiManager()->titleChanged(m_navigator->frameTitle());
499 }
500 
502  //printf("Need to reset\n");
503 }
504 
506 {
507  const char* kRootType[] = {"ROOT files","*.root", 0, 0};
508  TGFileInfo fi;
509  fi.fFileTypes = kRootType;
510  /* this is how things used to be done:
511  fi.fIniDir = ".";
512  this is bad because the destructor calls delete[] on fIniDir.
513  */
514  fi.fIniDir = new char[128];
515  strncpy(fi.fIniDir, ".", 127);
516  guiManager()->updateStatus("waiting for data file ...");
517  new TGFileDialog(gClient->GetDefaultRoot(), guiManager()->getMainFrame(), kFDOpen, &fi);
518  guiManager()->updateStatus("loading file ...");
519  if (fi.fFilename) {
520  m_navigator->openFile(fi.fFilename);
521  m_loadedAnyInputFile = true;
522  m_navigator->firstEvent();
523  checkPosition();
524  draw();
525  }
526  guiManager()->clearStatus();
527 }
528 
530 {
531  const char* kRootType[] = {"ROOT files","*.root", 0, 0};
532  TGFileInfo fi;
533  fi.fFileTypes = kRootType;
534  /* this is how things used to be done:
535  fi.fIniDir = ".";
536  this is bad because the destructor calls delete[] on fIniDir.
537  */
538  fi.fIniDir = new char[128];
539  strncpy(fi.fIniDir, ".", 127);
540  guiManager()->updateStatus("waiting for data file ...");
541  new TGFileDialog(gClient->GetDefaultRoot(), guiManager()->getMainFrame(), kFDOpen, &fi);
542  guiManager()->updateStatus("loading file ...");
543  if (fi.fFilename) {
544  m_navigator->appendFile(fi.fFilename, false, false);
545  m_loadedAnyInputFile = true;
546  checkPosition();
547  draw();
548  guiManager()->titleChanged(m_navigator->frameTitle());
549  }
550  guiManager()->clearStatus();
551 }
552 
553 void
555 {
556  if (m_searchFiles.get() == 0) {
557  m_searchFiles = std::auto_ptr<CmsShowSearchFiles>(new CmsShowSearchFiles("",
558  "Open Remote Data Files",
559  guiManager()->getMainFrame(),
560  500, 400));
561  m_searchFiles->CenterOnParent(kTRUE,TGTransientFrame::kBottomRight);
562  }
563  std::string chosenFile = m_searchFiles->chooseFileFromURL();
564  if(!chosenFile.empty()) {
565  guiManager()->updateStatus("loading file ...");
566  if(m_navigator->openFile(chosenFile.c_str())) {
567  m_loadedAnyInputFile = true;
568  m_navigator->firstEvent();
569  checkPosition();
570  draw();
571  guiManager()->clearStatus();
572  } else {
573  guiManager()->updateStatus("failed to load data file");
574  }
575  }
576 }
577 
578 //
579 // const member functions
580 //
581 
582 //_______________________________________________________________________________
583 void
585 {
587 
588  // case when start with no input file
590  {
591  if (m_monitor.get())
593  return;
594  }
595 
596  bool reachedEnd = (forward() && m_navigator->isLastEvent()) || (!forward() && m_navigator->isFirstEvent());
597 
598  if (loop() && reachedEnd)
599  {
600  forward() ? m_navigator->firstEvent() : m_navigator->lastEvent();
601  draw();
602  }
603  else if (!reachedEnd)
604  {
605  forward() ? m_navigator->nextEvent() : m_navigator->previousEvent();
606  draw();
607  }
608 
609  // stop loop in case no loop or monitor mode
610  if (reachedEnd && (loop() || m_monitor.get()) == kFALSE)
611  {
612  if (forward() && m_navigator->isLastEvent())
613  {
615  checkPosition();
616  }
617 
618  if ((!forward()) && m_navigator->isFirstEvent())
619  {
621  checkPosition();
622  }
623  }
624  else
626 }
627 
628 //______________________________________________________________________________
629 
630 void
632 {
633  if ((m_monitor.get() || loop() ) && isPlaying())
634  return;
635 
637 
638  if (m_navigator->isFirstEvent())
640 
641  if (m_navigator->isLastEvent())
642  {
643  guiManager()->disableNext();
644  // force enable play events action in --port mode
645  if (m_monitor.get() && !guiManager()->playEventsAction()->isEnabled())
647  }
648 }
649 
650 //==============================================================================
651 void
653 {
654  guiManager()->updateStatus("Setting up data handling...");
655 
656 
657  // navigator filtering ->
658  m_navigator->fileChanged_.connect(boost::bind(&CmsShowMain::fileChangedSlot, this, _1));
659  m_navigator->editFiltersExternally_.connect(boost::bind(&FWGUIManager::updateEventFilterEnable, guiManager(), _1));
660  m_navigator->filterStateChanged_.connect(boost::bind(&CmsShowMain::navigatorChangedFilterState, this, _1));
661  m_navigator->postFiltering_.connect(boost::bind(&CmsShowMain::postFiltering, this, _1));
662 
663  // navigator fitlering <-
666 
667  // Data handling. File related and therefore not in the base class.
668  if (guiManager()->getAction(cmsshow::sOpenData) != 0)
669  guiManager()->getAction(cmsshow::sOpenData)->activated.connect(sigc::mem_fun(*this, &CmsShowMain::openData));
670  if (guiManager()->getAction(cmsshow::sAppendData) != 0)
671  guiManager()->getAction(cmsshow::sAppendData)->activated.connect(sigc::mem_fun(*this, &CmsShowMain::appendData));
672  if (guiManager()->getAction(cmsshow::sSearchFiles) != 0)
674 
675  setupActions();
676  // init data from CmsShowNavigator configuration, can do this with signals since there were not connected yet
677  guiManager()->setFilterButtonIcon(m_navigator->getFilterState());
678 
679  for (unsigned int ii = 0; ii < m_inputFiles.size(); ++ii)
680  {
681  const std::string& fname = m_inputFiles[ii];
682  if (fname.empty())
683  continue;
684  guiManager()->updateStatus("loading data file ...");
685  if (!m_navigator->appendFile(fname, false, false))
686  {
687  guiManager()->updateStatus("failed to load data file");
688  }
689  else
690  {
691  m_loadedAnyInputFile = true;
692 
693  }
694  }
695 
697  {
698  m_navigator->firstEvent();
699  checkPosition();
700  draw();
701  }
702  else if (m_monitor.get() == 0 && (configurationManager()->getIgnore() == false) )
703  {
704  if (m_inputFiles.empty())
705  openDataViaURL();
706  else
707  openData();
708  }
709 }
710 
711 void
712 CmsShowMain::setupSocket(unsigned int iSocket)
713 {
714  m_monitor = std::auto_ptr<TMonitor>(new TMonitor);
715  TServerSocket* server = new TServerSocket(iSocket,kTRUE);
716  if (server->GetErrorCode())
717  {
718  fwLog(fwlog::kError) << "CmsShowMain::setupSocket, can't create socket on port "<< iSocket << "." << std::endl;
719  exit(0);
720  }
721  m_monitor->Add(server);
722 }
723 
724 void
726 {
727  m_monitor->Connect("Ready(TSocket*)","CmsShowMain",this,"notified(TSocket*)");
728 
729 }
730 
731 void
732 CmsShowMain::notified(TSocket* iSocket)
733 {
734  TServerSocket* server = dynamic_cast<TServerSocket*> (iSocket);
735  if (server)
736  {
737  TSocket* connection = server->Accept();
738  if (connection)
739  {
740  m_monitor->Add(connection);
741  std::stringstream s;
742  s << "received connection from "<<iSocket->GetInetAddress().GetHostName();
743  guiManager()->updateStatus(s.str().c_str());
744  }
745  }
746  else
747  {
748  char buffer[4096];
749  memset(buffer,0,sizeof(buffer));
750  if (iSocket->RecvRaw(buffer, sizeof(buffer)) <= 0)
751  {
752  m_monitor->Remove(iSocket);
753  //std::stringstream s;
754  //s << "closing connection to "<<iSocket->GetInetAddress().GetHostName();
755  //m_guiManager->updateStatus(s.str().c_str());
756  delete iSocket;
757  return;
758  }
759  std::string fileName(buffer);
760  std::string::size_type lastNonSpace = fileName.find_last_not_of(" \n\t");
761  if (lastNonSpace != std::string::npos)
762  {
763  fileName.erase(lastNonSpace+1);
764  }
765 
766  std::stringstream s;
767  s <<"New file notified '"<<fileName<<"'";
768  guiManager()->updateStatus(s.str().c_str());
769 
770  bool appended = m_navigator->appendFile(fileName, true, m_live);
771 
772  if (appended)
773  {
774  if (m_live && isPlaying() && forward())
775  m_navigator->activateNewFileOnNextEvent();
776  else if (!isPlaying())
777  checkPosition();
778 
779  // bootstrap case: --port and no input file
781  {
782  m_loadedAnyInputFile = true;
783  m_navigator->firstEvent();
784  if (!isPlaying())
785  draw();
786  }
787 
788  std::stringstream sr;
789  sr <<"New file registered '"<<fileName<<"'";
790  guiManager()->updateStatus(sr.str().c_str());
791  }
792  else
793  {
794  std::stringstream sr;
795  sr <<"New file NOT registered '"<<fileName<<"'";
796  guiManager()->updateStatus(sr.str().c_str());
797  }
798  }
799 }
800 
801 void
803 {
804  if (m_live) {
805  Int_t keycode = gVirtualX->KeysymToKeycode((int)kKey_Space);
806  Window_t id = FWGUIManager::getGUIManager()->getMainFrame()->GetId();
807  gVirtualX->GrabKey(id, keycode, 0, isPlaying());
808  }
809 }
810 
811 void
813 {
815  if (m_live)
816  m_navigator->resetNewFileOnNextEvent();
819  checkPosition();
820 }
821 
822 void
824 {
826  if (m_navigator->filesNeedUpdate() == false)
827  {
828  guiManager()->setFilterButtonText(m_navigator->filterStatusMessage());
829  checkPosition();
830  }
831 }
832 
833 void
835 {
836  if (m_navigator->getFilterState() == CmsShowNavigator::kWithdrawn )
838  else
839  m_navigator->toggleFilterEnable();
840 }
841 
842 void
844 {
845  // called only if filter has changed
846  guiManager()->updateStatus("Filtering events");
847 }
848 
849 void
851 {
852  // called only filter is changed
853  guiManager()->clearStatus();
854  if (doDraw) draw();
855  checkPosition();
856  guiManager()->setFilterButtonText(m_navigator->filterStatusMessage());
857 }
858 
859 //______________________________________________________________________________
860 
861 void
863 {
864  m_live = true;
865  m_liveTimer.reset(new SignalTimer());
866  m_liveTimer->timeout_.connect(boost::bind(&CmsShowMain::checkLiveMode,this));
867 
868  Window_t rootw, childw;
869  Int_t root_x, root_y, win_x, win_y;
870  UInt_t mask;
871  gVirtualX->QueryPointer(gClient->GetDefaultRoot()->GetId(),
872  rootw, childw,
873  root_x, root_y,
874  win_x, win_y,
875  mask);
876 
877 
878  m_liveTimer->SetTime(m_liveTimeout);
879  m_liveTimer->Reset();
880  m_liveTimer->TurnOn();
881 }
882 
883 void
885 {
886  m_liveTimer->TurnOff();
887 
888 #if defined(R__LINUX)
889  TGX11 *x11 = dynamic_cast<TGX11*>(gVirtualX);
890  if (x11) {
891  XAnyEvent *ev = (XAnyEvent*) x11->GetNativeEvent();
892  // printf("serial %d \n",(int)ev->serial );
893 
894  if ( !isPlaying() && m_lastXEventSerial == ev->serial )
896  m_lastXEventSerial = ev->serial;
897  }
898 #endif
899  m_liveTimer->SetTime((Long_t)(m_liveTimeout));
900  m_liveTimer->Reset();
901  m_liveTimer->TurnOn();
902 }
DieTimer(CmsShowMain *app)
Definition: CmsShowMain.cc:427
void fileChangedSlot(const TFile *file)
Definition: CmsShowMain.cc:484
static const char *const kPlayCommandOpt
Definition: CmsShowMain.cc:85
static const char *const kNoVersionCheck
Definition: CmsShowMain.cc:111
void navigatorChangedFilterState(int)
Definition: CmsShowMain.cc:823
type
Definition: HCALResponse.h:21
void openData()
Definition: CmsShowMain.cc:505
const fwlite::Event * getCurrentEvent() const
Definition: CmsShowMain.cc:476
CmsShowMain * fApp
Definition: CmsShowMain.cc:425
static const char *const kGeomFileCommandOpt
Definition: CmsShowMain.cc:79
void showEventFilterGUI(const TGWindow *p)
FWSelectionManager * selectionManager()
sigc::signal< void > filterButtonClicked_
Definition: FWGUIManager.h:206
static const char *const kChainCommandOpt
Definition: CmsShowMain.cc:101
static const char *const kAutoSaveAllViews
Definition: CmsShowMain.cc:105
bool m_loadedAnyInputFile
Definition: CmsShowMain.h:120
void resetInitialization()
Definition: CmsShowMain.cc:501
virtual void checkPosition()
Definition: CmsShowMain.cc:631
virtual void eventChangedImp()
Definition: CmsShowMain.cc:494
const double w
Definition: UKUtility.cc:23
FWGUIManager * guiManager()
static const char *const kZeroWinOffsets
Definition: CmsShowMain.cc:110
void appendData()
Definition: CmsShowMain.cc:529
void preFiltering()
Definition: CmsShowMain.cc:843
void setupSocket(unsigned int)
Definition: CmsShowMain.cc:712
void setFilterButtonIcon(int)
static const char *const kSyncAllViews
Definition: CmsShowMain.cc:108
void checkLiveMode()
Definition: CmsShowMain.cc:884
static const char *const kFieldCommandOpt
Definition: CmsShowMain.cc:103
void setAutoSaveAllViewsHeight(int x)
void enable()
Definition: CSGAction.cc:284
FWEventItemsManager * eiManager()
virtual void checkKeyBindingsOnPLayEventsStateChanged()
Definition: CmsShowMain.cc:802
sigc::signal< void > activated
Definition: CSGAction.h:88
static const char *const kLogLevelOpt
Definition: CmsShowMain.cc:89
static const char *const kSimGeomFileOpt
Definition: CmsShowMain.cc:80
std::auto_ptr< FWLiteJobMetadataManager > m_metadataManager
Definition: CmsShowMain.h:116
static const char *const kNoConfigFileOpt
Definition: CmsShowMain.cc:82
bool ev
const char * configFilename() const
const std::string sOpenData
Definition: ActionsList.cc:12
void setup(FWNavigatorBase *navigator, fireworks::Context *context, FWJobMetadataManager *metadataManager)
void updateStatus(const char *status)
void setContext(fireworks::Context *)
virtual ~CmsShowMain()
Definition: CmsShowMain.cc:416
int ii
Definition: cuy.py:588
uint16_t size_type
static const char *const kConfigFileCommandOpt
Definition: CmsShowMain.cc:77
void setupDataHandling()
Definition: CmsShowMain.cc:652
void enableActions(bool enable=true)
virtual void autoLoadNewEvent()
Definition: CmsShowMain.cc:584
static const char * fmt
Definition: Version.cc:9
std::auto_ptr< SignalTimer > m_liveTimer
Definition: CmsShowMain.h:127
static const char *const kExpertCommandOpt
Definition: CmsShowMain.cc:97
static const char *const kAdvancedRenderOpt
Definition: CmsShowMain.cc:92
CmsShowMain(int argc, char *argv[])
Definition: CmsShowMain.cc:117
static const char *const kGeomFileOpt
Definition: CmsShowMain.cc:78
std::auto_ptr< fireworks::Context > m_context
Definition: CmsShowMain.h:117
LogLevel
Definition: fwLog.h:35
void setupAutoLoad(float x)
static const char *const kPortCommandOpt
Definition: CmsShowMain.cc:98
void setGeometryFilename(const std::string &filename)
static const char *const kPlayOpt
Definition: CmsShowMain.cc:84
virtual void stopPlaying()
void filterButtonClicked()
Definition: CmsShowMain.cc:834
void resetWMOffsets()
const std::string sAppendData
Definition: ActionsList.cc:13
bool loop() const
virtual Bool_t Notify() override
Definition: CmsShowMain.cc:432
CmsShowTaskExecutor * startupTasks()
virtual Bool_t isEnabled() const
Definition: CSGAction.cc:308
std::auto_ptr< TMonitor > m_monitor
Definition: CmsShowMain.h:133
UInt_t m_lastXEventSerial
Definition: CmsShowMain.h:129
sigc::signal< void, const TGWindow * > showEventFilterGUI_
Definition: FWGUIManager.h:207
static const char *const kEveOpt
Definition: CmsShowMain.cc:90
virtual void quit()
Definition: CmsShowMain.cc:441
virtual void eventChangedImp()
static void enable()
enable automatic library loading
static const char *const kConfigFileOpt
Definition: CmsShowMain.cc:76
static const char *const kFreePaletteCommandOpt
Definition: CmsShowMain.cc:104
static const char *const kLoopOpt
Definition: CmsShowMain.cc:86
static const char *const kEveCommandOpt
Definition: CmsShowMain.cc:91
double f[11][100]
static const char *const kSoftCommandOpt
Definition: CmsShowMain.cc:96
static const char *const kLogLevelCommandOpt
Definition: CmsShowMain.cc:88
CmsShowMainFrame * getMainFrame() const
Definition: FWGUIManager.h:200
void disablePrevious()
static const char *const kNoConfigFileCommandOpt
Definition: CmsShowMain.cc:83
static const char *const kEnableFPE
Definition: CmsShowMain.cc:109
std::vector< std::string > m_inputFiles
Definition: CmsShowMain.h:119
void setLiveMode()
Definition: CmsShowMain.cc:862
void setSimGeometryFilename(const std::string &filename)
void clearStatus()
void postFiltering(bool)
Definition: CmsShowMain.cc:850
CSGAction * getAction(const std::string name)
static const char *const kLiveCommandOpt
Definition: CmsShowMain.cc:102
void updateEventFilterEnable(bool)
static const char *const kHelpCommandOpt
Definition: CmsShowMain.cc:95
static FWGUIManager * getGUIManager()
static const char *const kInputFilesCommandOpt
Definition: CmsShowMain.cc:75
#define fwLog(_level_)
Definition: fwLog.h:50
static const char *const kInputFilesOpt
Definition: CmsShowMain.cc:74
static const char *const kPlainRootCommandOpt
Definition: CmsShowMain.cc:99
tuple argc
Definition: dir2webdir.py:38
const TFile * m_openFile
Definition: CmsShowMain.h:121
void setAutoSaveAllViewsFormat(const std::string &fmt)
std::auto_ptr< CmsShowNavigator > m_navigator
Definition: CmsShowMain.h:115
void setFilterButtonText(const char *txt)
std::auto_ptr< CmsShowSearchFiles > m_searchFiles
Definition: CmsShowMain.h:123
static const char *const kAutoSaveType
Definition: CmsShowMain.cc:106
static const char *const kRootInteractiveCommandOpt
Definition: CmsShowMain.cc:100
CSGContinuousAction * playEventsAction()
string fname
main script
bool m_noVersionCheck
Definition: CmsShowMain.h:131
static const char *const kAdvancedRenderCommandOpt
Definition: CmsShowMain.cc:93
void doExit()
Definition: CmsShowMain.cc:446
bool isPlaying() const
boost::function0< void > TaskFunctor
FWConfigurationManager * configurationManager()
void showEventFilterGUI()
void addTask(const TaskFunctor &iTask)
int m_liveTimeout
Definition: CmsShowMain.h:128
void evePreTerminate()
void setMaxNumberOfFilesToChain(unsigned int i)
tuple cout
Definition: gather_cfg.py:121
virtual void stopPlaying()
Definition: CmsShowMain.cc:812
void notified(TSocket *)
Definition: CmsShowMain.cc:732
tuple level
Definition: testEve_cfg.py:34
bool forward() const
volatile std::atomic< bool > shutdown_flag false
const std::string & geometryFilename(void)
static void EnableFreePalette()
void setPresentLogLevel(LogLevel)
Definition: fwLog.cc:55
static const char *const kSimGeomFileCommandOpt
Definition: CmsShowMain.cc:81
static void syncAllViews()
void connectSocket()
Definition: CmsShowMain.cc:725
void titleChanged(const char *title)
static const char *const kHelpOpt
Definition: CmsShowMain.cc:94
void disableNext()
static const char *const kLoopCommandOpt
Definition: CmsShowMain.cc:87
void openDataViaURL()
Definition: CmsShowMain.cc:554
static const char *const kAutoSaveHeight
Definition: CmsShowMain.cc:107
void reachedEnd()
void setConfigFilename(const std::string &f)
T get(const Candidate &c)
Definition: component.h:55
const std::string sSearchFiles
Definition: ActionsList.cc:14