ChannelView.h
Go to the documentation of this file.
1 //File: ChannelView.h
2 //Brief: Interface for mapping some value in (module, channel) space to
3 // a concrete graphical object that is drawn in a TPad. Example implementation (derived)
4 // classes might include a simple wrapper over a TH2D and an overlaid
5 // pair of TH2Ds that draw channels as they relate in space. Derive
6 // from this abstract base class to use it.
7 //Author: Andrew Olivier aolivier@ur.rochester.edu
8 
9 #ifndef CRT_CHANNELVIEW_H
10 #define CRT_CHANNELVIEW_H
11 
12 //ROOT includes
13 #include "TPad.h"
14 
15 //c++ includes
16 #include <memory>
17 
18 namespace CRT
19 {
21  {
22  public:
23  ChannelView(); //Create my own TPad for this ChannelView
24  ChannelView(TPad* pad); //Use a TPad the user provides for all drawing. Might be useful if you want to divide a
25  //TPad for some GUI.
26 
27  virtual ~ChannelView();
28 
29  //Public interface. Private implementation below.
30  void Fill(const size_t module, const size_t channel, const double weight=1.0);
31  void SetValue(const size_t module, const size_t channel, const double value);
32  void Draw(const char* option);
33  void Reset(const char* option);
34 
35  protected:
36  //Implement the following methods in a base class to use this interface.
37  virtual void doFill(const size_t module, const size_t channel, const double weight) = 0; //Add a module-channel pair to histogram
38  virtual void doSetValue(const size_t module, const size_t channel, const double value) = 0; //Set histogram value for a module-channel
39  //pair. Lets histogram be used as a graph.
40  virtual void doDraw(const char* option) = 0; //Queue whatever graphical object(s) are doing the drawing to draw on next update.
41  virtual void doReset(const char* option) = 0; //Reset statistical contents of model that keeps track of bin values
42 
43  //Since I am planning to hard-code number of CRTs for now, put it all in one place so that I can maintain that decision in one place
44  static constexpr size_t NModules = 32;
45  static constexpr size_t ChannelsPerModule = 64;
46 
47  TPad* GetMainPad() { return fPad.get(); } //Provide derived classes with observer pointer access to fPad
48 
49  private:
50  template <class T>
51  struct MaybeDeleter
52  {
53  MaybeDeleter(const bool toDelete): fDeleteMe(toDelete) {}
54 
55  void operator ()(T* obj) const
56  {
57  if(fDeleteMe) delete obj;
58  }
59 
60  const bool fDeleteMe;
61  };
62 
63  //WARNING: I might not really own fPad below even though it is a unique_ptr. In one constructor, it will be
64  // constructed with the default deleter (and so owned). In the other constructor, it will be created
65  // with a no-op deleter (and so not owned).
66  std::unique_ptr<TPad, MaybeDeleter<TPad>> fPad;
67  };
68 }
69 
70 #endif //CRT_CHANNELVIEW_H
virtual ~ChannelView()
Definition: ChannelView.cpp:22
std::unique_ptr< TPad, MaybeDeleter< TPad > > fPad
Definition: ChannelView.h:66
void operator()(T *obj) const
Definition: ChannelView.h:55
uint8_t channel
Definition: CRTFragment.hh:201
MaybeDeleter(const bool toDelete)
Definition: ChannelView.h:53
weight
Definition: test.py:257
virtual void doDraw(const char *option)=0
TPad * GetMainPad()
Definition: ChannelView.h:47
virtual void doFill(const size_t module, const size_t channel, const double weight)=0
void Reset(const char *option)
Definition: ChannelView.cpp:44
static constexpr size_t ChannelsPerModule
Definition: ChannelView.h:45
void SetValue(const size_t module, const size_t channel, const double value)
Definition: ChannelView.cpp:32
static constexpr size_t NModules
Definition: ChannelView.h:44
virtual void doSetValue(const size_t module, const size_t channel, const double value)=0
virtual void doReset(const char *option)=0
void Draw(const char *option)
Definition: ChannelView.cpp:38
void Fill(const size_t module, const size_t channel, const double weight=1.0)
Definition: ChannelView.cpp:26