CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWFFLooper.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include "boost/bind.hpp"
3 
21 
24 
39 
40 #include "TROOT.h"
41 #include "TSystem.h"
42 #include "TRint.h"
43 #include "TGLWidget.h"
44 
45 #include "TEveManager.h"
46 #include "TEveEventManager.h"
47 #include "TEveTrackPropagator.h"
48 #include "TEveBrowser.h"
49 #include "TGeoManager.h"
50 
51 
52 namespace edm
53 {
54  class StreamContext;
55  class ModuleCallingContext;
56 }
57 
58 namespace
59 {
60  class CmsEveMagField : public TEveMagField
61  {
62  private:
63  Float_t fField;
64  Float_t fFieldMag;
65 
66  public:
67 
68  CmsEveMagField() : TEveMagField(), fField(-3.8), fFieldMag(3.8) {}
69  virtual ~CmsEveMagField() {}
70 
71  // set current
72  void SetFieldByCurrent(Float_t avg_current)
73  {
74  fField = -3.8 * avg_current / 18160.0;
75  fFieldMag = TMath::Abs(fField);
76  }
77 
78  // get field values
79  virtual Float_t GetMaxFieldMag() const override
80  {
81  return fFieldMag;
82  }
83 
84  virtual TEveVector GetField(Float_t x, Float_t y, Float_t z) const override
85  {
86  static const Float_t barrelFac = 1.2 / 3.8;
87  static const Float_t endcapFac = 2.0 / 3.8;
88 
89  const Float_t R = sqrt(x*x+y*y);
90  const Float_t absZ = TMath::Abs(z);
91 
92  //barrel
93  if (absZ < 724.0f)
94  {
95  //inside solenoid
96  if (R < 300.0f) return TEveVector(0, 0, fField);
97 
98  // outside solinoid
99  if ((R > 461.0f && R < 490.5f) ||
100  (R > 534.5f && R < 597.5f) ||
101  (R > 637.0f && R < 700.0f))
102  {
103  return TEveVector(0, 0, -fField*barrelFac);
104  }
105  } else {
106  if ((absZ > 724.0f && absZ < 786.0f) ||
107  (absZ > 850.0f && absZ < 910.0f) ||
108  (absZ > 975.0f && absZ < 1003.0f))
109  {
110  const Float_t fac = (z >= 0 ? fField : -fField) * endcapFac / R;
111  return TEveVector(x*fac, y*fac, 0);
112  }
113  }
114  return TEveVector(0, 0, 0);
115  }
116  };
117 }
118 
119 //
120 // constants, enums and typedefs
121 //
122 
123 //
124 // static data member definitions
125 //
126 
127 //==============================================================================
128 // constructors and destructor
129 //==============================================================================
130 
132  : CmsShowMainBase(),
133  m_navigator(new FWFFNavigator(*this)),
134  m_metadataManager(new FWFFMetadataManager()),
135  m_context(new fireworks::Context(changeManager(),
136  selectionManager(),
137  eiManager(),
138  colorManager(),
139  m_metadataManager.get())),
140  m_Rint(m_appHelper->app()),
141  m_AllowStep(true),
142  m_ShowEvent(true),
143  m_firstTime(true),
144  m_pathsGUI(0),
145  m_geomWatcher(this, &FWFFLooper::remakeGeometry)
146 {
147  setup(m_navigator.get(), m_context.get(), m_metadataManager.get());
148 
149  eiManager()->setContext(m_context.get());
150 
151  // By default, we look up geometry and configuration in the workarea, then
152  // in the release area then in the local directory. It is also possible to
153  // override those locations by using the displayConfigurationFilename and
154  // geometryFilename in the parameterset.
155  const char *releaseBase = getenv("CMSSW_RELEASE_BASE");
156  const char *workarea = getenv("CMSSW_BASE");
157  std::string displayConfigRelFilename = "/src/Fireworks/FWInterface/macros/ffw.fwc";
158  std::string geometryRelFilename = "/src/Fireworks/FWInterface/data/cmsGeom10.root";
159 
160  std::string displayConfigFilename = "ffw.fwc";
162 
163  if (releaseBase && access((releaseBase + displayConfigFilename).c_str(), R_OK) == 0)
164  displayConfigFilename = releaseBase + displayConfigRelFilename;
165  if (workarea && access((workarea + displayConfigRelFilename).c_str(), R_OK) == 0)
166  displayConfigFilename = workarea + displayConfigRelFilename;
167 
168  if (releaseBase && access((releaseBase + geometryRelFilename).c_str(), R_OK) == 0)
169  geometryFilename = releaseBase + geometryRelFilename;
170  if (workarea && access((workarea + geometryRelFilename).c_str(), R_OK) == 0)
171  geometryFilename = workarea + geometryRelFilename;
172 
173  displayConfigFilename = ps.getUntrackedParameter<std::string>("displayConfigFilename", displayConfigFilename);
174  geometryFilename = ps.getUntrackedParameter<std::string>("geometryFilename", geometryFilename);
175 
176  setGeometryFilename(geometryFilename);
177  setConfigFilename(displayConfigFilename);
178 
179  if( !geometryFilename.empty())
180  {
182  }
183 
184  m_MagField = new CmsEveMagField();
185 }
186 
187 void
189 {
191  f=boost::bind( &CmsShowMainBase::loadGeometry, this );
192  startupTasks()->addTask( f );
193 }
194 
195 void
197 {
198  m_pathsGUI = new FWPathsPopup(this, guiManager());
199 
203 }
204 
206 {
207  delete m_MagField;
208 }
209 
210 
211 //==============================================================================
212 // Service watchers
213 //==============================================================================
214 
215 void
217 {
218  // Initialise on first loop.
219  if (count == 0)
220  {
222  m_pathsGUI->setup(info);
223 
224  // We need to enter the GUI loop in order to
225  // have all the callbacks executed. The last callback will
226  // be responsible for returning the control to CMSSW.
227  assert(m_Rint);
229  f=boost::bind(&TApplication::Terminate, m_Rint, 0);
230  startupTasks()->addTask(f);
231  // FIXME: do we really need to delay tasks like this?
233  m_Rint->Run(kTRUE);
234  // Show the GUI ...
235  gSystem->ProcessEvents();
236  }
237 }
238 
239 void
241 {
242  printf("FWFFLooper::postEndJob\n");
243  TEveManager::Terminate();
244 }
245 
246 void
248 {
249  if (loop() && isPlaying())
250  return;
251 
254 
255  if (m_isFirstEvent)
257 
258  if (m_isLastEvent)
259  {
260  guiManager()->disableNext();
261  // force enable play events action in --port mode
262  if (!guiManager()->playEventsAction()->isEnabled())
264  }
265 }
266 
271 void
273 {
275  bool reachedEnd = (forward() && m_isLastEvent) || (!forward() && m_isFirstEvent);
276 
277  if (!reachedEnd || loop())
278  {
279  // Will exit the loop here!
280  m_autoReload = true;
281  forward() ? m_navigator->nextEvent() : m_navigator->previousEvent();
282  }
283  else
284  {
285  m_autoReload = false;
286  setIsPlaying(false);
289  }
290 }
291 
292 void
294 {
296  m_autoReload = false;
297  setIsPlaying(false);
300  checkPosition();
301 }
302 
303 
304 //------------------------------------------------------------------------------
305 
306 void
307 FWFFLooper::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
308 {
309  // Check DisplayGeomRecord changes.
310  try {
311  m_geomWatcher.check(iSetup);
312  }
313  catch (...) {}
314 
315  // If the geometry was not picked up from a file, we try to get it from the
316  // EventSetup!
317  // FIXME: we need to check we execute only once because the view managers
318  // depend on geometry and they cannot be initialised more than once.
319  // This should actually be cleaned up so that the various view manager
320  // don't care about geometry.
321  // FIXME: we should actually be able to update the geometry when requested.
322  // this is not possible at the moment.
323  if (m_firstTime == true)
324  {
325  if (m_context->getGeom() == 0)
326  {
327  try
328  {
329  guiManager()->updateStatus("Loading geometry...");
331  iSetup.get<FWRecoGeometryRecord>().get(geoh);
332  getGeom().initMap(geoh.product()->idToName);
333  m_context->setGeom(&(getGeom()));
334  }
335  catch( const cms::Exception& exception )
336  {
337  setGeometryFilename("cmsGeom10.root");
339  }
340  }
341 
344  setupActions();
345 
346  guiManager()->showEventFilterGUI_.connect(boost::bind(&FWFFLooper::showPathsGUI, this, _1));
347  guiManager()->setFilterButtonText("Show paths / CMSSW configuration editor");
349 
350  m_firstTime = false;
351  m_autoReload = false;
352  }
353 
354  float current = 18160.0f;
355  try {
357  // bool res = iRun.getByType(runCond);
358  bool res = iRun.getByLabel("conditionsInEdm", runCond);
359  if (res && runCond.isValid())
360  {
361  printf("Got current from conds in edm %f\n", runCond->BAvgCurrent);
362  current = runCond->BAvgCurrent;
363  }
364  else
365  {
366  printf("Could not extract run-conditions get-result=%d, is-valid=%d\n", res, runCond.isValid());
367 
368  const edm::eventsetup::EventSetupRecord* rec = iSetup.find( edm::eventsetup::EventSetupRecordKey::makeKey<RunInfoRcd>());
369  if( 0 != rec )
370  {
372  iSetup.get<RunInfoRcd>().get(sum);
373 
374  current = sum->m_avg_current;
375  printf("Got current from RunInfoRcd %f\n", sum->m_avg_current);
376  }
377  }
378  }
379  catch (...) {
380  fwLog(fwlog::kInfo) << "ConditionsInRunBlock not available\n";
381  }
382  static_cast<CmsEveMagField*>(m_MagField)->SetFieldByCurrent(current);
383 }
384 
385 //------------------------------------------------------------------------------
388  const edm::EventSetup&es,
389  edm::ProcessingController &controller)
390 {
391  // Check DisplayGeomRecord changes.
392  try {
393  m_geomWatcher.check(es);
394  } catch (...) {}
395 
396 
397  m_pathsGUI->postEvent(event);
398 
401  // If the next event id is valid, set the transition so
402  // that we go to it go to to it.
403  if (m_nextEventId != edm::EventID())
404  {
407  return kContinue;
408  }
409  // We handle "last event" by going to the first event and then moving to the
410  // previous event.
411  if (m_navigator->currentTransition() == FWFFNavigator::kLastEvent)
412  {
413  m_navigator->resetTransition();
414  controller.setTransitionToPreviousEvent();
415  return kContinue;
416  }
417 
418  m_pathsGUI->hasChanges() = false;
419  m_metadataManager->update(new FWFFMetadataUpdateRequest(event));
420  m_navigator->setCurrentEvent(&event);
421  if (m_autoReload == true)
423 
424  checkPosition();
425  draw();
426 
427  m_Rint->Run(kTRUE);
428  // If the GUI changed the PSet, save the current event to reload
429  // it on next iteration.
430  if (m_pathsGUI->hasChanges())
431  {
433  return kStop;
434  }
435  else if (m_navigator->currentTransition() == FWFFNavigator::kFirstEvent)
436  {
437  m_nextEventId = m_navigator->getFirstEventID();
438  return kStop;
439  }
440  else if (m_navigator->currentTransition() == FWFFNavigator::kLastEvent)
441  {
442  m_nextEventId = m_navigator->getFirstEventID();
443  return kStop;
444  }
445  else if (m_navigator->currentTransition() == FWFFNavigator::kNextEvent)
446  controller.setTransitionToNextEvent();
447  else if (m_navigator->currentTransition() == FWFFNavigator::kPreviousEvent)
448  controller.setTransitionToPreviousEvent();
449  return kContinue;
450 }
451 
452 //------------------------------------------------------------------------------
453 void
455 {
456  // Display whatever was registered so far, wait until user presses
457  // the "Step" button.
458 
459  if (m_AllowStep)
460  {
461  gEve->Redraw3D();
462  m_Rint->Run(kTRUE);
463  }
464 }
465 
466 //==============================================================================
467 // Getters for cleints
468 //==============================================================================
469 
470 TEveMagField*
472 {
473  return m_MagField;
474 }
475 
476 void
477 FWFFLooper::setupFieldForPropagator(TEveTrackPropagator* prop)
478 {
479  prop->SetMagFieldObj(m_MagField, kFALSE);
480 }
481 
482 void
484 {
485  gSystem->ExitLoop();
486 
487  // Throwing exception here is bad because:
488  // a) it does not work when in a "debug step";
489  // b) does not restore terminal state.
490  // So we do exit instead for now.
491  // throw cms::Exception("UserTerminationRequest");
492  gSystem->Exit(0);
493 }
494 
501 {
502  // Looks like the module changer is availble only here.
503  for (ModuleChanges::iterator i = m_scheduledChanges.begin(),
504  e = m_scheduledChanges.end();
505  i != e; ++i)
506  {
507  try {
508  moduleChanger()->changeModule(i->first, i->second);
509  }
510  catch (cms::Exception const& e)
511  {
512  fwLog(fwlog::kError) << "FWFFLooper::endOfLoop caught exception.\n";
513  std::cerr << e.what() << std::endl;
514  }
515  }
516  m_scheduledChanges.clear();
517  return kContinue;
518 }
519 
520 void
521 FWFFLooper::showPathsGUI(const TGWindow *)
522 {
523  if (!m_pathsGUI)
524  return;
525  if (m_pathsGUI->IsMapped())
526  {
527  guiManager()->setFilterButtonText("Show paths / CMSSW configuration editor");
528  m_pathsGUI->UnmapWindow();
529  }
530  else
531  {
532  guiManager()->setFilterButtonText("Hide paths / CMSSW configuration editor");
533  m_pathsGUI->MapWindow();
534  }
535 }
536 
537 void
539 {
540  m_scheduledChanges[moduleLabel] = ps;
541 }
542 
543 //______________________________________________________________________________
544 
545 void
547 {
548  fwLog(fwlog::kInfo) << "FWFFLooper set TGeo geomtery from DisplayGeomRecord.\n";
549 
551  dgRec.get(geom);
552  TEveGeoManagerHolder _tgeo(const_cast<TGeoManager*>(geom.product()));
554 }
edm::ESWatcher< DisplayGeomRecord > m_geomWatcher
Definition: FWFFLooper.h:110
virtual char const * what() const
Definition: Exception.cc:141
TEveMagField * getMagField()
Definition: FWFFLooper.cc:471
virtual edm::EDLooperBase::Status endOfLoop(const edm::EventSetup &, unsigned int) override
Definition: FWFFLooper.cc:500
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:214
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
void preModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
sigc::signal< void > filterButtonClicked_
Definition: FWGUIManager.h:205
static const TGPicture * info(bool iBackgroundIsBlack)
bool m_isLastEvent
Definition: FWFFLooper.h:108
void setupFieldForPropagator(TEveTrackPropagator *prop)
Definition: FWFFLooper.cc:477
FWGUIManager * guiManager()
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void initMap(const FWRecoGeom::InfoMap &map)
Definition: FWGeometry.cc:143
virtual void stopPlaying()
Definition: FWFFLooper.cc:293
void watchPreModuleEvent(PreModuleEvent::slot_type const &iSlot)
void enable()
Definition: CSGAction.cc:284
FWEventItemsManager * eiManager()
ModuleChanges m_scheduledChanges
Definition: FWFFLooper.h:104
virtual void startingNewLoop(unsigned int) override
Definition: FWFFLooper.cc:216
FWPathsPopup * m_pathsGUI
Definition: FWFFLooper.h:101
void watchPostModuleEvent(PostModuleEvent::slot_type const &iSlot)
TEveMagField * m_MagField
Definition: FWFFLooper.h:96
void postEndJob()
Definition: FWFFLooper.cc:240
void setup(FWNavigatorBase *navigator, fireworks::Context *context, FWJobMetadataManager *metadataManager)
virtual ~FWFFLooper()
Definition: FWFFLooper.cc:205
void remakeGeometry(const DisplayGeomRecord &dgRec)
Definition: FWFFLooper.cc:546
void updateStatus(const char *status)
void setContext(fireworks::Context *)
FWFFLooper(const edm::ParameterSet &)
Definition: FWFFLooper.cc:131
void loadDefaultGeometryFile(void)
Definition: FWFFLooper.cc:188
float float float z
void enableActions(bool enable=true)
const eventsetup::EventSetupRecord * find(const eventsetup::EventSetupRecordKey &) const
Definition: EventSetup.cc:90
void requestChanges(const std::string &, const edm::ParameterSet &)
Definition: FWFFLooper.cc:538
virtual edm::EDLooperBase::Status duringLoop(const edm::Event &, const edm::EventSetup &, edm::ProcessingController &) override
Definition: FWFFLooper.cc:387
void display(const std::string &info="")
Definition: FWFFLooper.cc:454
void setGeometryFilename(const std::string &filename)
void setTransitionToEvent(edm::EventID const &iID)
bool changeModule(const std::string &iLabel, const ParameterSet &iPSet) const
bool loop() const
CmsShowTaskExecutor * startupTasks()
bool m_autoReload
Definition: FWFFLooper.h:106
ForwardState forwardState() const
Returns the present state of processing.
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
Called after all event modules have processed the begin of a Run.
Definition: FWFFLooper.cc:307
T sqrt(T t)
Definition: SSEVec.h:48
ModuleChanger const * moduleChanger() const
This only returns a non-zero value during the call to endOfLoop.
sigc::signal< void, const TGWindow * > showEventFilterGUI_
Definition: FWGUIManager.h:206
std::auto_ptr< FWFFNavigator > m_navigator
Definition: FWFFLooper.h:89
void get(HolderT &iHolder) const
std::auto_ptr< FWFFMetadataManager > m_metadataManager
Definition: FWFFLooper.h:90
T Abs(T a)
Definition: MathUtil.h:49
bool & hasChanges()
Definition: FWPathsPopup.h:37
TRint * m_Rint
Definition: FWFFLooper.h:94
double f[11][100]
bool m_firstTime
Definition: FWFFLooper.h:100
CmsShowMainFrame * getMainFrame() const
Definition: FWGUIManager.h:199
void disablePrevious()
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
bool isValid() const
Definition: HandleBase.h:76
ScheduleInfo const * scheduleInfo() const
This returns a non-zero value after the constructor has been called.
bool m_isFirstEvent
Definition: FWFFLooper.h:107
void setIsPlaying(bool value)
#define fwLog(_level_)
Definition: fwLog.h:50
virtual void checkPosition()
Definition: FWFFLooper.cc:247
virtual void attachTo(edm::ActivityRegistry &)
Override this method if you need to monitor the state of the processing.
Definition: FWFFLooper.cc:196
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
bool m_AllowStep
Definition: FWFFLooper.h:98
void setFilterButtonText(const char *txt)
void quit()
Definition: FWFFLooper.cc:483
void postModuleEvent(edm::StreamContext const &, edm::ModuleCallingContext const &)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
CSGContinuousAction * playEventsAction()
bool isPlaying() const
FWGeometry & getGeom()
boost::function0< void > TaskFunctor
void postEvent(edm::Event const &event)
void showEventFilterGUI()
void addTask(const TaskFunctor &iTask)
static void setGeoManagerRuntime(TGeoManager *)
void showPathsGUI(const TGWindow *p)
Definition: FWFFLooper.cc:521
bool forward() const
Definition: DDAxes.h:10
const std::string & geometryFilename(void)
void enableComplexNavigation(bool enable=true)
virtual void autoLoadNewEvent()
Definition: FWFFLooper.cc:272
void setup(const edm::ScheduleInfo *info)
edm::EventID m_nextEventId
Definition: FWFFLooper.h:105
void disableNext()
void setConfigFilename(const std::string &f)
T get(const Candidate &c)
Definition: component.h:55
std::auto_ptr< fireworks::Context > m_context
Definition: FWFFLooper.h:91
ReverseState reverseState() const
Definition: Run.h:41