otsdaq_components  v2_04_02
ROCStream.h
1 #ifndef _ots_ROCStream_h_
2 #define _ots_ROCStream_h_
3 
4 #include "otsdaq-components/DetectorConfiguration/ROCDACs.h"
5 #include "otsdaq/Macros/CoutMacros.h"
6 
7 #include <iostream>
8 #include <string>
9 
10 #include <tracemf.h>
11 
12 namespace ots
13 {
14 class ROCStream
15 {
16  public:
17  ROCStream(void)
18  : theDetectorID_("")
19  , theROCType_("")
20  , theROCStatus_("")
21  , theFEWROCAddress_(0)
22  , theROCMask_("")
23  , theROCTrimBits_("")
24  {
25  ;
26  }
27  virtual ~ROCStream(void) { ; }
28 
29  // Setters
30  void setDetectorID(const std::string& rocName) { theDetectorID_ = rocName; }
31  void setROCType(const std::string& rocType) { theROCType_ = rocType; }
32  void setROCStatus(bool rocStatus) { theROCStatus_ = rocStatus; }
33  void setFEWROCAddress(unsigned int fecROCAddress)
34  {
35  theFEWROCAddress_ = fecROCAddress;
36  }
37  void setROCDACs(const ROCDACs& rocDACs) { theROCDACs_ = rocDACs; }
38  void addDAC(std::string name, unsigned int address, unsigned int value)
39  {
40  theROCDACs_.setDAC(name, address, value);
41  }
42  void setROCMask(const std::string& rocMask);
43  void setROCTrimBits(const std::string& rocTrimBits) { theROCTrimBits_ = rocTrimBits; }
44 
45  // Getters
46  const std::string& getDetectorID(void) const { return theDetectorID_; }
47  const std::string& getROCType(void) const { return theROCType_; }
48  bool getROCStatus(void) const { return theROCStatus_; }
49  unsigned int getFEWROCAddress(void) const { return theFEWROCAddress_; }
50  const ROCDACs& getROCDACs(void) const { return theROCDACs_; }
51  const std::string& getROCMask(void) const { return theROCMask_; }
52  const std::string& getROCTrimBits(void) const { return theROCTrimBits_; }
53 
54  private:
55  std::string theDetectorID_;
56  std::string theROCType_;
57  bool theROCStatus_;
58  unsigned int theFEWROCAddress_;
59  ROCDACs theROCDACs_;
60  std::string theROCMask_;
61  std::string theROCTrimBits_;
62 };
63 }
64 
66 inline void ots::ROCStream::setROCMask(const std::string& rocMask)
67 {
68  // theROCMask_ = rocMask;
69  theROCMask_.clear();
70  int row = -1;
71  int col = -1;
72  bool openRow = false;
73  bool openCol = false;
74  for(unsigned int i = 0; i < rocMask.length(); i++)
75  if(rocMask[i] == '[')
76  if(!openRow)
77  {
78  openRow = true;
79  ++row;
80  }
81  else if(!openCol)
82  {
83  openCol = true;
84  ++col;
85  }
86  else
87  {
88  __SS__ << "Too many [ in bit mask configuration" << std::endl;
89  __COUT_ERR__ << "\n" << ss.str();
90  __SS_THROW__;
91  }
92  else if(rocMask[i] == ']')
93  if(openCol)
94  {
95  openCol = false;
96  --col;
97  }
98  else if(openRow)
99  {
100  openRow = false;
101  --row;
102  }
103  else
104  {
105  __SS__ << "Too many ] in bit mask configuration" << std::endl;
106  __COUT_ERR__ << "\n" << ss.str();
107  __SS_THROW__;
108  }
109  else if(rocMask[i] == '0' || rocMask[i] == '1')
110  theROCMask_ +=
111  rocMask[i]; // No matrix style mask ... needs to be changed //TODO
112  // std::cout << theROCMask_ << std::endl;
113 }
114 
115 #endif // ots_ROCStream_h