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