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