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 <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")(
202  kSizeTreeCacheOpt, po::value<int>(), "Set size of TTreeCache for data access in MB (default is 50)")(
203  kPrefetchTreeCacheOpt, "Enable prefetching");
204 
205  po::options_description rnrdesc("Appearance");
206  rnrdesc.add_options()(kFreePaletteCommandOpt, "Allow free color selection (requires special configuration!)")(
207  kZeroWinOffsets, "Disable auto-detection of window position offsets")(kAdvancedRenderCommandOpt,
208  "Enable line anti-aliasing");
209  po::positional_options_description p;
210  p.add(kInputFilesOpt, -1);
211 
212  po::options_description hiddendesc("hidden");
213  hiddendesc.add_options();
214 
215  po::options_description all("");
216  all.add(desc).add(rnrdesc).add(livedesc).add(debugdesc).add(tcachedesc);
217 
218  int newArgc = argc;
219  char** newArgv = argv;
220  po::variables_map vm;
221  try {
222  po::store(po::command_line_parser(newArgc, newArgv).options(all).positional(p).run(), vm);
223 
224  po::notify(vm);
225  } catch (const std::exception& e) {
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)
256  throw std::runtime_error("tree-cache-size should be non negative");
257  if (ds > 8192)
258  throw std::runtime_error("tree-cache-size should be smaller than 8 GB");
259  fwLog(fwlog::kInfo) << "Setting default TTreeCache size to " << ds << " MB." << std::endl;
260  FWTTreeCache::SetDefaultCacheSize(ds * 1024 * 1024);
261  }
262 
263  if (vm.count(kPlainRootCommandOpt)) {
264  fwLog(fwlog::kInfo) << "Plain ROOT prompt requested" << std::endl;
265  return;
266  }
267 
268  const char* cmspath = gSystem->Getenv("CMSSW_BASE");
269  if (nullptr == cmspath) {
270  throw std::runtime_error("CMSSW_BASE environment variable not set");
271  }
272 
273  // input file
274  if (vm.count(kInputFilesOpt)) {
275  m_inputFiles = vm[kInputFilesOpt].as<std::vector<std::string> >();
276  }
277 
278  if (m_inputFiles.empty())
279  fwLog(fwlog::kInfo) << "No data file given." << std::endl;
280  else if (m_inputFiles.size() == 1)
281  fwLog(fwlog::kInfo) << "Input " << m_inputFiles.front() << std::endl;
282  else
283  fwLog(fwlog::kInfo) << m_inputFiles.size() << " input files; first: " << m_inputFiles.front()
284  << ", last: " << m_inputFiles.back() << std::endl;
285 
286  // configuration file
287  if (vm.count(kConfigFileOpt)) {
288  setConfigFilename(vm[kConfigFileOpt].as<std::string>());
289  if (access(configFilename(), R_OK) == -1) {
290  fwLog(fwlog::kError) << "Specified configuration file does not exist. Quitting.\n";
291  exit(1);
292  }
293 
294  fwLog(fwlog::kInfo) << "Config " << configFilename() << std::endl;
295  } else {
296  if (vm.count(kNoConfigFileOpt)) {
297  fwLog(fwlog::kInfo) << "No configuration is loaded.\n";
299  }
300  }
301 
302  // geometry
303  if (vm.count(kGeomFileOpt)) {
304  m_globalTagCheck = false;
305  setGeometryFilename(vm[kGeomFileOpt].as<std::string>());
306  fwLog(fwlog::kInfo) << "Geometry file " << geometryFilename() << "\n";
307  }
308 
309  if (vm.count(kSimGeomFileOpt)) {
310  if (vm.count(kTGeoNameOpt))
311  setSimGeometryFilename(vm[kSimGeomFileOpt].as<std::string>(), vm[kTGeoNameOpt].as<std::string>());
312  else
313  setSimGeometryFilename(vm[kSimGeomFileOpt].as<std::string>(), "cmsGeo;1");
314  } else {
315  setSimGeometryFilename("cmsSimGeom-14.root", "cmsGeo;1");
316  }
317 
318  // Free-palette palette
319  if (vm.count(kFreePaletteCommandOpt)) {
321  fwLog(fwlog::kInfo) << "Palette restriction removed on user request!\n";
322  }
323  bool eveMode = vm.count(kEveOpt);
324 
325  //Delay creating guiManager and enabling autoloading until here so that if we have a 'help' request we don't
326  // open any graphics or build dictionaries
328 
329  TEveManager::Create(kFALSE, eveMode ? "FIV" : "FI");
330 
331  if (vm.count(kExpertCommandOpt)) {
332  m_context->setHidePFBuilders(false);
333  } else {
334  m_context->setHidePFBuilders(true);
335  }
336 
337  if (vm.count(kExpertCommandOpt)) {
338  m_context->setHidePFBuilders(false);
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)) {
347  fwLog(fwlog::kInfo) << "Window offsets reset on user request!\n";
348  }
349 
350  if (vm.count(kAdvancedRenderOpt)) {
351  TEveLine::SetDefaultSmooth(kTRUE);
352  }
353 
354  //figure out where to find macros
355  //tell ROOT where to find our macros
357  // first check if port is not occupied
358  if (vm.count(kPortCommandOpt)) {
359  f = std::bind(&CmsShowMain::setupSocket, this, vm[kPortCommandOpt].as<unsigned int>());
360  startupTasks()->addTask(f);
361  }
362  if (!geometryFilename().empty()) {
363  f = std::bind(&CmsShowMainBase::loadGeometry, this);
364  startupTasks()->addTask(f);
365  }
366  f = std::bind(&CmsShowMainBase::setupViewManagers, this);
367  startupTasks()->addTask(f);
368 
369  if (vm.count(kLiveCommandOpt)) {
370  f = std::bind(&CmsShowMain::setLiveMode, this);
371  startupTasks()->addTask(f);
372  }
373 
374  if (vm.count(kFieldCommandOpt)) {
375  m_context->getField()->setSource(FWMagField::kUser);
376  m_context->getField()->setUserField(vm[kFieldCommandOpt].as<double>());
377  }
378 
379  f = std::bind(&CmsShowMain::setupDataHandling, this);
380  startupTasks()->addTask(f);
381 
382  if (vm.count(kLoopOpt))
383  setPlayLoop();
384 
385  if (eveMode) {
386  f = std::bind(&CmsShowMainBase::setupDebugSupport, this);
387  startupTasks()->addTask(f);
388  }
389  if (vm.count(kChainCommandOpt)) {
390  f = std::bind(
392  startupTasks()->addTask(f);
393  }
394  if (vm.count(kPlayOpt)) {
395  f = std::bind(&CmsShowMainBase::setupAutoLoad, this, vm[kPlayOpt].as<float>());
396  startupTasks()->addTask(f);
397  }
398 
399  if (vm.count(kAutoSaveAllViews)) {
400  std::string type = "png";
401  if (vm.count(kAutoSaveType)) {
402  type = vm[kAutoSaveType].as<std::string>();
403  if (type != "png" && type != "jpg") {
404  fwLog(fwlog::kError) << "Specified auto-save type not supported. Quitting.\n";
405  exit(1);
406  }
407  }
408  std::string fmt = vm[kAutoSaveAllViews].as<std::string>();
409  fmt += "%u_%u_%llu_%s.";
410  fmt += type;
412  }
413  if (vm.count(kAutoSaveHeight)) {
415  }
416  if (vm.count(kSyncAllViews)) {
418  }
419  if (vm.count(kNoVersionCheck)) {
420  m_noVersionCheck = true;
421  }
422  if (vm.count(kEnableFPE)) {
423  gSystem->SetFPEMask();
424  }
425 
426  if (vm.count(kPortCommandOpt)) {
427  f = std::bind(&CmsShowMain::connectSocket, this);
428  startupTasks()->addTask(f);
429  }
430 
432 }
433 
434 //
435 // Destruction
436 //
437 
439  //avoids a seg fault from eve which happens if eve is terminated after the GUI is gone
441 }
442 
443 class DieTimer : public TTimer {
444 protected:
446 
447 public:
448  DieTimer(CmsShowMain* app) : TTimer(), fApp(app) { Start(0, kTRUE); }
449 
450  Bool_t Notify() override {
451  TurnOff();
452  fApp->doExit();
453  delete this;
454  return kFALSE;
455  }
456 };
457 
458 void CmsShowMain::quit() { new DieTimer(this); }
459 
461  // pre terminate eve
462  m_context->deleteEveElements();
464 
465  // sleep at least 150 ms
466  // windows in ROOT GUI are destroyed in 150 ms timeout after
467  gSystem->Sleep(151);
468  gSystem->ProcessEvents();
469  gSystem->ExitLoop();
470 }
471 
472 //
473 // assignment operators
474 //
475 // const CmsShowMain& CmsShowMain::operator=(const CmsShowMain& rhs)
476 // {
477 // //An exception safe implementation is
478 // CmsShowMain temp(rhs);
479 // swap(rhs);
480 //
481 // return *this;
482 // }
483 
484 //
485 // member functions
486 //
487 
489  if (m_navigator.get())
490  return static_cast<const fwlite::Event*>(m_navigator->getCurrentEvent());
491  return nullptr;
492 }
493 
494 void CmsShowMain::fileChangedSlot(const TFile* file) {
495  m_openFile = file;
496  if (file)
497  guiManager()->titleChanged(m_navigator->frameTitle());
498 
499  if (context()->getField()->getSource() == FWMagField::kNone) {
501  }
502  if (geometryFilename().empty()) {
503  std::string gt = m_navigator->getCurrentGlobalTag();
505  }
507 }
508 
511  guiManager()->titleChanged(m_navigator->frameTitle());
513 }
514 
516  //printf("Need to reset\n");
517 }
518 
520  const char* kRootType[] = {"ROOT files", "*.root", nullptr, nullptr};
521  TGFileInfo fi;
522  fi.fFileTypes = kRootType;
523  /* this is how things used to be done:
524  fi.fIniDir = ".";
525  this is bad because the destructor calls delete[] on fIniDir.
526  */
527  fi.fIniDir = new char[128];
528  strncpy(fi.fIniDir, ".", 127);
529  guiManager()->updateStatus("waiting for data file ...");
530  new TGFileDialog(gClient->GetDefaultRoot(), guiManager()->getMainFrame(), kFDOpen, &fi);
531  guiManager()->updateStatus("loading file ...");
532  if (fi.fFilename) {
533  m_navigator->openFile(fi.fFilename);
534 
536  m_navigator->firstEvent();
537  checkPosition();
538  draw();
539  }
540  guiManager()->clearStatus();
541 }
542 
544  const char* kRootType[] = {"ROOT files", "*.root", nullptr, nullptr};
545  TGFileInfo fi;
546  fi.fFileTypes = kRootType;
547  /* this is how things used to be done:
548  fi.fIniDir = ".";
549  this is bad because the destructor calls delete[] on fIniDir.
550  */
551  fi.fIniDir = new char[128];
552  strncpy(fi.fIniDir, ".", 127);
553  guiManager()->updateStatus("waiting for data file ...");
554  new TGFileDialog(gClient->GetDefaultRoot(), guiManager()->getMainFrame(), kFDOpen, &fi);
555  guiManager()->updateStatus("loading file ...");
556  if (fi.fFilename) {
557  m_navigator->appendFile(fi.fFilename, false, false);
559  checkPosition();
560  draw();
561  guiManager()->titleChanged(m_navigator->frameTitle());
562  }
563  guiManager()->clearStatus();
564 }
565 
567  if (m_searchFiles.get() == nullptr) {
568  m_searchFiles =
569  std::make_unique<CmsShowSearchFiles>("", "Open Remote Data Files", guiManager()->getMainFrame(), 500, 400);
570  m_searchFiles->CenterOnParent(kTRUE, TGTransientFrame::kBottomRight);
571  }
572  std::string chosenFile = m_searchFiles->chooseFileFromURL();
573  if (!chosenFile.empty()) {
574  guiManager()->updateStatus("loading file ...");
575  if (m_navigator->openFile(chosenFile)) {
577  m_navigator->firstEvent();
578  checkPosition();
579  draw();
580  guiManager()->clearStatus();
581  } else {
582  guiManager()->updateStatus("failed to load data file");
583  }
584  }
585 }
586 
587 //
588 // const member functions
589 //
590 
591 //_______________________________________________________________________________
594 
595  // case when start with no input file
596  if (!m_loadedAnyInputFile) {
597  if (m_monitor.get())
599  return;
600  }
601 
602  bool reachedEnd = (forward() && m_navigator->isLastEvent()) || (!forward() && m_navigator->isFirstEvent());
603 
604  if (loop() && reachedEnd) {
605  forward() ? m_navigator->firstEvent() : m_navigator->lastEvent();
606  draw();
607  } else if (!reachedEnd) {
608  forward() ? m_navigator->nextEvent() : m_navigator->previousEvent();
609  draw();
610  }
611 
612  // stop loop in case no loop or monitor mode
613  if (reachedEnd && (loop() || m_monitor.get()) == kFALSE) {
614  if (forward() && m_navigator->isLastEvent()) {
616  checkPosition();
617  }
618 
619  if ((!forward()) && m_navigator->isFirstEvent()) {
621  checkPosition();
622  }
623  } else
625 }
626 
627 //______________________________________________________________________________
628 
630  if ((m_monitor.get() || loop()) && isPlaying())
631  return;
632 
634 
635  if (m_navigator->isFirstEvent())
637 
638  if (m_navigator->isLastEvent()) {
639  guiManager()->disableNext();
640  // force enable play events action in --port mode
641  if (m_monitor.get() && !guiManager()->playEventsAction()->isEnabled())
643  }
644 }
645 
646 //==============================================================================
648  guiManager()->updateStatus("Setting up data handling...");
649 
650  // navigator filtering ->
651  m_navigator->fileChanged_.connect(std::bind(&CmsShowMain::fileChangedSlot, this, std::placeholders::_1));
652  m_navigator->editFiltersExternally_.connect(
653  std::bind(&FWGUIManager::updateEventFilterEnable, guiManager(), std::placeholders::_1));
654  m_navigator->filterStateChanged_.connect(
655  std::bind(&CmsShowMain::navigatorChangedFilterState, this, std::placeholders::_1));
656  m_navigator->postFiltering_.connect(std::bind(&CmsShowMain::postFiltering, this, std::placeholders::_1));
657 
658  // navigator fitlering <-
659  guiManager()->showEventFilterGUI_.connect(
660  std::bind(&CmsShowNavigator::showEventFilterGUI, m_navigator.get(), std::placeholders::_1));
662 
663  // Data handling. File related and therefore not in the base class.
664  if (guiManager()->getAction(cmsshow::sOpenData) != nullptr)
665  guiManager()->getAction(cmsshow::sOpenData)->activated.connect(sigc::mem_fun(*this, &CmsShowMain::openData));
666  if (guiManager()->getAction(cmsshow::sAppendData) != nullptr)
667  guiManager()->getAction(cmsshow::sAppendData)->activated.connect(sigc::mem_fun(*this, &CmsShowMain::appendData));
668  if (guiManager()->getAction(cmsshow::sSearchFiles) != nullptr)
669  guiManager()
671  ->activated.connect(sigc::mem_fun(*this, &CmsShowMain::openDataViaURL));
672 
673  setupActions();
674  // init data from CmsShowNavigator configuration, can do this with signals since there were not connected yet
675  guiManager()->setFilterButtonIcon(m_navigator->getFilterState());
676 
677  for (unsigned int ii = 0; ii < m_inputFiles.size(); ++ii) {
678  const std::string& fname = m_inputFiles[ii];
679  if (fname.empty())
680  continue;
681  guiManager()->updateStatus("loading data file ...");
682  if (!m_navigator->appendFile(fname, false, false)) {
683  guiManager()->updateStatus("failed to load data file");
684  } else {
685  m_loadedAnyInputFile = true;
686  }
687  }
688 
689  if (m_loadedAnyInputFile) {
690  m_navigator->firstEvent();
691  checkPosition();
692  if (configurationManager()->getIgnore())
693  guiManager()->initEmpty();
694  else
696  } else {
697  if (configFilename()[0] == '\0') {
698  guiManager()->initEmpty();
699  } else {
701  }
702 
703  bool geoBrowser = (configFilename()[0] != '\0') && (eiManager()->begin() == eiManager()->end());
704 
705  if (m_monitor.get() == nullptr && (configurationManager()->getIgnore() == false) && (!geoBrowser)) {
706  if (m_inputFiles.empty())
707  openDataViaURL();
708  else
709  openData();
710  }
711  }
712 }
713 
715  if (m_loadedAnyInputFile == false) {
716  m_loadedAnyInputFile = true;
717  if ((configFilename()[0] == '\0') && (configurationManager()->getIgnore() == false))
719  }
720 }
721 
722 void CmsShowMain::setupSocket(unsigned int iSocket) {
723  m_monitor = std::make_unique<TMonitor>();
724  TServerSocket* server = new TServerSocket(iSocket, kTRUE);
725  if (server->GetErrorCode()) {
726  fwLog(fwlog::kError) << "CmsShowMain::setupSocket, can't create socket on port " << iSocket << "." << std::endl;
727  exit(0);
728  }
729  m_monitor->Add(server);
730 }
731 
732 void CmsShowMain::connectSocket() { m_monitor->Connect("Ready(TSocket*)", "CmsShowMain", this, "notified(TSocket*)"); }
733 
734 void CmsShowMain::notified(TSocket* iSocket) {
735  TServerSocket* server = dynamic_cast<TServerSocket*>(iSocket);
736  if (server) {
737  TSocket* connection = server->Accept();
738  if (connection) {
739  m_monitor->Add(connection);
740  std::stringstream s;
741  s << "received connection from " << iSocket->GetInetAddress().GetHostName();
742  guiManager()->updateStatus(s.str().c_str());
743  }
744  } else {
745  char buffer[4096];
746  memset(buffer, 0, sizeof(buffer));
747  if (iSocket->RecvRaw(buffer, sizeof(buffer)) <= 0) {
748  m_monitor->Remove(iSocket);
749  //std::stringstream s;
750  //s << "closing connection to "<<iSocket->GetInetAddress().GetHostName();
751  //m_guiManager->updateStatus(s.str().c_str());
752  delete iSocket;
753  return;
754  }
756  std::string::size_type lastNonSpace = fileName.find_last_not_of(" \n\t");
757  if (lastNonSpace != std::string::npos) {
758  fileName.erase(lastNonSpace + 1);
759  }
760 
761  std::stringstream s;
762  s << "New file notified '" << fileName << "'";
763  guiManager()->updateStatus(s.str().c_str());
764 
765  bool appended = m_navigator->appendFile(fileName, true, m_live);
766 
767  if (appended) {
768  if (m_live && isPlaying() && forward())
769  m_navigator->activateNewFileOnNextEvent();
770  else if (!isPlaying())
771  checkPosition();
772 
773  // bootstrap case: --port and no input file
774  if (!m_loadedAnyInputFile) {
775  m_loadedAnyInputFile = true;
776  m_navigator->firstEvent();
777  if (!isPlaying())
778  draw();
779  }
780 
781  std::stringstream sr;
782  sr << "New file registered '" << fileName << "'";
783  guiManager()->updateStatus(sr.str().c_str());
784  } else {
785  std::stringstream sr;
786  sr << "New file NOT registered '" << fileName << "'";
787  guiManager()->updateStatus(sr.str().c_str());
788  }
789  }
790 }
791 
793  if (m_live) {
794  Int_t keycode = gVirtualX->KeysymToKeycode((int)kKey_Space);
795  Window_t id = FWGUIManager::getGUIManager()->getMainFrame()->GetId();
796  gVirtualX->GrabKey(id, keycode, 0, isPlaying());
797  }
798 }
799 
802  if (m_live)
803  m_navigator->resetNewFileOnNextEvent();
806  checkPosition();
807 }
808 
811  if (m_navigator->filesNeedUpdate() == false) {
812  guiManager()->setFilterButtonText(m_navigator->filterStatusMessage());
813  checkPosition();
814  }
815 }
816 
818  if (m_navigator->getFilterState() == CmsShowNavigator::kWithdrawn)
820  else
821  m_navigator->toggleFilterEnable();
822 }
823 
825  // called only if filter has changed
826  guiManager()->updateStatus("Filtering events");
827 }
828 
829 void CmsShowMain::postFiltering(bool doDraw) {
830  // called only filter is changed
831  guiManager()->clearStatus();
832  if (doDraw)
833  draw();
834  checkPosition();
835  guiManager()->setFilterButtonText(m_navigator->filterStatusMessage());
836 }
837 
838 //______________________________________________________________________________
839 
841  m_live = true;
842  m_liveTimer = std::make_unique<SignalTimer>();
843  m_liveTimer->timeout_.connect(std::bind(&CmsShowMain::checkLiveMode, this));
844 
845  Window_t rootw, childw;
846  Int_t root_x, root_y, win_x, win_y;
847  UInt_t mask;
848  gVirtualX->QueryPointer(gClient->GetDefaultRoot()->GetId(), rootw, childw, root_x, root_y, win_x, win_y, mask);
849 
850  m_liveTimer->SetTime(m_liveTimeout);
851  m_liveTimer->Reset();
852  m_liveTimer->TurnOn();
853 }
854 
856  m_liveTimer->TurnOff();
857 
858 #if defined(R__LINUX)
859  TGX11* x11 = dynamic_cast<TGX11*>(gVirtualX);
860  if (x11) {
861  XAnyEvent* ev = (XAnyEvent*)x11->GetNativeEvent();
862  // printf("serial %d \n",(int)ev->serial );
863 
864  if (!isPlaying() && m_lastXEventSerial == ev->serial)
866  m_lastXEventSerial = ev->serial;
867  }
868 #endif
869  m_liveTimer->SetTime((Long_t)(m_liveTimeout));
870  m_liveTimer->Reset();
871  m_liveTimer->TurnOn();
872 }
DieTimer(CmsShowMain *app)
Definition: CmsShowMain.cc:448
void fileChangedSlot(const TFile *file)
Definition: CmsShowMain.cc:494
static const char *const kPlayCommandOpt
Definition: CmsShowMain.cc:94
static const char *const kNoVersionCheck
Definition: CmsShowMain.cc:122
void navigatorChangedFilterState(int)
Definition: CmsShowMain.cc:809
static void PrefetchingOn()
Definition: FWTTreeCache.cc:25
void openData()
Definition: CmsShowMain.cc:519
CmsShowMain * fApp
Definition: CmsShowMain.cc:445
static const char *const kGeomFileCommandOpt
Definition: CmsShowMain.cc:86
void setLoadedAnyInputFileAfterStartup()
Definition: CmsShowMain.cc:714
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:629
bool m_loadedAnyInputFile
Definition: CmsShowMain.h:119
void resetFieldEstimate() const
Definition: FWMagField.cc:135
void eventChangedImp() override
Definition: CmsShowMain.cc:509
void resetInitialization()
Definition: CmsShowMain.cc:515
FWGUIManager * guiManager()
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
static const char *const kZeroWinOffsets
Definition: CmsShowMain.cc:121
void appendData()
Definition: CmsShowMain.cc:543
void preFiltering()
Definition: CmsShowMain.cc:824
void setupSocket(unsigned int)
Definition: CmsShowMain.cc:722
void setFilterButtonIcon(int)
T w() const
static const char *const kSyncAllViews
Definition: CmsShowMain.cc:119
void checkLiveMode()
Definition: CmsShowMain.cc:855
static const char *const kFieldCommandOpt
Definition: CmsShowMain.cc:114
void setAutoSaveAllViewsHeight(int x)
Bool_t Notify() override
Definition: CmsShowMain.cc:450
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:792
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 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 *)
static const char *const kTGeoNameOpt
Definition: CmsShowMain.cc:89
uint16_t size_type
static const char *const kConfigFileCommandOpt
Definition: CmsShowMain.cc:84
constexpr uint32_t mask
Definition: gpuClustering.h:26
void stopPlaying() override
Definition: CmsShowMain.cc:800
void setupDataHandling()
Definition: CmsShowMain.cc:647
void enableActions(bool enable=true)
static const char *const kExpertCommandOpt
Definition: CmsShowMain.cc:108
CmsShowMainFrame * getMainFrame() const
Definition: FWGUIManager.h:197
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
const char * configFilename() const
LogLevel
Definition: fwLog.h:35
void setupAutoLoad(float x)
bool loop() const
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:817
void resetWMOffsets()
FWGeometry * getGeom() const
Definition: Context.h:72
const std::string sAppendData
Definition: ActionsList.cc:13
~CmsShowMain() override
Definition: CmsShowMain.cc:438
CmsShowTaskExecutor * startupTasks()
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
double f[11][100]
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
void disablePrevious()
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:209
ii
Definition: cuy.py:589
void setLiveMode()
Definition: CmsShowMain.cc:840
static const char *const kPrefetchTreeCacheOpt
Definition: CmsShowMain.cc:100
void autoLoadNewEvent() override
Definition: CmsShowMain.cc:592
void clearStatus()
void postFiltering(bool)
Definition: CmsShowMain.cc:829
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
virtual Bool_t isEnabled() const
Definition: CSGAction.cc:289
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
const fwlite::Event * getCurrentEvent() const
Definition: CmsShowMain.cc:488
void doExit()
Definition: CmsShowMain.cc:460
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
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
void applyGlobalTag(const std::string &gt)
Definition: FWGeometry.cc:59
void quit() override
Definition: CmsShowMain.cc:458
void notified(TSocket *)
Definition: CmsShowMain.cc:734
bool isPlaying() const
#define get
sigc::signal< void()> filterButtonClicked_
Definition: FWGUIManager.h:203
const_iterator end() const
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
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:732
ESource getSource() const
Definition: FWMagField.h:31
void titleChanged(const char *title)
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:566
static const char *const kAutoSaveHeight
Definition: CmsShowMain.cc:118
void reachedEnd()
bool forward() const
void setConfigFilename(const std::string &f)
FWMagField * getField() const
Definition: Context.h:66
const fireworks::Context * context() const
Definition: CmsShowMain.h:77
const std::string sSearchFiles
Definition: ActionsList.cc:14
def exit(msg="")