AdcMultiChannelPlotter.h
Go to the documentation of this file.
1 // AdcMultiChannelPlotter.h
2 //
3 // AdcMultiChannelPlotter is an intermediate base for
4 // AdcChannelTool that implements viewMap by looping over
5 // channel ranges and calling the subclass method
6 // viewMapChannels with the data for the channels in that group.
7 //
8 // Each call includes a pad that the receiver is expected to fill.
9 // Plots with names derived from the template XXXName are
10 // produced from these pads. There is one pad for each channel group.
11 //
12 // In addition, this class provides the method viewSummary(ilev) which
13 // produces plots with names derived from XXXSummaryNames[ilev].
14 // The pads are filled by calls to the subclass method viewMapSummary
15 // for each channel range with again one pad for each channel group.
16 // Calls to viewSummary are made by the subclass. E.g it might create
17 // event-level plots from endEvent or job level plots from its dtor.
18 //
19 // Both channel ranges and range groups may be specified and the subclass
20 // calls are made for the ranges in each.
21 // The subclass provides the method viewMapChannels that is called with the
22 // channel data for
23 // each range in the range list and
24 // each range in each of the groups in the group list.
25 // Each range in the range list is drawn on a separate pad.
26 // If XXXOverlayGroups is true, there is one drawing pad per channel group.
27 // Otherwise, there is one for each range in each group.
28 // If no ranges or groups are specified, a separate plot is made for each channel.
29 //
30 // Each plot file shows up to NX*NY channels in a NY x NX array.
31 // The overall plot size is YSize pixels by XSize pixels or Root
32 // default (500 x 700?) if either is zero.
33 //
34 // Configuration (XXX is prefix supplied in ctor):
35 // LogLevel - Logging opt (0=none, 1=init only, 2=every call, ...)
36 // XXXChannelRanges - Channel ranges.
37 // XXXChannelGroups - Channel range groups.
38 // XXXOverlayGroups - Flag indicating if ranges in a group appear on the same pad.
39 // XXXDataView - Data view to plot ("" = top)
40 // XXXName - Name for the multi-plot file created for each call to view.
41 // XXXSummaryNames - Name for the multi-plot summary file
42 // XXXSizeX - XSize in pixels of the multi-plot file.
43 // XXXSizeY - YSize in pixels of the multi-plot file.
44 // XXXSplitX - NX
45 // XXXSplitY - NY
46 //
47 // To obtain summary plots, viewMap must called (view is no sufficient).
48 
49 #ifndef AdcMultiChannelPlotter_H
50 #define AdcMultiChannelPlotter_H
51 
53 #include "fhiclcpp/ParameterSet.h"
57 #include <set>
58 
60 class TPadManipulator;
61 
63 
64 public:
65 
66  using Name = std::string;
67  using NameVector = std::vector<Name>;
68  using Index = unsigned int;
69  using IndexVector = std::vector<Index>;
70  using IndexSet = std::set<Index>;
71  using AcdVector = std::vector<const AdcChannelData*>;
72  using ChannelRangeMap = std::map<Name, IndexRange>;
73  using ChannelGroupMap = std::map<Name, IndexRangeGroup>;
74 
75  // Base class for the description of one drawing pad.
76  class Pad {
77  public:
78  Name cgname; // Channel group name
79  NameVector crnames; // Ordered vector of channel range names
80  ChannelRangeMap crmap; // Channel range associated with each name
81  // Create a pad with no channel ranges.
82  Pad(Name a_cgname) : cgname(a_cgname) { }
83  };
84 
85  using PadVector = std::vector<Pad>;
86 
88 
89  ~AdcMultiChannelPlotter() override;
90 
91  // Loop over channels, create plots and call viewMapChannel to fill them.
92  // Return could includes data from those calls (not implemented) and does include
93  // multiChannelNChannel - # channels processed
94  // multiChannelNPlot - # plots produced
95  DataMap viewMap(const AdcChannelDataMap& acds) const override;
96 
97  // Loop over channels, create summary plots at level ilev and call viewMapSummary to fill them.
98  // Subclass calls this at appropriate levels.
99  void viewSummary(Index ilev) const;
100 
101  // Subclass provides this method to process the channels in one range from one call to view.
102  // If a data view has been specified, then there be zero, one or one data object for each channel.
103  // crn - Name for this set of channels
104  // acds - Data for the channels
105  // man - Pad to be filled with the plot for this channel.
106  // Subclass can use man.haveHistOrGraph() to see if it has previously filled the pad.
107  // ncr - # channel ranges in this plot
108  // icr - index of the channel ranges in this plot
109  virtual int viewMapChannels(Name crn, const AcdVector& acds, TPadManipulator& man, Index ncr, Index icr) const =0;
110 
111  // Subclass provides this method to process the channels in one range for a summary plot,
112  // i.e. combining data from preceding view calls.
113  // cgn - Name for the group holding the channel range
114  // crn - Name for the channel range
115  // acds - Data for the channels
116  // man - Pad to be filled with the plot for this channel.
117  // Subclass can use man.haveHistOrGraph() or icrn to see if it has previously filled the pad.
118  // ncr - # channel ranges in this plot
119  // icr - index of the channel ranges in this plot
120  virtual int viewMapSummary(Index ilev, Name cgn, Name crn, TPadManipulator& man, Index ncr, Index icr) const =0;
121 
122  // Provide read access to configuration.
123  Index getLogLevel() const { return m_LogLevel; }
124  Name getDataView() const { return m_PlotDataView; }
127  bool haveChannelRanges() const { return getChannelRangeNames().size(); }
128  bool haveChannelGroups() const { return getChannelGroupNames().size(); }
129  bool overlayGroups() const { return m_PlotOverlayGroups; }
130  Name getPlotName() const { return m_PlotName; }
132  if ( ilev >= m_PlotSummaryNames.size() ) return "";
133  return m_PlotSummaryNames[ilev];
134  }
135  Index getPlotSizeX() const { return m_PlotSizeX; }
136  Index getPlotSizeY() const { return m_PlotSizeY; }
137  Index getPlotSplitX() const { return m_PlotSplitX; }
138  Index getPlotSplitY() const { return m_PlotSplitY; }
139 
140  // Return the channel groups.
141  const IndexRangeGroup& getChannelGroup(Name cgn) const;
142 
143 private:
144 
145  // Configuration data.
157 
158  // Derived from configuration.
164 
165  // ADC string tools.
167 
168  // State data.
169  // run = run number from first call to view.
170  class BaseState {
172  public:
173  Index event =0;
174  void setRun(Index irun) { m_runs.clear(); m_runs.resize(1, irun); }
175  bool hasRun() const { return m_runs.size(); }
176  Index run() const { return hasRun() ? m_runs[0] : 0; }
177  IndexSet channels; // Channels for no ranges or groups
178  };
180 
181 protected:
182 
183  BaseState& getBaseState() const { return const_cast<BaseState&>(m_baseState); }
184 
185 };
186 
187 #endif
std::vector< Name > NameVector
Name getPlotSummaryName(Index ilev) const
unsigned int Index
std::string string
Definition: nybbler.cc:12
BaseState & getBaseState() const
std::map< Name, IndexRangeGroup > ChannelGroupMap
const NameVector & getChannelRangeNames() const
std::vector< Index > IndexVector
void viewSummary(Index ilev) const
AdcMultiChannelPlotter(const fhicl::ParameterSet &ps, Name prefix="Plot")
const IndexRangeGroup & getChannelGroup(Name cgn) const
DataMap viewMap(const AdcChannelDataMap &acds) const override
virtual int viewMapSummary(Index ilev, Name cgn, Name crn, TPadManipulator &man, Index ncr, Index icr) const =0
static constexpr double ps
Definition: Units.h:99
std::vector< Pad > PadVector
virtual int viewMapChannels(Name crn, const AcdVector &acds, TPadManipulator &man, Index ncr, Index icr) const =0
const NameVector & getChannelGroupNames() const
std::map< AdcChannel, AdcChannelData > AdcChannelDataMap
const AdcChannelStringTool * m_adcStringBuilder
std::map< Name, IndexRange > ChannelRangeMap
std::vector< const AdcChannelData * > AcdVector