PVGroup.h

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #ifndef PVGROUP_H
00009 #define PVGROUP_H
00010 
00011 
00012 #include <PVDataHolder.h>
00013 
00014 
00019 class MemberMap {
00020         typedef std::map<long, std::string> mapLongString;
00021 private:
00022         mapLongString           mapNameIndex;
00023         mapLongString::iterator pos;
00024         Helper helper;
00025 
00026 public:
00027     MemberMap(){};
00028    ~MemberMap(){};
00029 
00030 void  insert(int  a, std::string _Name)   {
00031     mapNameIndex.insert(std::make_pair(a, _Name));
00032 };
00033 
00034 std::string getPV (int  i) {
00035 
00036     pos = mapNameIndex.find(i);
00037     if (pos != mapNameIndex.end()) return    pos->second;
00038     cout <<  "Index " << i << " not found! Size of group vector is " << mapNameIndex.size() << endl;
00039     return "";
00040 };
00041 
00042 int   getIndex (std::string _Name) {
00043     char pvStripped[PVNAME_SIZE];
00044     helper.removeLeadingAndTrailingSpaces(_Name.c_str(), pvStripped);
00045     string Name=pvStripped;
00046 
00047     for (pos=mapNameIndex.begin(); pos != mapNameIndex.end(); ++pos) {
00048 
00049         if (pos->second==Name) {return pos->first;}
00050         // String searches such as s.find(s1) return string::npos on failure
00051         //else if ( (pos->second).find(Name)  != std::string::npos) return pos->first;
00052     }
00053     cout << "PV: " <<  Name << " IS NOT A MEMBER OF THIS LIST " << endl;
00054     return  -1;
00055 };
00056 };
00057 
00058 
00064 class PVGroup {
00065     friend class Connect;
00066     friend class CAFE;
00067                 //if HAVE_LIBQTXML
00068     friend class restorePVGroupXMLParser;
00069                 //endif
00070 private:
00071     PVDataHolder * pvdata;
00072     unsigned int   npv;
00073           char name [PVGROUP_PSEUDO_SIZE];
00074     int     statusGroup;
00075     unsigned int  groupHandle;
00076     bool isIndexOutOfRange (unsigned int  idx) {
00077         return (idx >= npv) ? true:false;
00078     };
00079     MemberMap memberMap;
00080 
00081 public:
00082      //Initialize 1st two to avoid compiler warning messages
00083          PVGroup(){npv=0; pvdata=NULL; statusGroup=ICAFE_NORMAL; groupHandle=0; strcpy(name,"");};
00084     ~PVGroup(){};
00085     MemberMap getMemberMap() const {return memberMap;};
00086     PVDataHolder * getPVData() const {return pvdata;};
00087     PVDataHolder   getPVData(unsigned int  idx) throw(std::out_of_range){
00088         if(isIndexOutOfRange(idx)) {
00089             std::ostringstream oss;
00090             oss << "Exception! Index " << idx <<
00091                     " to PVGroup.pvdata() is out of range. Valid range is from 0 to " << npv-1;
00092             throw std::out_of_range(oss.str());
00093         }
00094         return pvdata[idx];
00095     };
00096         void setHasAlarm(bool h){ for (unsigned int i=0; i<npv; ++i) {pvdata[i].setHasAlarm(h);} }
00097         void setHasTS(bool h){ for (unsigned int i=0; i<npv; ++i) {pvdata[i].setHasTS(h);} }
00098 
00099     unsigned int    getNPV() const {return npv;};
00100     string getNameAsString() const {return name;};
00101     const char * getName()   const {return (const char *) name;};
00102     int  getStatusGroup()    const {return statusGroup;};
00103     int  getGroupStatus()    const {return statusGroup;};
00104     unsigned int  getGroupHandle() const {return groupHandle;};
00105 
00106     int  PV2Index(std::string _pv)     const {return getMemberMap().getIndex(_pv);}
00107     string Index2PV(unsigned int _idx) const {return getMemberMap().getPV(_idx);}
00108 
00109     void setPVData(PVDataHolder * _pvdata) {
00110 
00111         //We do not need to make a deep copy
00112         /*
00113         for (unsigned int i=0; i<npv; ++i) {
00114             pvdata[i].alarmStatus=_pvdata[i].alarmStatus;
00115             pvdata[i].alarmSeverity=_pvdata[i].alarmSeverity;
00116             pvdata[i].status=_pvdata[i].status;
00117             pvdata[i].nelem=_pvdata[i].nelem;
00118             pvdata[i].size=_pvdata[i].size;
00119             pvdata[i].dataType=_pvdata[i].dataType;
00120             pvdata[i].dataTypeNative=_pvdata[i].dataTypeNative;
00121             pvdata[i].rule=_pvdata[i].rule;
00122             pvdata[i].beamEventNo=_pvdata[i].beamEventNo;
00123             pvdata[i].userNo=_pvdata[i].userNo;
00124             pvdata[i].ts.nsec=_pvdata[i].ts.nsec;
00125             pvdata[i].ts.secPastEpoch=_pvdata[i].ts.secPastEpoch;
00126             strcpy(pvdata[i].pv,_pvdata[i].pv);
00127             strcpy(pvdata[i].pvAlias,_pvdata[i].pvAlias);
00128             strcpy(pvdata[i].device,_pvdata[i].device);
00129             strcpy(pvdata[i].attrib,_pvdata[i].attrib);
00130         }
00131         */
00132 
00133         //Shallow copy will do
00134         pvdata=_pvdata;
00135     };
00136 
00137     void set(unsigned int  _npv) {npv=_npv;};
00138     void setName(const char * _name) {strcpy(name, _name);};
00139     void setName(string _name) {strcpy(name,_name.c_str());};
00140     void setStatusGroup(int  _sg) {statusGroup=_sg;}
00141 
00142 
00143     void show() {print(npv) ;}
00144     void showMax(unsigned int  npvToPrint){print(npvToPrint);}
00145     void showMaxMax(unsigned int  npvToPrint, unsigned int  maxNelemWF){
00146         print(npvToPrint, maxNelemWF);}
00147 
00148     void print() {print(npv) ;}
00149     void print(unsigned int  npvToPrint) {
00150         npvToPrint=min(npvToPrint,npv);
00151         std::cout << "------------ PVGroup Handle = " << groupHandle << " ------------ "<< std::endl;
00152         std::cout << "PVGROUP: " << name << " HAS " << npv << " MEMBERS " << std::endl;
00153         std::cout << "PRINTING THE REQUESTED " << npvToPrint << " MEMBERS " << std::endl;
00154         std::cout << "OVERALL STATUS OF GROUP REPORTS " << statusGroup << std::endl;
00155         if (statusGroup!=ICAFE_NORMAL) {
00156             CAFEStatus cstat; cstat.report(statusGroup);
00157         }
00158         for (unsigned int  i=0; i<npvToPrint; ++i) {
00159             pvdata[i].print();
00160         }
00161     }
00162     void print(unsigned int  npvToPrint, unsigned int  maxNelemWF) {
00163         npvToPrint=min(npvToPrint,npv);
00164         std::cout << "------------ PVGroup Handle = " << groupHandle << " ------------ "<< std::endl;
00165         std::cout << "PVGROUP: " << name << " HAS " << npv << " MEMBERS " << std::endl;
00166         std::cout << "PRINTING THE REQUESTED " << npvToPrint << " MEMBERS " << std::endl;
00167         std::cout << "OVERALL STATUS OF GROUP REPORTS " << statusGroup << std::endl;
00168         if (statusGroup!=ICAFE_NORMAL) {
00169             CAFEStatus cstat; cstat.report(statusGroup);
00170         }
00171         for (unsigned int  i=0; i<npvToPrint; ++i) {
00172             pvdata[i].print(min(maxNelemWF,pvdata[i].getNelem()));
00173         }
00174     }
00175 
00176     void printIfError() {
00177         unsigned int  npvToPrint=npv;
00178         bool iErrorFound=false;
00179         for (unsigned int  i=0; i<npvToPrint; ++i) {
00180             if (pvdata[i].getStatus() != ICAFE_NORMAL) {
00181                 if(!iErrorFound) {
00182                     std::cout << "PVGROUP: " << name << " HAS " << npv << " MEMBERS " << std::endl;
00183                     std::cout << "PRINTING PV TRANSACTIONS WITH ERRORS " << std::endl;
00184                     iErrorFound=true;
00185                 }
00186                 cout << "------------------------------------------------------------" << endl;
00187                 cout << "Element [" << i << "] of " << npv << " in group: " << name << endl;
00188                 pvdata[i].print();
00189             }
00190         }
00191     }
00192 };
00193 
00194 
00195 
00196 #endif //PVGROUP_H

Generated on 3 May 2017 for CAFE by  doxygen 1.6.1