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