00001 #ifndef _ots_ROCStream_h_
00002 #define _ots_ROCStream_h_
00003
00004 #include "otsdaq-components/DetectorConfiguration/ROCDACs.h"
00005 #include "otsdaq-core/Macros/CoutMacros.h"
00006
00007 #include <string>
00008 #include <iostream>
00009
00010 namespace ots
00011 {
00012
00013 class ROCStream
00014 {
00015 public:
00016 ROCStream(void) :
00017 theDetectorID_ (""),
00018 theROCType_ (""),
00019 theROCStatus_ (""),
00020 theFEWROCAddress_(0),
00021 theROCMask_ (""),
00022 theROCTrimBits_ ("")
00023 {;}
00024 virtual ~ROCStream(void){;}
00025
00026
00027 void setDetectorID (const std::string& rocName ){theDetectorID_ = rocName;}
00028 void setROCType (const std::string& rocType ){theROCType_ = rocType;}
00029 void setROCStatus (bool rocStatus ){theROCStatus_ = rocStatus;}
00030 void setFEWROCAddress(unsigned int fecROCAddress ){theFEWROCAddress_ = fecROCAddress;}
00031 void setROCDACs (const ROCDACs& rocDACs ){theROCDACs_ = rocDACs;}
00032 void addDAC (std::string name, unsigned int address, unsigned int value){theROCDACs_.setDAC(name,address,value);}
00033 void setROCMask (const std::string& rocMask );
00034 void setROCTrimBits (const std::string& rocTrimBits){theROCTrimBits_ = rocTrimBits;}
00035
00036
00037 const std::string& getDetectorID (void) const {return theDetectorID_;}
00038 const std::string& getROCType (void) const {return theROCType_;}
00039 bool getROCStatus (void) const {return theROCStatus_;}
00040 unsigned int getFEWROCAddress(void) const {return theFEWROCAddress_;}
00041 const ROCDACs& getROCDACs (void) const {return theROCDACs_;}
00042 const std::string& getROCMask (void) const {return theROCMask_;}
00043 const std::string& getROCTrimBits (void) const {return theROCTrimBits_;}
00044
00045
00046
00047 private:
00048 std::string theDetectorID_;
00049 std::string theROCType_;
00050 bool theROCStatus_;
00051 unsigned int theFEWROCAddress_;
00052 ROCDACs theROCDACs_;
00053 std::string theROCMask_;
00054 std::string theROCTrimBits_;
00055 };
00056
00057 }
00058
00060 inline void ots::ROCStream::setROCMask(const std::string& rocMask)
00061 {
00062
00063 theROCMask_.clear();
00064 int row = -1;
00065 int col = -1;
00066 bool openRow = false;
00067 bool openCol = false;
00068 for(unsigned int i=0; i<rocMask.length(); i++)
00069 if(rocMask[i] == '[')
00070 if(!openRow)
00071 {
00072 openRow = true;
00073 ++row;
00074 }
00075 else if(!openCol)
00076 {
00077 openCol = true;
00078 ++col;
00079 }
00080 else
00081 {
00082 __SS__ << "Too many [ in bit mask configuration" << std::endl;
00083 __COUT_ERR__ << "\n" << ss.str();
00084 __SS_THROW__;
00085 }
00086 else if(rocMask[i] == ']')
00087 if(openCol)
00088 {
00089 openCol = false;
00090 --col;
00091 }
00092 else if(openRow)
00093 {
00094 openRow = false;
00095 --row;
00096 }
00097 else
00098 {
00099 __SS__ << "Too many ] in bit mask configuration" << std::endl;
00100 __COUT_ERR__ << "\n" << ss.str();
00101 __SS_THROW__;
00102 }
00103 else if(rocMask[i] == '0' || rocMask[i] == '1')
00104 theROCMask_ += rocMask[i];
00105
00106 }
00107
00108 #endif //ots_ROCStream_h