QwAnalysis
VQwSubsystem.h
Go to the documentation of this file.
1 /*!
2  * \file VQwSubsystem.h
3  * \brief Definition of the pure virtual base class of all subsystems
4  *
5  * \author P. M. King
6  * \date 2007-05-08 15:40
7  */
8 
9 #ifndef __VQWSUBSYSTEM__
10 #define __VQWSUBSYSTEM__
11 
12 // System headers
13 #include <iostream>
14 #include <vector>
15 
16 // ROOT headers
17 #include "Rtypes.h"
18 #include "TString.h"
19 #include "TDirectory.h"
20 #include "TTree.h"
21 
22 // Qweak headers
23 #include "MQwHistograms.h"
24 // Note: the factory header is included here because every subsystem
25 // has to register itself with a subsystem factory.
26 #include "QwFactory.h"
27 
28 // Forward declarations
29 class VQwHardwareChannel;
30 class QwSubsystemArray;
31 class QwParameterFile;
32 
33 
34 /**
35  * \class VQwSubsystem
36  * \ingroup QwAnalysis
37  * \brief The pure virtual base class of all subsystems
38  *
39  * Virtual base class for the classes containing the event-based
40  * information from each tracking subsystem and the parity analysis.
41  * The subclasses VQwSubsystemTracking and VQwSubsystemParity are base
42  * classes for the classes containing the event-based information
43  * from each tracking subsystem and parity analysis, respectively.
44  *
45  * \dot
46  * digraph example {
47  * node [shape=box, fontname=Helvetica, fontsize=10];
48  * VQwSubsystem [ label="VQwSubsystem" URL="\ref VQwSubsystem"];
49  * VQwSubsystemParity [ label="VQwSubsystemParity" URL="\ref VQwSubsystemParity"];
50  * VQwSubsystemTracking [ label="VQwSubsystemTracking" URL="\ref VQwSubsystemTracking"];
51  * VQwSubsystem -> VQwSubsystemParity;
52  * VQwSubsystem -> VQwSubsystemTracking;
53  * }
54  * \enddot
55  *
56  * This will define the interfaces used in communicating with the
57  * CODA routines.
58  */
59 class VQwSubsystem: virtual public VQwSubsystemCloneable, public MQwHistograms {
60 
61  public:
62 
63  /// Constructor with name
64  VQwSubsystem(const TString& name)
65  : MQwHistograms(),
66  fSystemName(name), fEventTypeMask(0x0), fIsDataLoaded(kFALSE),
69  }
70  /// Copy constructor by object
72  : MQwHistograms(orig),
79  fROC_IDs(orig.fROC_IDs),
80  fBank_IDs(orig.fBank_IDs)
81  { }
82 
83  /// Default destructor
84  virtual ~VQwSubsystem() { }
85 
86 
87  /// \brief Define options function (note: no virtual static functions in C++)
88  static void DefineOptions() { /* No default options defined */ };
89  /// Process the command line options
90  virtual void ProcessOptions(QwOptions &options) { };
91 
92 
93  TString GetSubsystemName() const {return fSystemName;};
94  Bool_t HasDataLoaded() const {return fIsDataLoaded;}
95 
96  /// \brief Set the parent of this subsystem to the specified array
97  void SetParent(QwSubsystemArray* parent);
98  /// \brief Get the parent of this subsystem
99  QwSubsystemArray* GetParent(const unsigned int parent = 0) const;
100  /// \brief Get the sibling with specified name
101  VQwSubsystem* GetSibling(const std::string& name) const;
102 
103 
104  public:
105 
106  /// \brief Publish a variable name to the parent subsystem array
107  Bool_t PublishInternalValue(const TString& name, const TString& desc, const VQwHardwareChannel* value) const;
108  /// \brief Publish all variables of the subsystem
109  virtual Bool_t PublishInternalValues() const {
110  return kTRUE; // when not implemented, this returns success
111  };
112  /// \brief Try to publish an internal variable matching the submitted name
113  virtual Bool_t PublishByRequest(TString device_name){
114  return kFALSE; // when not implemented, this returns failure
115  };
116 
117  /// \brief Request a named value which is owned by an external subsystem;
118  /// the request will be handled by the parent subsystem array
119  Bool_t RequestExternalValue(const TString& name, VQwHardwareChannel* value) const;
120 
121  /// \brief Return a pointer to a varialbe to the parent subsystem array to be
122  /// delivered to a different subsystem.
123 
124  virtual const VQwHardwareChannel* ReturnInternalValue(const TString& name) const{
125  std::cout << " VQwHardwareChannel::ReturnInternalValue for value name, " << name.Data()
126  << " define the routine in the respective subsystem to process this! " <<std::endl;
127  return 0;
128  };
129 
130  /// \brief Return a named value to the parent subsystem array to be
131  /// delivered to a different subsystem.
132  virtual Bool_t ReturnInternalValue(const TString& name,
133  VQwHardwareChannel* value) const {
134  return kFALSE;
135  };
136 
137  virtual std::vector<TString> GetParamFileNameList();
138  virtual std::map<TString, TString> GetDetectorMaps();
139 
140  protected:
141  /// Map of published internal values
142  std::map<TString, VQwHardwareChannel*> fPublishedInternalValues;
143  /// List of parameters to be published (loaded at the channel map)
144  std::vector<std::vector<TString> > fPublishList;
145 
146  void UpdatePublishedValue(const TString& name, VQwHardwareChannel* data_channel) {
147  fPublishedInternalValues[name] = data_channel;
148  };
149 
150  public:
151 
152  /// \brief Parse parameter file to find the map files
153  virtual Int_t LoadDetectorMaps(QwParameterFile& file);
154  /// Mandatory map file definition
155  virtual Int_t LoadChannelMap(TString mapfile) = 0;
156  /// Mandatory parameter file definition
157  virtual Int_t LoadInputParameters(TString mapfile) = 0;
158  /// Optional geometry definition
159  virtual Int_t LoadGeometryDefinition(TString mapfile) { return 0; };
160  /// Optional crosstalk definition
161  virtual Int_t LoadCrosstalkDefinition(TString mapfile) { return 0; };
162  /// Optional event cut file
163  virtual Int_t LoadEventCuts(TString mapfile) { return 0; };
164 
165  /// Set event type mask
166  void SetEventTypeMask(const UInt_t mask) { fEventTypeMask = mask; };
167  /// Get event type mask
168  UInt_t GetEventTypeMask() const { return fEventTypeMask; };
169 
170 
171  virtual void ClearEventData() = 0;
172 
173  virtual Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words) = 0;
174 
175  virtual 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){
176  /// TODO: Subsystems should be changing their ProcessEvBuffer routines to take the event_type as the first
177  /// argument. But in the meantime, default to just calling the non-event-type-aware ProcessEvBuffer routine.
178  if (((0x1 << (event_type - 1)) & this->GetEventTypeMask()) == 0) return 0;
179  else return this->ProcessEvBuffer(roc_id, bank_id, buffer, num_words);
180  };
181  /// TODO: The non-event-type-aware ProcessEvBuffer routine should be replaced with the event-type-aware version.
182  virtual Int_t ProcessEvBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t* buffer, UInt_t num_words) = 0;
183 
184  virtual void ProcessEvent() = 0;
185  /*! \brief Request processed data from other subsystems for internal
186  * use in the second event processing stage. Not all derived
187  * classes will require data from other subsystems.
188  */
189  virtual void ExchangeProcessedData() { };
190  /*! \brief Process the event data again, including data from other
191  * subsystems. Not all derived classes will require
192  * a second stage of event data processing.
193  */
194  virtual void ProcessEvent_2() { };
195 
196 
197  /// \brief Perform actions at the end of the event loop
198  virtual void AtEndOfEventLoop(){QwDebug << fSystemName << " at end of event loop" << QwLog::endl;};
199 
200 
201  // Not all derived classes will have the following functions
202  virtual void RandomizeEventData(int helicity = 0, double time = 0.0) { };
203  virtual void EncodeEventData(std::vector<UInt_t> &buffer) { };
204 
205 
206  /// \name Histogram construction and maintenance
207  // @{
208  /// Construct the histograms for this subsystem
209  virtual void ConstructHistograms() {
210  TString tmpstr("");
211  ConstructHistograms((TDirectory*) NULL, tmpstr);
212  };
213  /// Construct the histograms for this subsystem in a folder
214  virtual void ConstructHistograms(TDirectory *folder) {
215  TString tmpstr("");
216  ConstructHistograms(folder, tmpstr);
217  };
218  /// Construct the histograms for this subsystem with a prefix
219  virtual void ConstructHistograms(TString &prefix) {
220  ConstructHistograms((TDirectory*) NULL, prefix);
221  };
222  /// \brief Construct the histograms for this subsystem in a folder with a prefix
223  virtual void ConstructHistograms(TDirectory *folder, TString &prefix) = 0;
224  /// \brief Fill the histograms for this subsystem
225  virtual void FillHistograms() = 0;
226  // @}
227 
228 
229  /// \name Tree and branch construction and maintenance
230  /// The methods should exist for all subsystems and are therefore defined
231  /// as pure virtual.
232  // @{
233  /// \brief Construct the branch and tree vector
234  virtual void ConstructBranchAndVector(TTree *tree, TString& prefix, std::vector<Double_t>& values) = 0;
235  /// \brief Construct the branch and tree vector
236  virtual void ConstructBranchAndVector(TTree *tree, std::vector<Double_t>& values) {
237  TString tmpstr("");
238  ConstructBranchAndVector(tree,tmpstr,values);
239  };
240  /// \brief Construct the branch and tree vector
241  virtual void ConstructBranch(TTree *tree, TString& prefix) = 0;
242  /// \brief Construct the branch and tree vector based on the trim file
243  virtual void ConstructBranch(TTree *tree, TString& prefix, QwParameterFile& trim_file) = 0;
244  /// \brief Fill the tree vector
245  virtual void FillTreeVector(std::vector<Double_t>& values) const = 0;
246  // @}
247 
248 
249 
250 
251  /// \name Expert tree construction and maintenance
252  /// These functions are not purely virtual, since not every subsystem is
253  /// expected to implement them. They are intended for expert output to
254  /// trees.
255  // @{
256  /// \brief Construct the tree for this subsystem
257  virtual void ConstructTree() {
258  TString tmpstr("");
259  ConstructTree((TDirectory*) NULL, tmpstr);
260  };
261  /// \brief Construct the tree for this subsystem in a folder
262  virtual void ConstructTree(TDirectory *folder) {
263  TString tmpstr("");
264  ConstructTree(folder, tmpstr);
265  };
266  /// \brief Construct the tree for this subsystem with a prefix
267  virtual void ConstructTree(TString &prefix) {
268  ConstructTree((TDirectory*) NULL, prefix);
269  };
270  /// \brief Construct the tree for this subsystem in a folder with a prefix
271  virtual void ConstructTree(TDirectory *folder, TString &prefix) { return; };
272  /// \brief Fill the tree for this subsystem
273  virtual void FillTree() { return; };
274  /// \brief Delete the tree for this subsystem
275  virtual void DeleteTree() { return; };
276  // @}
277 
278  /// \brief Print some information about the subsystem
279  virtual void PrintInfo() const;
280 
281  /// \brief Assignment
282  /// Note: Must be called at the beginning of all subsystems routine
283  /// call to operator=(VQwSubsystem *value) by VQwSubsystem::operator=(value)
284  virtual VQwSubsystem& operator=(VQwSubsystem *value);
285 
286 
287  virtual void PrintDetectorMaps(Bool_t status) const;
288 
289  protected:
290 
291  /*! \brief Clear all registration of ROC and Bank IDs for this subsystem
292  */
294 
295  /*! \brief Tell the object that it will decode data from this ROC and sub-bank
296  */
297  virtual Int_t RegisterROCNumber(const UInt_t roc_id, const UInt_t bank_id = 0);
298 
299  /*! \brief Tell the object that it will decode data from this sub-bank in the ROC currently open for registration
300  */
301  Int_t RegisterSubbank(const UInt_t bank_id);
302 
304  Int_t GetSubbankIndex(const UInt_t roc_id, const UInt_t bank_id) const;
305  void SetDataLoaded(Bool_t flag){fIsDataLoaded = flag;};
306 
307 
308 
309 
310  protected:
311  Int_t FindIndex(const std::vector<UInt_t> &myvec, const UInt_t value) const ;
312 
313  protected:
314 
315  TString fSystemName; ///< Name of this subsystem
316 
317  UInt_t fEventTypeMask; ///< Mask of event types
318 
319  Bool_t fIsDataLoaded; ///< Has this subsystem gotten data to be processed?
320 
321  std::vector<TString> fDetectorMapsNames;
322  std::map<TString, TString> fDetectorMaps;
323  protected:
324 
325  Int_t fCurrentROC_ID; ///< ROC ID that is currently being processed
326  Int_t fCurrentBank_ID; ///< Bank ID that is currently being processed
327 
328  /// Vector of ROC IDs associated with this subsystem
329  std::vector<UInt_t> fROC_IDs;
330  /// Vector of Bank IDs per ROC ID associated with this subsystem
331  std::vector< std::vector<UInt_t> > fBank_IDs;
332 
333  /// Vector of pointers to subsystem arrays that contain this subsystem
334  std::vector<QwSubsystemArray*> fArrays;
335 
336 
337  protected:
338 
339  // Comparison of type
340  Bool_t Compare(VQwSubsystem* source) {
341  return (typeid(*this) == typeid(*source));
342  }
343 
344  private:
345 
346  // Private constructor (not implemented, will throw linker error on use)
347  VQwSubsystem();
348 
349 }; // class VQwSubsystem
350 
351 
352 #endif // __VQWSUBSYSTEM__
Int_t GetSubbankIndex() const
Definition: VQwSubsystem.h:303
virtual void EncodeEventData(std::vector< UInt_t > &buffer)
Definition: VQwSubsystem.h:203
virtual void ConstructBranch(TTree *tree, TString &prefix)=0
Construct the branch and tree vector.
VQwSubsystem(const VQwSubsystem &orig)
Copy constructor by object.
Definition: VQwSubsystem.h:71
virtual 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)
Definition: VQwSubsystem.h:175
std::map< TString, TString > fDetectorMaps
Definition: VQwSubsystem.h:322
virtual void FillTreeVector(std::vector< Double_t > &values) const =0
Fill the tree vector.
VQwSubsystem * GetSibling(const std::string &name) const
Get the sibling with specified name.
virtual std::vector< TString > GetParamFileNameList()
void SetParent(QwSubsystemArray *parent)
Set the parent of this subsystem to the specified array.
virtual void ProcessOptions(QwOptions &options)
Process the command line options.
Definition: VQwSubsystem.h:90
virtual Bool_t PublishByRequest(TString device_name)
Try to publish an internal variable matching the submitted name.
Definition: VQwSubsystem.h:113
An options class.
Definition: QwOptions.h:133
std::vector< QwSubsystemArray * > fArrays
Vector of pointers to subsystem arrays that contain this subsystem.
Definition: VQwSubsystem.h:334
virtual Int_t LoadChannelMap(TString mapfile)=0
Mandatory map file definition.
class VQwCloneable< VQwSubsystem > VQwSubsystemCloneable
Mix-in factory functionality for subsystems.
Definition: QwFactory.h:219
virtual void RandomizeEventData(int helicity=0, double time=0.0)
Definition: VQwSubsystem.h:202
virtual void ProcessEvent_2()
Process the event data again, including data from other subsystems. Not all derived classes will requ...
Definition: VQwSubsystem.h:194
Bool_t HasDataLoaded() const
Definition: VQwSubsystem.h:94
virtual const VQwHardwareChannel * ReturnInternalValue(const TString &name) const
Return a pointer to a varialbe to the parent subsystem array to be delivered to a different subsystem...
Definition: VQwSubsystem.h:124
virtual Int_t LoadDetectorMaps(QwParameterFile &file)
Parse parameter file to find the map files.
Definition: VQwSubsystem.cc:37
virtual void ConstructHistograms(TDirectory *folder)
Construct the histograms for this subsystem in a folder.
Definition: VQwSubsystem.h:214
virtual void ConstructTree(TString &prefix)
Construct the tree for this subsystem with a prefix.
Definition: VQwSubsystem.h:267
virtual void ConstructTree(TDirectory *folder, TString &prefix)
Construct the tree for this subsystem in a folder with a prefix.
Definition: VQwSubsystem.h:271
virtual void ConstructHistograms()
Construct the histograms for this subsystem.
Definition: VQwSubsystem.h:209
UInt_t fEventTypeMask
Mask of event types.
Definition: VQwSubsystem.h:317
virtual std::map< TString, TString > GetDetectorMaps()
virtual Int_t LoadEventCuts(TString mapfile)
Optional event cut file.
Definition: VQwSubsystem.h:163
std::map< TString, VQwHardwareChannel * > fPublishedInternalValues
Map of published internal values.
Definition: VQwSubsystem.h:142
virtual Int_t LoadCrosstalkDefinition(TString mapfile)
Optional crosstalk definition.
Definition: VQwSubsystem.h:161
Int_t FindIndex(const std::vector< UInt_t > &myvec, const UInt_t value) const
virtual VQwSubsystem & operator=(VQwSubsystem *value)
Assignment Note: Must be called at the beginning of all subsystems routine call to operator=(VQwSubsy...
#define QwDebug
Predefined log drain for debugging output.
Definition: QwLog.h:60
virtual void ConstructBranchAndVector(TTree *tree, std::vector< Double_t > &values)
Construct the branch and tree vector.
Definition: VQwSubsystem.h:236
static void DefineOptions()
Define options function (note: no virtual static functions in C++)
Definition: VQwSubsystem.h:88
virtual void ConstructTree(TDirectory *folder)
Construct the tree for this subsystem in a folder.
Definition: VQwSubsystem.h:262
TString fSystemName
Name of this subsystem.
Definition: VQwSubsystem.h:315
void SetEventTypeMask(const UInt_t mask)
Set event type mask.
Definition: VQwSubsystem.h:166
virtual void FillHistograms()=0
Fill the histograms for this subsystem.
virtual void DeleteTree()
Delete the tree for this subsystem.
Definition: VQwSubsystem.h:275
virtual void PrintInfo() const
Print some information about the subsystem.
std::vector< std::vector< TString > > fPublishList
List of parameters to be published (loaded at the channel map)
Definition: VQwSubsystem.h:144
virtual void ProcessEvent()=0
The pure virtual base class of all subsystems.
Definition: VQwSubsystem.h:59
virtual Bool_t ReturnInternalValue(const TString &name, VQwHardwareChannel *value) const
Return a named value to the parent subsystem array to be delivered to a different subsystem...
Definition: VQwSubsystem.h:132
VQwSubsystem(const TString &name)
Constructor with name.
Definition: VQwSubsystem.h:64
std::vector< std::vector< UInt_t > > fBank_IDs
Vector of Bank IDs per ROC ID associated with this subsystem.
Definition: VQwSubsystem.h:331
virtual ~VQwSubsystem()
Default destructor.
Definition: VQwSubsystem.h:84
Int_t fCurrentROC_ID
ROC ID that is currently being processed.
Definition: VQwSubsystem.h:325
Int_t RegisterSubbank(const UInt_t bank_id)
Tell the object that it will decode data from this sub-bank in the ROC currently open for registratio...
virtual Int_t RegisterROCNumber(const UInt_t roc_id, const UInt_t bank_id=0)
Tell the object that it will decode data from this ROC and sub-bank.
virtual Int_t LoadGeometryDefinition(TString mapfile)
Optional geometry definition.
Definition: VQwSubsystem.h:159
virtual void ConstructBranchAndVector(TTree *tree, TString &prefix, std::vector< Double_t > &values)=0
Construct the branch and tree vector.
static std::ostream & endl(std::ostream &)
End of the line.
Definition: QwLog.cc:299
Bool_t Compare(VQwSubsystem *source)
Definition: VQwSubsystem.h:340
std::vector< UInt_t > fROC_IDs
Vector of ROC IDs associated with this subsystem.
Definition: VQwSubsystem.h:329
Bool_t RequestExternalValue(const TString &name, VQwHardwareChannel *value) const
Request a named value which is owned by an external subsystem; the request will be handled by the par...
void UpdatePublishedValue(const TString &name, VQwHardwareChannel *data_channel)
Definition: VQwSubsystem.h:146
QwSubsystemArray * GetParent(const unsigned int parent=0) const
Get the parent of this subsystem.
virtual void FillTree()
Fill the tree for this subsystem.
Definition: VQwSubsystem.h:273
Bool_t PublishInternalValue(const TString &name, const TString &desc, const VQwHardwareChannel *value) const
Publish a variable name to the parent subsystem array.
virtual void ConstructTree()
Construct the tree for this subsystem.
Definition: VQwSubsystem.h:257
std::vector< TString > fDetectorMapsNames
Definition: VQwSubsystem.h:321
virtual Int_t LoadInputParameters(TString mapfile)=0
Mandatory parameter file definition.
UInt_t GetEventTypeMask() const
Get event type mask.
Definition: VQwSubsystem.h:168
virtual Int_t ProcessConfigurationBuffer(const UInt_t roc_id, const UInt_t bank_id, UInt_t *buffer, UInt_t num_words)=0
virtual void ConstructHistograms(TString &prefix)
Construct the histograms for this subsystem with a prefix.
Definition: VQwSubsystem.h:219
Int_t fCurrentBank_ID
Bank ID that is currently being processed.
Definition: VQwSubsystem.h:326
Bool_t fIsDataLoaded
Has this subsystem gotten data to be processed?
Definition: VQwSubsystem.h:319
void ClearAllBankRegistrations()
Clear all registration of ROC and Bank IDs for this subsystem.
virtual void ExchangeProcessedData()
Request processed data from other subsystems for internal use in the second event processing stage...
Definition: VQwSubsystem.h:189
virtual Bool_t PublishInternalValues() const
Publish all variables of the subsystem.
Definition: VQwSubsystem.h:109
virtual void PrintDetectorMaps(Bool_t status) const
TString GetSubsystemName() const
Definition: VQwSubsystem.h:93
virtual void ClearEventData()=0
virtual void AtEndOfEventLoop()
Perform actions at the end of the event loop.
Definition: VQwSubsystem.h:198
void SetDataLoaded(Bool_t flag)
Definition: VQwSubsystem.h:305