CMS 3D CMS Logo

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