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