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