Belle II Software development
CalibrationCollectorModule.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <memory>
12
13#include <TDirectory.h>
14#include <TRandom.h>
15
16#include <framework/core/HistoModule.h>
17#include <framework/dataobjects/EventMetaData.h>
18#include <framework/datastore/StoreObjPtr.h>
19
20#include <calibration/dataobjects/RunRange.h>
21#include <calibration/CalibObjManager.h>
22#include <calibration/Utilities.h>
23
24namespace Belle2 {
33
34 public:
39
41 void initialize() final;
43 void event() final;
45 void beginRun() final;
47 void endRun() final;
49 void terminate() final;
51 void defineHisto() final;
52
54 template <class T>
55 void registerObject(std::string name, T* obj)
56 {
57 std::shared_ptr<T> calObj(obj);
58 calObj->SetName(name.c_str());
59 m_manager.addObject(name, calObj);
60 }
61
63 template<class T>
64 T* getObjectPtr(std::string name)
65 {
66 return m_manager.getObject<T>(name, m_expRun);
67 }
68
69 protected:
71 virtual void prepare() {}
73 virtual void collect() {}
75 virtual void startRun() {}
77 virtual void closeRun() {}
79 virtual void finish() {}
81 virtual void inDefineHisto() {}
82
84 TDirectory* m_dir;
85
88
91
93 Calibration::ExpRun m_expRun;
94
97
98 private:
99 /****** Module Parameters *******/
101 std::string m_granularity;
106 /********************************/
107
111 bool m_runCollectOnRun = true;
115 std::map<Calibration::ExpRun, int> m_expRunEvents;
123 {
124 if (m_preScale == 1.) {
125 return true;
126 } else if (m_preScale == 0.) {
127 return false;
128 } else {
129 const double randomNumber = gRandom->Uniform();
130 return randomNumber < m_preScale;
131 }
132 }
133 };
135} // Belle2 namespace
Manager class for collector registered data. Handles much of the TDirectory/TObject manipulation.
T * getObject(const std::string &name, const Belle2::Calibration::ExpRun expRun)
Gets the collector object of this name for the given exprun.
Calibration collector module base class.
bool m_runCollectOnRun
Whether or not we will run the collect() at all this run, basically skips the event() function if fal...
virtual void startRun()
Replacement for beginRun(). Do anything you would normally do in beginRun here.
Calibration::ExpRun m_expRun
Current ExpRun for object retrieval (becomes -1,-1 for granularity=all)
void registerObject(std::string name, T *obj)
Register object with a name, takes ownership, do not access the pointer beyond prepare()
CalibObjManager m_manager
Controls the creation, collection and access to calibration objects.
void endRun() final
Write the current collector objects to a file and clear their memory.
std::string m_granularity
Granularity of data collection = run|all(= no granularity, exp,run=-1,-1)
void initialize() final
Set up a default RunRange object in datastore and call prepare()
void beginRun() final
Reset the m_runCollectOnRun flag, if necessary, to begin collection again.
void event() final
Check current experiment and run and update if needed, fill into RunRange and collect()
RunRange * m_runRange
Overall list of runs processed.
virtual void prepare()
Replacement for initialize(). Register calibration dataobjects here as well.
TDirectory * m_dir
The top TDirectory that collector objects for this collector will be stored beneath.
virtual void closeRun()
Replacement for endRun(). Do anything you would normally do in endRun here.
StoreObjPtr< EventMetaData > m_evtMetaData
Required input for EventMetaData.
float m_preScale
Prescale module parameter, this fraction of events will have collect() run on them [0....
virtual void inDefineHisto()
Replacement for defineHisto(). Do anything you would normally do in defineHisto here.
void defineHisto() final
Runs due to HistoManager, allows us to discover the correct file.
int * m_eventsCollectedInRun
Will point at correct value in m_expRunEvents.
virtual void collect()
Replacement for event(). Fill you calibration data objects here.
virtual void finish()
Replacement for terminate(). Do anything you would normally do in terminate here.
StoreObjPtr< EventMetaData > m_emd
Current EventMetaData.
int m_maxEventsPerRun
Maximum number of events to be collected at the start of each run (-1 = no maximum)
CalibrationCollectorModule()
Constructor. Sets the default prefix for calibration dataobjects.
void terminate() final
Write the final objects to the file.
virtual ~CalibrationCollectorModule()
Virtual destructor (base class)
bool getPreScaleChoice()
I'm a little worried about floating point precision when comparing to 0.0 and 1.0 as special values.
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...
T * getObjectPtr(std::string name)
Calls the CalibObjManager to get the requested stored collector data.
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
Definition: HistoModule.h:29
Mergeable object holding (unique) set of (exp,run) pairs.
Definition: RunRange.h:25
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
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.
Abstract base class for different kinds of events.
STL namespace.