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