CMS 3D CMS Logo

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