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