CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CmsShowMainBase.cc
Go to the documentation of this file.
1 #include <fstream>
2 #include <sys/types.h>
3 #include <sys/socket.h>
4 #include <netinet/in.h>
5 #include <arpa/inet.h>
6 #include <netdb.h>
7 
8 #include <functional>
9 #include <memory>
10 
11 #include "TGLWidget.h"
12 #include "TGMsgBox.h"
13 #include "TROOT.h"
14 #include "TSystem.h"
15 #include "TStopwatch.h"
16 #include "TTimer.h"
17 #include "TEveManager.h"
18 #include "TPRegexp.h"
19 
49 
51  : m_changeManager(new FWModelChangeManager),
52  m_colorManager(new FWColorManager(m_changeManager.get())),
53  m_configurationManager(new FWConfigurationManager),
54  m_eiManager(new FWEventItemsManager(m_changeManager.get())),
55  m_guiManager(nullptr),
56  m_selectionManager(new FWSelectionManager(m_changeManager.get())),
57  m_startupTasks(new CmsShowTaskExecutor),
58  m_viewManager(new FWViewManagerManager(m_changeManager.get(), m_colorManager.get())),
59  m_autoLoadTimer(new SignalTimer()),
60  m_navigatorPtr(nullptr),
61  m_metadataManagerPtr(nullptr),
62  m_contextPtr(nullptr),
63  m_autoSaveAllViewsHeight(-1),
64  m_autoLoadTimerRunning(kFALSE),
65  m_forward(true),
66  m_isPlaying(false),
67  m_loop(false),
68  m_playDelay(3.f) {
70 }
71 
73 
75  m_guiManager->writeToPresentConfigurationFile_.connect(
76  sigc::mem_fun(*this, &CmsShowMainBase::writeToCurrentConfigFile));
77 
78  // init TGSlider state before signals are connected
79  m_guiManager->setDelayBetweenEvents(m_playDelay);
80 
82  if (m_guiManager->getAction(cmsshow::sNextEvent) != nullptr)
83  m_guiManager->getAction(cmsshow::sNextEvent)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doNextEvent));
84  if (m_guiManager->getAction(cmsshow::sPreviousEvent) != nullptr)
86  ->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doPreviousEvent));
87  if (m_guiManager->getAction(cmsshow::sGotoFirstEvent) != nullptr)
89  ->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doFirstEvent));
90  if (m_guiManager->getAction(cmsshow::sGotoLastEvent) != nullptr)
92  ->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doLastEvent));
93  if (m_guiManager->getAction(cmsshow::sQuit) != nullptr)
94  m_guiManager->getAction(cmsshow::sQuit)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::quit));
95 
96  m_guiManager->changedEventId_.connect(std::bind(
97  &CmsShowMainBase::goToRunEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
98  m_guiManager->playEventsAction()->started_.connect(sigc::mem_fun(*this, &CmsShowMainBase::playForward));
99  m_guiManager->playEventsBackwardsAction()->started_.connect(sigc::mem_fun(*this, &CmsShowMainBase::playBackward));
100  m_guiManager->loopAction()->started_.connect(sigc::mem_fun(*this, &CmsShowMainBase::setPlayLoopImp));
101  m_guiManager->loopAction()->stopped_.connect(sigc::mem_fun(*this, &CmsShowMainBase::unsetPlayLoopImp));
102  m_guiManager->changedDelayBetweenEvents_.connect(
103  std::bind(&CmsShowMainBase::setPlayDelay, this, std::placeholders::_1));
104  m_guiManager->playEventsAction()->stopped_.connect(sigc::mem_fun(*this, &CmsShowMainBase::stopPlaying));
105  m_guiManager->playEventsBackwardsAction()->stopped_.connect(sigc::mem_fun(*this, &CmsShowMainBase::stopPlaying));
106 
107  m_autoLoadTimer->timeout_.connect(std::bind(&CmsShowMainBase::autoLoadNewEvent, this));
108 }
109 
111  guiManager()->updateStatus("Setting up view manager...");
112 
113  std::shared_ptr<FWViewManagerBase> eveViewManager = std::make_shared<FWEveViewManager>(guiManager());
114  eveViewManager->setContext(m_contextPtr);
115  viewManager()->add(eveViewManager);
116 
117  auto tableViewManager = std::make_shared<FWTableViewManager>(guiManager());
118  configurationManager()->add(std::string("Tables"), tableViewManager.get());
119  viewManager()->add(tableViewManager);
120  eiManager()->goingToClearItems_.connect(std::bind(&FWTableViewManager::removeAllItems, tableViewManager.get()));
121 
122  auto triggerTableViewManager = std::make_shared<FWTriggerTableViewManager>(guiManager());
123  configurationManager()->add(std::string("TriggerTables"), triggerTableViewManager.get());
124  configurationManager()->add(std::string("L1TriggerTables"),
125  triggerTableViewManager.get()); // AMT: added for backward compatibilty
126  triggerTableViewManager->setContext(m_contextPtr);
127  viewManager()->add(triggerTableViewManager);
128 
129  auto geoTableViewManager =
130  std::make_shared<FWGeometryTableViewManager>(guiManager(), m_simGeometryFilename, m_TGeoName);
131  geoTableViewManager->setContext(m_contextPtr);
132  viewManager()->add(geoTableViewManager);
133 
134  // Unfortunately, due to the plugin mechanism, we need to delay
135  // until here the creation of the FWJobMetadataManager, because
136  // otherwise the supportedTypesAndRepresentations map is empty.
137  // FIXME: should we have a signal for whenever the above mentioned map
138  // changes? Can that actually happer (maybe if we add support
139  // for loading plugins on the fly??).
140  m_metadataManagerPtr->initReps(viewManager()->supportedTypesAndRepresentations());
141 }
142 
144 
146 
149  checkPosition();
150  draw();
151 }
152 
155  checkPosition();
156  draw();
157 }
158 
161  checkPosition();
162  draw();
163 }
166  checkPosition();
167  draw();
168 }
169 
171  m_navigatorPtr->goToRunEvent(run, lumi, event);
172  checkPosition();
173  draw();
174 }
175 
177  m_guiManager->updateStatus("loading event ...");
178 
181  }
183 
184  TStopwatch sw;
185  m_viewManager->eventBegin();
187  m_viewManager->eventEnd();
188  sw.Stop();
189  fwLog(fwlog::kDebug) << "CmsShowMainBase::draw CpuTime " << sw.CpuTime() << " RealTime " << sw.RealTime()
190  << std::endl;
191 
192  if (!m_autoSaveAllViewsFormat.empty()) {
193  m_guiManager->updateStatus("auto saving images ...");
195  }
196  m_guiManager->clearStatus();
197 }
198 
201  FWJobMetadataManager *metadataManager) {
205  m_metadataManagerPtr = metadataManager;
206 
207  m_colorManager->initialize();
209  m_guiManager = std::make_unique<FWGUIManager>(m_contextPtr, m_viewManager.get(), m_navigatorPtr);
210 
211  m_eiManager->newItem_.connect(
212  std::bind(&FWModelChangeManager::newItemSlot, m_changeManager.get(), std::placeholders::_1));
213 
214  m_eiManager->newItem_.connect(
215  std::bind(&FWViewManagerManager::registerEventItem, m_viewManager.get(), std::placeholders::_1));
216  m_configurationManager->add("EventItems", m_eiManager.get());
217  m_configurationManager->add("GUI", m_guiManager.get());
218  m_configurationManager->add("EventNavigator", m_navigatorPtr);
219  m_configurationManager->add("CommonPreferences",
220  m_contextPtr->commonPrefs()); // must be after GUIManager in alphabetical order
221 
222  m_guiManager->writeToConfigurationFile_.connect(
223  std::bind(&CmsShowMainBase::writeToConfigFile, this, std::placeholders::_1));
224 
225  m_guiManager->loadFromConfigurationFile_.connect(
226  std::bind(&CmsShowMainBase::reloadConfiguration, this, std::placeholders::_1));
227  m_guiManager->loadPartialFromConfigurationFile_.connect(
228  std::bind(&CmsShowMainBase::partialLoadConfiguration, this, std::placeholders::_1));
229 
230  m_guiManager->writePartialToConfigurationFile_.connect(
231  std::bind(&CmsShowMainBase::partialWriteToConfigFile, this, std::placeholders::_1));
232 
233  std::string macPath(gSystem->Getenv("CMSSW_BASE"));
234  macPath += "/src/Fireworks/Core/macros";
235  const char *base = gSystem->Getenv("CMSSW_RELEASE_BASE");
236  if (nullptr != base) {
237  macPath += ":";
238  macPath += base;
239  macPath += "/src/Fireworks/Core/macros";
240  }
241  gROOT->SetMacroPath((std::string("./:") + macPath).c_str());
242 
243  m_startupTasks->tasksCompleted_.connect(std::bind(&FWGUIManager::clearStatus, m_guiManager.get()));
244 }
245 
249 }
250 
252 
254  std::string p = (name == "current") ? m_configFileName.c_str() : name.c_str();
255  new FWPartialConfigSaveGUI(p.c_str(), m_configFileName.c_str(), m_configurationManager.get());
256 }
257 
259  if (config.empty())
260  return;
261 
263 
264  std::string msg = "Reloading configuration " + config + "...";
265  fwLog(fwlog::kDebug) << msg << std::endl;
266  m_guiManager->updateStatus(msg.c_str());
267  m_guiManager->subviewDestroyAll();
268  m_eiManager->clearItems();
270  try {
271  gEve->DisableRedraw();
272  m_configurationManager->readFromFile(config);
273  gEve->EnableRedraw();
274  } catch (SimpleSAXParser::ParserError &e) {
275  Int_t chosen;
276  new TGMsgBox(gClient->GetDefaultRoot(),
277  gClient->GetDefaultRoot(),
278  "Bad configuration",
279  ("Configuration " + config + " cannot be parsed: " + e.error()).c_str(),
280  kMBIconExclamation,
281  kMBCancel,
282  &chosen);
283  } catch (...) {
284  Int_t chosen;
285  new TGMsgBox(gClient->GetDefaultRoot(),
286  gClient->GetDefaultRoot(),
287  "Bad configuration",
288  ("Configuration " + config + " cannot be parsed.").c_str(),
289  kMBIconExclamation,
290  kMBCancel,
291  &chosen);
292  }
293 
294  m_guiManager->updateStatus("");
295 }
296 
298  new FWPartialConfigLoadGUI(name.c_str(), m_configurationManager.get(), m_eiManager.get());
299 }
300 
302  m_playDelay = x;
303  m_guiManager->setDelayBetweenEvents(m_playDelay);
304  if (!m_guiManager->playEventsAction()->isEnabled())
305  m_guiManager->playEventsAction()->enable();
306 
307  m_guiManager->playEventsAction()->switchMode();
308 }
309 
311  m_autoLoadTimer->SetTime((Long_t)(m_playDelay * 1000));
312  m_autoLoadTimer->Reset();
313  m_autoLoadTimer->TurnOn();
314  m_autoLoadTimerRunning = kTRUE;
315 }
316 
318  m_autoLoadTimer->TurnOff();
319  m_autoLoadTimerRunning = kFALSE;
320 }
321 
323  m_guiManager->updateStatus("Setting up configuration...");
324 
325  try {
326  gEve->DisableRedraw();
327  if (m_configFileName.empty()) {
329  } else {
330  char *whereConfig = gSystem->Which(TROOT::GetMacroPath(), m_configFileName.c_str(), kReadPermission);
331  m_configFileName = whereConfig;
332  delete[] whereConfig;
334  }
335  gEve->EnableRedraw();
336  } catch (SimpleSAXParser::ParserError &e) {
337  fwLog(fwlog::kError) << "Unable to load configuration file '" << m_configFileName << "': " << e.error()
338  << std::endl;
339  exit(1);
340  } catch (std::runtime_error &e) {
341  fwLog(fwlog::kError) << "Unable to load configuration file '" << m_configFileName
342  << "' which was specified on command line. Quitting." << std::endl;
343  exit(1);
344  }
345 }
346 
348 
350  m_guiManager->updateStatus("Setting up Eve debug window...");
351  m_guiManager->openEveBrowserForDebugging();
352 }
353 
355  if (!m_loop) {
356  setPlayLoopImp();
357  m_guiManager->loopAction()->activated();
358  }
359 }
360 
362  if (m_loop) {
364  m_guiManager->loopAction()->stop();
365  }
366 }
367 
369 
371 
373 
375  m_isPlaying = false;
377 }
378 
380  m_forward = true;
381  m_isPlaying = true;
382  guiManager()->enableActions(kFALSE);
385 }
386 
388  m_forward = false;
389  m_isPlaying = true;
390  guiManager()->enableActions(kFALSE);
393 }
394 
395 void CmsShowMainBase::loadGeometry() { // prepare geometry service
396  // ATTN: this should be made configurable
397  try {
398  guiManager()->updateStatus("Loading geometry...");
400  } catch (const std::runtime_error &iException) {
401  fwLog(fwlog::kError) << "CmsShowMain::loadGeometry() caught exception: \n"
402  << m_geometryFilename << " " << iException.what() << std::endl;
403  exit(0);
404  }
405 }
406 
408  // Send version info to xrootd.t2.ucsd.edu receiver on port 9698.
409 
410  // receiver
411  struct hostent *h = gethostbyname("xrootd.t2.ucsd.edu");
412  if (!h)
413  return;
414 
415  struct sockaddr_in remoteServAddr;
416  remoteServAddr.sin_family = h->h_addrtype;
417  memcpy((char *)&remoteServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
418  remoteServAddr.sin_port = htons(9698);
419 
420  // socket creation
421  int sd = socket(AF_INET, SOCK_DGRAM, 0);
422  if (sd < 0) {
423  // std::cout << "can't create socket \n";
424  return;
425  }
426  // bind any port
427  // printf("bind port\n");
428  struct sockaddr_in cliAddr;
429  cliAddr.sin_family = AF_INET;
430  cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
431  cliAddr.sin_port = htons(0);
432 
433  int rc = bind(sd, (struct sockaddr *)&cliAddr, sizeof(cliAddr));
434  if (rc < 0) {
435  // std::cout << "can't bind port %d " << rc << std::endl;
436  return;
437  }
438 
439  // get OSX version
440  TString osx_version;
441  try {
442  std::ifstream infoFile("/System/Library/CoreServices/SystemVersion.plist");
443  osx_version.ReadFile(infoFile);
444  TPMERegexp re("ProductVersion\\</key\\>\\n\\t\\<string\\>(10.*)\\</string\\>");
445  re.Match(osx_version);
446  osx_version = re[1];
447  } catch (...) {
448  }
449 
450  // send data
451  SysInfo_t sInfo;
452  gSystem->GetSysInfo(&sInfo);
453  char msg[128];
454 
455  if (gSystem->Getenv("CMSSW_VERSION")) {
456  snprintf(msg, 64, "%s %s %s", gSystem->Getenv("CMSSW_VERSION"), sInfo.fOS.Data(), osx_version.Data());
457  } else {
458  TString versionFileName("data/version.txt");
459  fireworks::setPath(versionFileName);
460  std::ifstream fs(versionFileName);
461  TString infoText;
462  infoText.ReadLine(fs);
463  fs.close();
464  snprintf(msg, 64, "Standalone %s %s %s", infoText.Data(), sInfo.fOS.Data(), osx_version.Data());
465  }
466 
467  int flags = 0;
468  sendto(sd, msg, strlen(msg), flags, (struct sockaddr *)&remoteServAddr, sizeof(remoteServAddr));
469 }
tuple base
Main Program
Definition: newFWLiteAna.py:92
void partialWriteToConfigFile(const std::string &config)
void registerEventItem(const FWEventItem *iItem)
virtual void goToRunEvent(edm::RunNumber_t, edm::LuminosityBlockNumber_t, edm::EventNumber_t)=0
std::string m_geometryFilename
FWGUIManager * guiManager()
void writeToConfigFile(const std::string &config)
std::unique_ptr< FWModelChangeManager > m_changeManager
std::unique_ptr< FWGUIManager > m_guiManager
virtual void nextEvent()=0
FWEventItemsManager * eiManager()
unsigned long long EventNumber_t
std::unique_ptr< FWEventItemsManager > m_eiManager
void initReps(const FWTypeToRepresentations &iTypeAndReps)
void partialLoadConfiguration(const std::string &config)
void initEveElements()
Definition: Context.cc:86
std::unique_ptr< SignalTimer > m_autoLoadTimer
void setup(FWNavigatorBase *navigator, fireworks::Context *context, FWJobMetadataManager *metadataManager)
void updateStatus(const char *status)
unsigned int LuminosityBlockNumber_t
void enableActions(bool enable=true)
virtual void checkPosition()=0
void checkBeamSpot(const edm::EventBase *event)
Definition: FWBeamSpot.cc:6
const std::string sNextEvent
Definition: ActionsList.cc:5
virtual ~CmsShowMainBase() noexcept(false)
void setupAutoLoad(float x)
std::unique_ptr< FWColorManager > m_colorManager
FWNavigatorBase * m_navigatorPtr
void newItemSlot(FWEventItem *)
FWBeamSpot * getBeamSpot() const
Definition: Context.h:67
void reloadConfiguration(const std::string &config)
virtual void stopPlaying()
FWMagField * getField() const
Definition: Context.h:66
virtual void firstEvent()=0
void loadMap(const char *fileName)
Definition: FWGeometry.cc:103
void setPlayDelay(Float_t val)
virtual void eventChangedImp()
virtual void quit()=0
std::unique_ptr< CmsShowTaskExecutor > m_startupTasks
virtual void checkKeyBindingsOnPLayEventsStateChanged()
FWJobMetadataManager * m_metadataManagerPtr
fireworks::Context * context()
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
const std::string sGotoLastEvent
Definition: ActionsList.cc:4
void setGeom(FWGeometry *x)
Definition: Context.h:50
ESource getSource() const
Definition: FWMagField.h:31
virtual void previousEvent()=0
list lumi
Definition: dqmdumpme.py:53
virtual const edm::EventBase * getCurrentEvent() const =0
void eventChangedCallback()
void clearStatus()
void checkFieldInfo(const edm::EventBase *)
Definition: FWMagField.cc:144
std::string m_TGeoName
void add(std::shared_ptr< FWViewManagerBase >)
FWViewManagerManager * viewManager()
virtual void autoLoadNewEvent()=0
std::string m_simGeometryFilename
#define fwLog(_level_)
Definition: fwLog.h:45
double sd
const std::string sGotoFirstEvent
Definition: ActionsList.cc:3
tuple msg
Definition: mps_check.py:285
fireworks::Context * m_contextPtr
void add(const std::string &iName, FWConfigurable *)
does not take ownership
std::unique_ptr< FWConfigurationManager > m_configurationManager
const std::string sPreviousEvent
Definition: ActionsList.cc:6
tuple config
parse the configuration file
std::unique_ptr< FWViewManagerManager > m_viewManager
FWConfigurationManager * configurationManager()
void writeToCurrentConfigFile()
std::string m_autoSaveAllViewsFormat
void registerPhysicsObject(const FWPhysicsObjectDesc &iItem)
unsigned int RunNumber_t
#define get
const std::string sQuit
Definition: ActionsList.cc:27
void goToRunEvent(edm::RunNumber_t, edm::LuminosityBlockNumber_t, edm::EventNumber_t)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
sigc::signal< void > goingToClearItems_
virtual void lastEvent()=0
void setPath(TString &v)
Definition: fwPaths.cc:15
sigc::signal< void > newEvent_
std::string m_configFileName