Belle II Software  release-05-02-19
CalibrationCollectorModule.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Tadeas Bilka (tadeas.bilka@gmail.com) *
7  * David Dossett (david.dossett@unimelb.edu.au) *
8  * *
9  * This software is provided "as is" without any warranty. *
10  **************************************************************************/
11 
12 #pragma once
13 
14 #include <memory>
15 
16 #include <TDirectory.h>
17 #include <TRandom.h>
18 
19 #include <framework/core/HistoModule.h>
20 #include <framework/dataobjects/EventMetaData.h>
21 #include <framework/datastore/StoreObjPtr.h>
22 
23 #include <calibration/dataobjects/RunRange.h>
24 #include <calibration/CalibObjManager.h>
25 #include <calibration/Utilities.h>
26 
27 namespace Belle2 {
35  class CalibrationCollectorModule: public HistoModule {
36 
37  public:
41  virtual ~CalibrationCollectorModule() {}
42 
44  void initialize() final;
46  void event() final;
48  void beginRun() final;
50  void endRun() final;
52  void terminate() final;
54  void defineHisto() final;
55 
57  template <class T>
58  void registerObject(std::string name, T* obj)
59  {
60  std::shared_ptr<T> calObj(obj);
61  calObj->SetName(name.c_str());
62  m_manager.addObject(name, calObj);
63  }
64 
66  template<class T>
67  T* getObjectPtr(std::string name)
68  {
69  return m_manager.getObject<T>(name, m_expRun);
70  }
71 
72  protected:
74  virtual void prepare() {}
76  virtual void collect() {}
78  virtual void startRun() {}
80  virtual void closeRun() {}
82  virtual void finish() {}
84  virtual void inDefineHisto() {}
85 
87  TDirectory* m_dir;
88 
91 
94 
96  Calibration::ExpRun m_expRun;
97 
100 
101  private:
102  /****** Module Parameters *******/
104  std::string m_granularity;
106  int m_maxEventsPerRun;
108  float m_preScale;
109  /********************************/
110 
113  bool m_runCollectOnRun = true;
118  std::map<Calibration::ExpRun, int> m_expRunEvents;
125  bool getPreScaleChoice()
126  {
127  if (m_preScale == 1.) {
128  return true;
129  } else if (m_preScale == 0.) {
130  return false;
131  } else {
132  const double randomNumber = gRandom->Uniform();
133  return randomNumber < m_preScale;
134  }
135  }
136  };
138 } // Belle2 namespace
Belle2::CalibrationCollectorModule::registerObject
void registerObject(std::string name, T *obj)
Register object with a name, takes ownership, do not access the pointer beyond prepare()
Definition: CalibrationCollectorModule.h:67
Belle2::CalibrationCollectorModule::inDefineHisto
virtual void inDefineHisto()
Replacement for defineHisto(). Do anything you would normally do in defineHisto here.
Definition: CalibrationCollectorModule.h:93
Belle2::CalibrationCollectorModule::getPreScaleChoice
bool getPreScaleChoice()
I'm a little worried about floating point precision when comparing to 0.0 and 1.0 as special values.
Definition: CalibrationCollectorModule.h:134
Belle2::CalibrationCollectorModule::CalibrationCollectorModule
CalibrationCollectorModule()
Constructor. Sets the default prefix for calibration dataobjects.
Definition: CalibrationCollectorModule.cc:8
Belle2::CalibrationCollectorModule::m_runRange
RunRange * m_runRange
Overall list of runs processed.
Definition: CalibrationCollectorModule.h:102
Belle2::CalibrationCollectorModule::startRun
virtual void startRun()
Replacement for beginRun(). Do anything you would normally do in beginRun here.
Definition: CalibrationCollectorModule.h:87
Belle2::CalibObjManager::addObject
void addObject(const std::string &name, std::shared_ptr< TNamed > object)
Add a new object to manage, this is used as a template for creating future/missing objects.
Definition: CalibObjManager.cc:33
Belle2::CalibrationCollectorModule::m_dir
TDirectory * m_dir
The top TDirectory that collector objects for this collector will be stored beneath.
Definition: CalibrationCollectorModule.h:96
Belle2::CalibrationCollectorModule::getObjectPtr
T * getObjectPtr(std::string name)
Calls the CalibObjManager to get the requested stored collector data.
Definition: CalibrationCollectorModule.h:76
Belle2::CalibrationCollectorModule::m_expRun
Calibration::ExpRun m_expRun
Current ExpRun for object retrieval (becomes -1,-1 for granularity=all)
Definition: CalibrationCollectorModule.h:105
Belle2::CalibrationCollectorModule::m_granularity
std::string m_granularity
Granularity of data collection = run|all(= no granularity, exp,run=-1,-1)
Definition: CalibrationCollectorModule.h:113
Belle2::CalibrationCollectorModule::m_evtMetaData
StoreObjPtr< EventMetaData > m_evtMetaData
Required input for EventMetaData.
Definition: CalibrationCollectorModule.h:120
Belle2::CalibrationCollectorModule::m_maxEventsPerRun
int m_maxEventsPerRun
Maximum number of events to be collected at the start of each run (-1 = no maximum)
Definition: CalibrationCollectorModule.h:115
Belle2::CalibrationCollectorModule::m_eventsCollectedInRun
int * m_eventsCollectedInRun
Will point at correct value in m_expRunEvents.
Definition: CalibrationCollectorModule.h:129
Belle2::CalibrationCollectorModule::closeRun
virtual void closeRun()
Replacement for endRun(). Do anything you would normally do in endRun here.
Definition: CalibrationCollectorModule.h:89
Belle2::CalibrationCollectorModule::m_expRunEvents
std::map< Calibration::ExpRun, int > m_expRunEvents
How many events processed for each ExpRun so far, stops counting up once max is hit Only used/increme...
Definition: CalibrationCollectorModule.h:127
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CalibrationCollectorModule::m_preScale
float m_preScale
Prescale module parameter, this fraction of events will have collect() run on them [0....
Definition: CalibrationCollectorModule.h:117
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::CalibrationCollectorModule::m_runCollectOnRun
bool m_runCollectOnRun
Whether or not we will run the collect() at all this run, basically skips the event() function if fal...
Definition: CalibrationCollectorModule.h:123
Belle2::CalibrationCollectorModule::m_emd
StoreObjPtr< EventMetaData > m_emd
Current EventMetaData.
Definition: CalibrationCollectorModule.h:108
Belle2::CalibObjManager
Manager class for collector registered data. Handles much of the TDirectory/TObject manipulation.
Definition: CalibObjManager.h:22
Belle2::CalibrationCollectorModule::m_manager
CalibObjManager m_manager
Controls the creation, collection and access to calibration objects.
Definition: CalibrationCollectorModule.h:99
Belle2::CalibrationCollectorModule::~CalibrationCollectorModule
virtual ~CalibrationCollectorModule()
Virtual destructor (base class)
Definition: CalibrationCollectorModule.h:50
Belle2::CalibrationCollectorModule::initialize
void initialize() final
Set up a default RunRange object in datastore and call prepare()
Definition: CalibrationCollectorModule.cc:37
Belle2::CalibrationCollectorModule::event
void event() final
Check current experiment and run and update if needed, fill into RunRange and collect()
Definition: CalibrationCollectorModule.cc:45
Belle2::CalibrationCollectorModule::terminate
void terminate() final
Write the final objects to the file.
Definition: CalibrationCollectorModule.cc:148
Belle2::CalibObjManager::getObject
T * getObject(const std::string &name, const Belle2::Calibration::ExpRun expRun)
Gets the collector object of this name for the given exprun.
Definition: CalibObjManager.h:73
Belle2::CalibrationCollectorModule::finish
virtual void finish()
Replacement for terminate(). Do anything you would normally do in terminate here.
Definition: CalibrationCollectorModule.h:91
Belle2::RunRange
Mergeable object holding (unique) set of (exp,run) pairs.
Definition: RunRange.h:18
Belle2::CalibrationCollectorModule::endRun
void endRun() final
Write the current collector objects to a file and clear their memory.
Definition: CalibrationCollectorModule.cc:136
Belle2::CalibrationCollectorModule::collect
virtual void collect()
Replacement for event(). Fill you calibration data objects here.
Definition: CalibrationCollectorModule.h:85
Belle2::CalibrationCollectorModule::defineHisto
void defineHisto() final
Runs due to HistoManager, allows us to discover the correct file.
Definition: CalibrationCollectorModule.cc:120
Belle2::CalibrationCollectorModule::prepare
virtual void prepare()
Replacement for initialize(). Register calibration dataobjects here as well.
Definition: CalibrationCollectorModule.h:83
Belle2::CalibrationCollectorModule::beginRun
void beginRun() final
Reset the m_runCollectOnRun flag, if necessary, to begin collection again.
Definition: CalibrationCollectorModule.cc:70