QwAnalysis
QwSubsystemArray.h
Go to the documentation of this file.
1 /**********************************************************\
2 * File: QwSubsystemArray.h *
3 * *
4 * Author: P. M. King, Rakitha Beminiwattha *
5 * Time-stamp: <2008-07-22 15:50> *
6 \**********************************************************/
7 
8 #ifndef __QWSUBSYSTEMARRAY__
9 #define __QWSUBSYSTEMARRAY__
10 
11 #include <vector>
12 #include <map>
13 #include "Rtypes.h"
14 #include "TString.h"
15 #include "TDirectory.h"
16 #include "TTree.h"
17 
18 
19 #include <boost/shared_ptr.hpp>
20 #include <boost/mem_fn.hpp>
21 
22 // Qweak headers
23 #include "VQwSubsystem.h"
24 #include "QwOptions.h"
25 
26 // Forward declarations
27 class VQwHardwareChannel;
28 class QwParameterFile;
29 
30 ///
31 /// \ingroup QwAnalysis
32 class QwSubsystemArray: public std::vector<boost::shared_ptr<VQwSubsystem> > {
33  private:
34  typedef std::vector<boost::shared_ptr<VQwSubsystem> > SubsysPtrs;
35  public:
36  using SubsysPtrs::const_iterator;
37  using SubsysPtrs::iterator;
38  using SubsysPtrs::begin;
39  using SubsysPtrs::end;
40  using SubsysPtrs::size;
41  using SubsysPtrs::empty;
42 
43  typedef Bool_t (*CanContainFn)(VQwSubsystem*);
44 
45  private:
46 
47  /// Private default constructor
48  QwSubsystemArray(); // not implemented, will throw linker error on use
49 
50  public:
51 
52  /// \brief Constructor with options
53  QwSubsystemArray(QwOptions& options, CanContainFn myCanContain);
54  /// \brief Copy constructor by reference
55  QwSubsystemArray(const QwSubsystemArray& source);
56  /// \brief Virtual destructor
57  virtual ~QwSubsystemArray() { };
58 
59  /// \brief Set the internal record of the CODA run number
60  void SetCodaRunNumber(UInt_t runnum) { fCodaRunNumber = runnum; };
61  /// \brief Set the internal record of the CODA segment number
62  void SetCodaSegmentNumber(UInt_t segnum) { fCodaSegmentNumber = segnum; };
63  /// \brief Set the internal record of the CODA event number
64  void SetCodaEventNumber(UInt_t evtnum) { fCodaEventNumber = evtnum; };
65  /// \brief Set the internal record of the CODA event type
66  void SetCodaEventType(UInt_t evttype) { fCodaEventType = evttype; };
67  /// \brief Get the internal record of the CODA run number
68  UInt_t GetCodaRunNumber() const { return fCodaRunNumber; };
69  /// \brief Get the internal record of the CODA segment number
70  UInt_t GetCodaSegmentNumber() const { return fCodaSegmentNumber; };
71  /// \brief Get the internal record of the CODA event number
72  UInt_t GetCodaEventNumber() const { return fCodaEventNumber; };
73  /// \brief Get the internal record of the CODA event type
74  UInt_t GetCodaEventType() const { return fCodaEventType; };
75 
76  /// \brief Set the internal record of the CODA event number
77  void SetCleanParameters(Double_t cleanparameter[3])
78  {
79  fCleanParameter[0] = cleanparameter[0];
80  fCleanParameter[1] = cleanparameter[1];
81  fCleanParameter[2] = cleanparameter[2];
82  };
83 
84  /// \brief Set event type mask
85  void SetEventTypeMask(const UInt_t mask) { fEventTypeMask = mask; };
86  /// \brief Get event type mask
87  UInt_t GetEventTypeMask() const { return fEventTypeMask; };
88  /// \brief Update the event type mask from the subsystems
90  for (iterator subsys_iter = begin(); subsys_iter != end(); ++subsys_iter) {
91  VQwSubsystem* subsys = dynamic_cast<VQwSubsystem*>(subsys_iter->get());
92  fEventTypeMask |= subsys->GetEventTypeMask();
93  }
94  return fEventTypeMask;
95  };
96 
97 
98  /// \brief Set data loaded flag
99  void SetDataLoaded(const Bool_t flag) { fHasDataLoaded = flag; };
100  /// \brief Get data loaded flag
101  Bool_t HasDataLoaded() const { return fHasDataLoaded; };
102 
103  /// \brief Define configuration options for global array
104  static void DefineOptions(QwOptions &options);
105  /// \brief Process configuration options for the subsystem array itself
106  void ProcessOptionsToplevel(QwOptions &options);
107  /// \brief Process configuration options for all subsystems in the array
108  void ProcessOptionsSubsystems(QwOptions &options);
109  /// \brief Process configuration options (default behavior)
110  void ProcessOptions(QwOptions &options) { ProcessOptionsSubsystems(options); };
111 
112 
113  /// \brief Add the subsystem to this array
114  void push_back(VQwSubsystem* subsys);
115 
116  /// \brief Get the subsystem with the specified name
117  virtual VQwSubsystem* GetSubsystemByName(const TString& name);
118 
119  /// \brief Get the list of subsystems of the specified type
120  virtual std::vector<VQwSubsystem*> GetSubsystemByType(const std::string& type);
121 
122  //each of the methods below will call their counterpart method separately.
123 
124  void ClearEventData();
125 
126  /// \brief Process the event buffer for configuration events
127  Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id,
128  UInt_t *buffer, UInt_t num_words);
129 
130  /// \brief Process the event buffer for events
131  Int_t ProcessEvBuffer(const UInt_t event_type, const UInt_t roc_id,
132  const UInt_t bank_id, UInt_t *buffer,
133  UInt_t num_words);
134 
135  /// \brief Randomize the data in this event
136  void RandomizeEventData(int helicity = 0, double time = 0.0);
137 
138  /// \brief Encode the data in this event
139  void EncodeEventData(std::vector<UInt_t> &buffer);
140 
141  /// \brief Process the decoded data in this event
142  void ProcessEvent();
143 
144  /// \brief Perform actions at the end of the event loop
145  void AtEndOfEventLoop();
146 
147  public:
148 
149  /// \brief Retrieve the variable name from other subsystem arrays
150  Bool_t RequestExternalValue(const TString& name, VQwHardwareChannel* value) const;
151 
152  /// \brief Retrieve the variable name from subsystems in this subsystem array
153  const VQwHardwareChannel* ReturnInternalValue(const TString& name) const;
154 
155  /// \brief Retrieve the variable name from subsystems in this subsystem array
156  Bool_t ReturnInternalValue(const TString& name, VQwHardwareChannel* value) const;
157 
158  /// \brief Publish the value name with description from a subsystem in this array
159  Bool_t PublishInternalValue(
160  const TString name,
161  const TString desc,
162  const VQwSubsystem* subsys,
163  const VQwHardwareChannel* element);
164 
165  /// \brief List the published values and description in this subsystem array
166  void ListPublishedValues() const;
167 
168  /// \brief Print list of parameter files
169  void PrintParamFileList() const;
170 
171  /// \brief Get list of parameter files
172  TList* GetParamFileNameList(TString name) const;
173 
174  private:
175  /// \brief Try to publish an internal variable matching the submitted name
176  Bool_t PublishByRequest(TString device_name);
177 
178  /// \brief Retrieve the variable name from subsystems in this subsystem array
179  VQwHardwareChannel* ReturnInternalValueForFriends(const TString& name) const;
180 
181  /// Friend with regression class who needs write access to data
182  friend class QwRegression;
183 
184  /// Published values
185  std::map<TString, const VQwHardwareChannel*> fPublishedValuesDataElement;
186  std::map<TString, const VQwSubsystem*> fPublishedValuesSubsystem;
187  std::map<TString, TString> fPublishedValuesDescription;
188 
189 
190  public:
191 
192  /// \name Histogram construction and maintenance
193  // @{
194  /// Construct the histograms for this subsystem
196  ConstructHistograms((TDirectory*) NULL);
197  };
198  /// Construct the histograms for this subsystem in a folder
199  void ConstructHistograms(TDirectory *folder) {
200  TString prefix = "";
201  ConstructHistograms(folder, prefix);
202  };
203  /// \brief Construct the histograms for this subsystem in a folder with a prefix
204  void ConstructHistograms(TDirectory *folder, TString &prefix);
205  /// \brief Fill the histograms for this subsystem
206  void FillHistograms();
207  /// \brief Share the histograms with another subsystem
208  void ShareHistograms(const QwSubsystemArray& source);
209  // @}
210 
211 
212  /// \name Tree and vector construction and maintenance
213  // @{
214  /// Construct the tree and vector for this subsystem
215  void ConstructBranchAndVector(TTree *tree, std::vector <Double_t> &values) {
216  TString tmpstr("");
217  ConstructBranchAndVector(tree,tmpstr,values);
218  };
219  /// \brief Construct a branch and vector for this subsystem with a prefix
220  void ConstructBranchAndVector(TTree *tree, TString& prefix, std::vector <Double_t> &values);
221  /// \brief Construct a branch for this subsystem with a prefix
222  void ConstructBranch(TTree *tree, TString& prefix);
223  /// \brief Construct a branch for this subsystem with a prefix after tree leave trimming
224  void ConstructBranch(TTree *tree, TString& prefix, QwParameterFile& trim_file);
225  /// \brief Fill the vector for this subsystem
226  void FillTreeVector(std::vector<Double_t> &values) const;
227  // @}
228 
229 
230  /// \name Tree construction and maintenance
231  /// These functions are not purely virtual, since not every subsystem is
232  /// expected to implement them. They are intended for expert output to
233  /// trees.
234  // @{
235  /// Construct the tree for this subsystem
236  void ConstructTree() {
237  ConstructTree((TDirectory*) NULL);
238  };
239  /// Construct the tree for this subsystem in a folder
240  void ConstructTree(TDirectory *folder) {
241  TString prefix = "";
242  ConstructTree(folder, prefix);
243  };
244  /// \brief Construct the tree for this subsystem in a folder with a prefix
245  void ConstructTree(TDirectory *folder, TString &prefix);
246 
247  /// \brief Fill the tree for this subsystem
248  void FillTree();
249  /// \brief Delete the tree for this subsystem
250  void DeleteTree();
251  // @}
252 
253 
254  /// \brief Print some information about the subsystem
255  void PrintInfo() const;
256 
257  void push_back(boost::shared_ptr<VQwSubsystem> subsys);
258 
259  protected:
261 
262  protected:
263  size_t fTreeArrayIndex; //! Index of this data element in root tree
264 
265  protected:
266  UInt_t fCodaRunNumber; ///< CODA run number as provided by QwEventBuffer
267  UInt_t fCodaSegmentNumber; ///< CODA segment number as provided by QwEventBuffer
268  UInt_t fCodaEventNumber; ///< CODA event number as provided by QwEventBuffer
269  UInt_t fCodaEventType; ///< CODA event type as provided by QwEventBuffer
270 
271  Double_t fCleanParameter[3];
272  UInt_t fEventTypeMask; ///< Mask of event types
273  Bool_t fHasDataLoaded; ///< Has this array gotten data to be processed?
274 
275  protected:
276  /// Function to determine which subsystems we can accept
278 
279  /// Test whether this subsystem array can contain a particular subsystem
280  static Bool_t CanContain(VQwSubsystem* subsys) {
281  if (subsys == 0) {
282  QwError << "Zero pointer passed!" << QwLog::endl;
283  }
284  // should never occur
285  return kFALSE;
286  };
287 
288  private:
289  /// Filename of the global detector map
290  std::string fSubsystemsMapFile;
291  std::vector<std::string> fSubsystemsDisabledByName; ///< List of disabled types
292  std::vector<std::string> fSubsystemsDisabledByType; ///< List of disabled names
293 
294 
295 }; // class QwSubsystemArray
296 
297 
298 #endif // __QWSUBSYSTEMARRAY__
UInt_t GetCodaRunNumber() const
Get the internal record of the CODA run number.
std::map< TString, const VQwSubsystem * > fPublishedValuesSubsystem
static Bool_t CanContain(VQwSubsystem *subsys)
Test whether this subsystem array can contain a particular subsystem.
UInt_t fCodaRunNumber
Index of this data element in root tree.
std::map< TString, TString > fPublishedValuesDescription
const VQwHardwareChannel * ReturnInternalValue(const TString &name) const
Retrieve the variable name from subsystems in this subsystem array.
Definition of the pure virtual base class of all subsystems.
void ConstructHistograms()
Construct the histograms for this subsystem.
virtual VQwSubsystem * GetSubsystemByName(const TString &name)
Get the subsystem with the specified name.
UInt_t GetCodaSegmentNumber() const
Get the internal record of the CODA segment number.
An options class.
Definition: QwOptions.h:133
TList * GetParamFileNameList(TString name) const
Get list of parameter files.
QwSubsystemArray()
Private default constructor.
Int_t ProcessEvBuffer(const UInt_t event_type, const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for events.
Bool_t PublishInternalValue(const TString name, const TString desc, const VQwSubsystem *subsys, const VQwHardwareChannel *element)
Publish the value name with description from a subsystem in this array.
UInt_t GetEventTypeMask() const
Get event type mask.
void push_back(VQwSubsystem *subsys)
Add the subsystem to this array.
void SetCodaEventNumber(UInt_t evtnum)
Set the internal record of the CODA event number.
UInt_t GetCodaEventType() const
Get the internal record of the CODA event type.
UInt_t fCodaEventNumber
CODA event number as provided by QwEventBuffer.
Bool_t RequestExternalValue(const TString &name, VQwHardwareChannel *value) const
Retrieve the variable name from other subsystem arrays.
void PrintParamFileList() const
Print list of parameter files.
void PrintInfo() const
Print some information about the subsystem.
void ProcessOptions(QwOptions &options)
Process configuration options (default behavior)
void ConstructTree(TDirectory *folder)
Construct the tree for this subsystem in a folder.
void EncodeEventData(std::vector< UInt_t > &buffer)
Encode the data in this event.
UInt_t fCodaSegmentNumber
CODA segment number as provided by QwEventBuffer.
void SetCleanParameters(Double_t cleanparameter[3])
Set the internal record of the CODA event number.
std::map< TString, const VQwHardwareChannel * > fPublishedValuesDataElement
Published values.
void SetEventTypeMask(const UInt_t mask)
Set event type mask.
void SetDataLoaded(const Bool_t flag)
Set data loaded flag.
void SetCodaRunNumber(UInt_t runnum)
Set the internal record of the CODA run number.
std::string fSubsystemsMapFile
Filename of the global detector map.
std::vector< boost::shared_ptr< VQwSubsystem > > SubsysPtrs
void ConstructTree()
Construct the tree for this subsystem.
UInt_t fCodaEventType
CODA event type as provided by QwEventBuffer.
void AtEndOfEventLoop()
Perform actions at the end of the event loop.
void ProcessOptionsToplevel(QwOptions &options)
Process configuration options for the subsystem array itself.
void ListPublishedValues() const
List the published values and description in this subsystem array.
void ConstructBranchAndVector(TTree *tree, std::vector< Double_t > &values)
Construct the tree and vector for this subsystem.
void ConstructBranch(TTree *tree, TString &prefix)
Construct a branch for this subsystem with a prefix.
void FillHistograms()
Fill the histograms for this subsystem.
Bool_t fHasDataLoaded
Has this array gotten data to be processed?
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
virtual ~QwSubsystemArray()
Virtual destructor.
static void DefineOptions(QwOptions &options)
Define configuration options for global array.
UInt_t GetCodaEventNumber() const
Get the internal record of the CODA event number.
Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)
Process the event buffer for configuration events.
void FillTree()
Fill the tree for this subsystem.
void ShareHistograms(const QwSubsystemArray &source)
Share the histograms with another subsystem.
CanContainFn fnCanContain
Function to determine which subsystems we can accept.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
void ProcessOptionsSubsystems(QwOptions &options)
Process configuration options for all subsystems in the array.
Double_t fCleanParameter[3]
Bool_t HasDataLoaded() const
Get data loaded flag.
void ProcessEvent()
Process the decoded data in this event.
An options class which parses command line, config file and environment.
Bool_t PublishByRequest(TString device_name)
Try to publish an internal variable matching the submitted name.
std::vector< std::string > fSubsystemsDisabledByType
List of disabled names.
Bool_t(* CanContainFn)(VQwSubsystem *)
void LoadSubsystemsFromParameterFile(QwParameterFile &detectors)
std::vector< std::string > fSubsystemsDisabledByName
List of disabled types.
void SetCodaEventType(UInt_t evttype)
Set the internal record of the CODA event type.
VQwHardwareChannel * ReturnInternalValueForFriends(const TString &name) const
Retrieve the variable name from subsystems in this subsystem array.
UInt_t fEventTypeMask
Mask of event types.
void ConstructHistograms(TDirectory *folder)
Construct the histograms for this subsystem in a folder.
UInt_t GetEventTypeMask() const
Get event type mask.
Definition: VQwSubsystem.h:168
void SetCodaSegmentNumber(UInt_t segnum)
Set the internal record of the CODA segment number.
virtual std::vector< VQwSubsystem * > GetSubsystemByType(const std::string &type)
Get the list of subsystems of the specified type.
void DeleteTree()
Delete the tree for this subsystem.
void RandomizeEventData(int helicity=0, double time=0.0)
Randomize the data in this event.
UInt_t UpdateEventTypeMask()
Update the event type mask from the subsystems.
#define QwError
Predefined log drain for errors.
Definition: QwLog.h:40
void FillTreeVector(std::vector< Double_t > &values) const
Fill the vector for this subsystem.