CMS 3D CMS Logo

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