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