CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 <boost/bind.hpp>
9 
10 #include "TGLWidget.h"
11 #include "TGMsgBox.h"
12 #include "TROOT.h"
13 #include "TSystem.h"
14 #include "TStopwatch.h"
15 #include "TTimer.h"
16 #include "TEveManager.h"
17 #include "TPRegexp.h"
18 
48 
50  :
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(0),
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(0),
61  m_metadataManagerPtr(0),
62  m_contextPtr(0),
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)
69 {
71 }
72 
74 {
75 }
76 
77 void
79 {
80  m_guiManager->writeToPresentConfigurationFile_.connect(sigc::mem_fun(*this, &CmsShowMainBase::writeToCurrentConfigFile));
81 
82  // init TGSlider state before signals are connected
83  m_guiManager->setDelayBetweenEvents(m_playDelay);
84 
85  m_navigatorPtr->newEvent_.connect(boost::bind(&CmsShowMainBase::eventChangedSlot, this));
86  if (m_guiManager->getAction(cmsshow::sNextEvent) != 0)
87  m_guiManager->getAction(cmsshow::sNextEvent)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doNextEvent));
88  if (m_guiManager->getAction(cmsshow::sPreviousEvent) != 0)
89  m_guiManager->getAction(cmsshow::sPreviousEvent)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doPreviousEvent));
90  if (m_guiManager->getAction(cmsshow::sGotoFirstEvent) != 0)
91  m_guiManager->getAction(cmsshow::sGotoFirstEvent)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doFirstEvent));
92  if (m_guiManager->getAction(cmsshow::sGotoLastEvent) != 0)
93  m_guiManager->getAction(cmsshow::sGotoLastEvent)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::doLastEvent));
94  if (m_guiManager->getAction(cmsshow::sQuit) != 0)
95  m_guiManager->getAction(cmsshow::sQuit)->activated.connect(sigc::mem_fun(*this, &CmsShowMainBase::quit));
96 
97  m_guiManager->changedEventId_.connect(boost::bind(&CmsShowMainBase::goToRunEvent,this,_1,_2,_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(boost::bind(&CmsShowMainBase::setPlayDelay,this,_1));
103  m_guiManager->playEventsAction()->stopped_.connect(sigc::mem_fun(*this,&CmsShowMainBase::stopPlaying));
104  m_guiManager->playEventsBackwardsAction()->stopped_.connect(sigc::mem_fun(*this,&CmsShowMainBase::stopPlaying));
105 
106  m_autoLoadTimer->timeout_.connect(boost::bind(&CmsShowMainBase::autoLoadNewEvent, this));
107 }
108 
109 void
111 {
112  guiManager()->updateStatus("Setting up view manager...");
113 
114  boost::shared_ptr<FWViewManagerBase> eveViewManager(new FWEveViewManager(guiManager()));
115  eveViewManager->setContext(m_contextPtr);
116  viewManager()->add(eveViewManager);
117 
118  boost::shared_ptr<FWTableViewManager> tableViewManager(new FWTableViewManager(guiManager()));
119  configurationManager()->add(std::string("Tables"), tableViewManager.get());
120  viewManager()->add(tableViewManager);
121  eiManager()->goingToClearItems_.connect(boost::bind(&FWTableViewManager::removeAllItems, tableViewManager.get()));
122 
123  boost::shared_ptr<FWTriggerTableViewManager> triggerTableViewManager(new FWTriggerTableViewManager(guiManager()));
124  configurationManager()->add(std::string("TriggerTables"), triggerTableViewManager.get());
125  configurationManager()->add(std::string("L1TriggerTables"), triggerTableViewManager.get()); // AMT: added for backward compatibilty
126  triggerTableViewManager->setContext(m_contextPtr);
127  viewManager()->add(triggerTableViewManager);
128 
129  boost::shared_ptr<FWGeometryTableViewManager> geoTableViewManager(new FWGeometryTableViewManager(guiManager(), m_simGeometryFilename));
130  geoTableViewManager->setContext(m_contextPtr);
131  viewManager()->add(geoTableViewManager);
132 
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 
143 void
145 {
146  eventChangedImp();
147 }
148 
149 void
151 {
153 }
154 
155 void
157 {
159  checkPosition();
160  draw();
161 }
162 
163 void
165 {
167  checkPosition();
168  draw();
169 }
170 
171 void
173 {
175  checkPosition();
176  draw();
177 }
178 void
180 {
182  checkPosition();
183  draw();
184 }
185 
186 void
188 {
189  m_navigatorPtr->goToRunEvent(run, lumi, event);
190  checkPosition();
191  draw();
192 }
193 
194 
195 void
197 {
198  m_guiManager->updateStatus("loading event ...");
199 
201  {
203  }
205 
206  TStopwatch sw;
207  m_viewManager->eventBegin();
209  m_viewManager->eventEnd();
210  sw.Stop();
211  fwLog(fwlog::kDebug) << "CmsShowMainBase::draw CpuTime " << sw.CpuTime()
212  <<" RealTime " << sw.RealTime() << std::endl;
213 
214  if (!m_autoSaveAllViewsFormat.empty())
215  {
216  m_guiManager->updateStatus("auto saving images ...");
218  }
219  m_guiManager->clearStatus();
220 }
221 
222 void
224  fireworks::Context *context,
225  FWJobMetadataManager *metadataManager)
226 {
229  m_metadataManagerPtr = metadataManager;
230 
231  m_colorManager->initialize();
234 
235  m_eiManager->newItem_.connect(boost::bind(&FWModelChangeManager::newItemSlot,
236  m_changeManager.get(), _1) );
237 
238  m_eiManager->newItem_.connect(boost::bind(&FWViewManagerManager::registerEventItem,
239  m_viewManager.get(), _1));
240  m_configurationManager->add("EventItems",m_eiManager.get());
241  m_configurationManager->add("GUI",m_guiManager.get());
242  m_configurationManager->add("EventNavigator", m_navigatorPtr);
243  m_configurationManager->add("CommonPreferences", m_contextPtr->commonPrefs()); // must be after GUIManager in alphabetical order
244 
245  m_guiManager->writeToConfigurationFile_.connect(boost::bind(&CmsShowMainBase::writeToConfigFile,
246  this,_1));
247 
248  m_guiManager->loadFromConfigurationFile_.connect(boost::bind(&CmsShowMainBase::reloadConfiguration,
249  this, _1));
250  m_guiManager->loadPartialFromConfigurationFile_.connect(boost::bind(&CmsShowMainBase::partialLoadConfiguration,
251  this, _1));
252 
253  m_guiManager->writePartialToConfigurationFile_.connect(boost::bind(&CmsShowMainBase::partialWriteToConfigFile,
254  this,_1));
255 
256  std::string macPath(gSystem->Getenv("CMSSW_BASE"));
257  macPath += "/src/Fireworks/Core/macros";
258  const char* base = gSystem->Getenv("CMSSW_RELEASE_BASE");
259  if(0!=base) {
260  macPath+=":";
261  macPath +=base;
262  macPath +="/src/Fireworks/Core/macros";
263  }
264  gROOT->SetMacroPath((std::string("./:")+macPath).c_str());
265 
266  m_startupTasks->tasksCompleted_.connect(boost::bind(&FWGUIManager::clearStatus,
267  m_guiManager.get()) );
268 }
269 
270 void
272 {
275 }
276 
277 void
279 {
281 }
282 
283 void
285 {
286  std::string p = (name == "current") ? m_configFileName.c_str() : name.c_str();
287  new FWPartialConfigSaveGUI( p.c_str() , m_configFileName.c_str(), m_configurationManager.get());
288 
289 }
290 
291 
292 void
294 {
295  if (config.empty())
296  return;
297 
299 
300  std::string msg = "Reloading configuration "
301  + config + "...";
302  fwLog(fwlog::kDebug) << msg << std::endl;
303  m_guiManager->updateStatus(msg.c_str());
304  m_guiManager->subviewDestroyAll();
305  m_eiManager->clearItems();
307  try
308  {
309  gEve->DisableRedraw();
310  m_configurationManager->readFromFile(config);
311  gEve->EnableRedraw();
312  }
314  {
315  Int_t chosen;
316  new TGMsgBox(gClient->GetDefaultRoot(),
317  gClient->GetDefaultRoot(),
318  "Bad configuration",
319  ("Configuration " + config + " cannot be parsed: " + e.error()).c_str(),
320  kMBIconExclamation,
321  kMBCancel,
322  &chosen);
323  }
324  catch (...)
325  {
326  Int_t chosen;
327  new TGMsgBox(gClient->GetDefaultRoot(),
328  gClient->GetDefaultRoot(),
329  "Bad configuration",
330  ("Configuration " + config + " cannot be parsed.").c_str(),
331  kMBIconExclamation,
332  kMBCancel,
333  &chosen);
334  }
335 
336  m_guiManager->updateStatus("");
337 }
338 
339 
340 void
342 {
343  new FWPartialConfigLoadGUI(name.c_str(), m_configurationManager.get(), m_eiManager.get());
344 }
345 
346 void
348 {
349  m_playDelay = x;
350  m_guiManager->setDelayBetweenEvents(m_playDelay);
351  if (!m_guiManager->playEventsAction()->isEnabled())
352  m_guiManager->playEventsAction()->enable();
353 
354  m_guiManager->playEventsAction()->switchMode();
355 }
356 
357 void
359 {
360  m_autoLoadTimer->SetTime((Long_t)(m_playDelay*1000));
361  m_autoLoadTimer->Reset();
362  m_autoLoadTimer->TurnOn();
363  m_autoLoadTimerRunning = kTRUE;
364 }
365 
366 void
368 {
369  m_autoLoadTimer->TurnOff();
370  m_autoLoadTimerRunning = kFALSE;
371 }
372 
373 void
375 {
376  m_guiManager->updateStatus("Setting up configuration...");
377 
378  if(m_configurationManager->getIgnore()) {
379  fwLog(fwlog::kInfo) << "no configuration is loaded." << std::endl;
380  m_configFileName = "newconfig.fwc";
381  }
382  else {
383  try
384  {
385  gEve->DisableRedraw();
386  if (m_configFileName.empty())
387  {
389  }
390  else
391  {
392  char* whereConfig = gSystem->Which(TROOT::GetMacroPath(), m_configFileName.c_str(), kReadPermission);
393  m_configFileName = whereConfig;
394  delete [] whereConfig;
396  }
397  gEve->EnableRedraw();
398  }
400  {
401  fwLog(fwlog::kError) <<"Unable to load configuration file '"
402  << m_configFileName
403  << "': "
404  << e.error()
405  << std::endl;
406  exit(1);
407  }
408  catch (std::runtime_error &e)
409  {
410  fwLog(fwlog::kError) <<"Unable to load configuration file '"
411  << m_configFileName
412  << "' which was specified on command line. Quitting."
413  << std::endl;
414  exit(1);
415  }
416 
417 
418  }
419 
420  // case configuration does not contain GUI Manager entry
421  if ( !m_guiManager->getMainFrame()->IsMapped()) {
422 
423  m_guiManager->getMainFrame()->MapSubwindows();
424  m_guiManager->getMainFrame()->Layout();
425  m_guiManager->getMainFrame()->MapRaised();
426  m_guiManager->createView("Rho Phi");
427  m_guiManager->createView("Rho Z");
428  }
429 }
430 
431 
432 void
434 {
435  m_playDelay = val;
436 }
437 
438 void
440 {
441  m_guiManager->updateStatus("Setting up Eve debug window...");
442  m_guiManager->openEveBrowserForDebugging();
443 }
444 
445 void
447 {
448  if(!m_loop) {
449  setPlayLoopImp();
450  m_guiManager->loopAction()->activated();
451  }
452 }
453 
454 void
456 {
457  if(m_loop) {
459  m_guiManager->loopAction()->stop();
460  }
461 }
462 
463 void
465 {
466  m_loop = true;
467 }
468 
469 void
471 {
472  m_loop = false;
473 }
474 
475 void
477 {
478  m_eiManager->add(iItem);
479 }
480 
481 
482 void
484 {
485  m_isPlaying = false;
487 }
488 
489 void
491 {
492  m_forward = true;
493  m_isPlaying = true;
494  guiManager()->enableActions(kFALSE);
497 }
498 
499 void
501 {
502  m_forward = false;
503  m_isPlaying = true;
504  guiManager()->enableActions(kFALSE);
507 }
508 
509 void
511 { // prepare geometry service
512  // ATTN: this should be made configurable
513  try
514  {
515  guiManager()->updateStatus("Loading geometry...");
518  }
519  catch (const std::runtime_error& iException)
520  {
521  fwLog(fwlog::kError) << "CmsShowMain::loadGeometry() caught exception: \n"
522  << m_geometryFilename << " "
523  << iException.what() << std::endl;
524  exit(0);
525  }
526 }
527 
528 void
530 {
531  // Send version info to xrootd.t2.ucsd.edu receiver on port 9698.
532 
533  // receiver
534  struct hostent* h = gethostbyname("xrootd.t2.ucsd.edu");
535  if (!h) return;
536 
537 
538  struct sockaddr_in remoteServAddr;
539  remoteServAddr.sin_family = h->h_addrtype;
540  memcpy((char *) &remoteServAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
541  remoteServAddr.sin_port = htons(9698);
542 
543  // socket creation
544  int sd = socket(AF_INET,SOCK_DGRAM, 0);
545  if (sd < 0)
546  {
547  // std::cout << "can't create socket \n";
548  return;
549  }
550  // bind any port
551  // printf("bind port\n");
552  struct sockaddr_in cliAddr;
553  cliAddr.sin_family = AF_INET;
554  cliAddr.sin_addr.s_addr = htonl(INADDR_ANY);
555  cliAddr.sin_port = htons(0);
556 
557  int rc = bind(sd, (struct sockaddr *) &cliAddr, sizeof(cliAddr));
558  if (rc < 0) {
559  // std::cout << "can't bind port %d " << rc << std::endl;
560  return;
561  }
562 
563  // get OSX version
564  TString osx_version;
565  try {
566  std::ifstream infoFile("/System/Library/CoreServices/SystemVersion.plist");
567  osx_version.ReadFile(infoFile);
568  TPMERegexp re("ProductVersion\\</key\\>\\n\\t\\<string\\>(10.*)\\</string\\>");
569  re.Match(osx_version);
570  osx_version = re[1];
571  }
572  catch (...) {}
573 
574  // send data
575  SysInfo_t sInfo;
576  gSystem->GetSysInfo(&sInfo);
577  char msg[128];
578 
579  if (gSystem->Getenv("CMSSW_VERSION"))
580  {
581  snprintf(msg, 64,"%s %s %s", gSystem->Getenv("CMSSW_VERSION"), sInfo.fOS.Data(), osx_version.Data());
582  }
583  else
584  {
585  TString versionFileName("data/version.txt");
586  fireworks::setPath(versionFileName);
587  std::ifstream fs(versionFileName);
588  TString infoText;
589  infoText.ReadLine(fs);
590  fs.close();
591  snprintf(msg, 64,"Standalone %s %s %s", infoText.Data(), sInfo.fOS.Data(), osx_version.Data() );
592  }
593 
594 
595  int flags = 0;
596  sendto(sd, msg, strlen(msg), flags,
597  (struct sockaddr *) &remoteServAddr,
598  sizeof(remoteServAddr));
599 }
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::auto_ptr< FWConfigurationManager > m_configurationManager
std::string m_geometryFilename
FWGUIManager * guiManager()
void setGeom(const FWGeometry *x)
Definition: Context.h:51
void writeToConfigFile(const std::string &config)
virtual void nextEvent()=0
tuple lumi
Definition: fjr2json.py:35
FWEventItemsManager * eiManager()
unsigned long long EventNumber_t
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
void initReps(const FWTypeToRepresentations &iTypeAndReps)
void partialLoadConfiguration(const std::string &config)
void initEveElements()
Definition: Context.cc:96
std::auto_ptr< FWEventItemsManager > m_eiManager
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()
void setupAutoLoad(float x)
FWNavigatorBase * m_navigatorPtr
void newItemSlot(FWEventItem *)
FWBeamSpot * getBeamSpot() const
Definition: Context.h:78
void reloadConfiguration(const std::string &config)
virtual void stopPlaying()
FWMagField * getField() const
Definition: Context.h:77
virtual void firstEvent()=0
std::auto_ptr< SignalTimer > m_autoLoadTimer
void loadMap(const char *fileName)
Definition: FWGeometry.cc:52
void setPlayDelay(Float_t val)
virtual void eventChangedImp()
virtual void quit()=0
virtual void checkKeyBindingsOnPLayEventsStateChanged()
FWJobMetadataManager * m_metadataManagerPtr
fireworks::Context * context()
double f[11][100]
const std::string sGotoLastEvent
Definition: ActionsList.cc:4
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
ESource getSource() const
Definition: FWMagField.h:33
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void previousEvent()=0
virtual const edm::EventBase * getCurrentEvent() const =0
std::auto_ptr< CmsShowTaskExecutor > m_startupTasks
void eventChangedCallback()
void clearStatus()
void checkFieldInfo(const edm::EventBase *)
Definition: FWMagField.cc:172
FWViewManagerManager * viewManager()
virtual void autoLoadNewEvent()=0
std::string m_simGeometryFilename
void add(boost::shared_ptr< FWViewManagerBase >)
#define fwLog(_level_)
Definition: fwLog.h:50
double sd
const std::string sGotoFirstEvent
Definition: ActionsList.cc:3
fireworks::Context * m_contextPtr
CmsShowCommon * commonPrefs() const
Definition: Context.cc:179
void add(const std::string &iName, FWConfigurable *)
does not take ownership
const std::string sPreviousEvent
Definition: ActionsList.cc:6
FWConfigurationManager * configurationManager()
void writeToCurrentConfigFile()
std::string m_autoSaveAllViewsFormat
std::auto_ptr< FWModelChangeManager > m_changeManager
void registerPhysicsObject(const FWPhysicsObjectDesc &iItem)
unsigned int RunNumber_t
volatile std::atomic< bool > shutdown_flag false
Definition: DDAxes.h:10
const std::string sQuit
Definition: ActionsList.cc:28
void goToRunEvent(edm::RunNumber_t, edm::LuminosityBlockNumber_t, edm::EventNumber_t)
std::auto_ptr< FWViewManagerManager > m_viewManager
std::auto_ptr< FWColorManager > m_colorManager
sigc::signal< void > goingToClearItems_
std::auto_ptr< FWGUIManager > m_guiManager
T get(const Candidate &c)
Definition: component.h:55
virtual void lastEvent()=0
void setPath(TString &v)
Definition: fwPaths.cc:15
sigc::signal< void > newEvent_
std::string m_configFileName