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