00001 #ifndef PSENV_EPICSSTOREIMPL_H
00002 #define PSENV_EPICSSTOREIMPL_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <string>
00017 #include <vector>
00018 #include <map>
00019 #include <boost/shared_ptr.hpp>
00020 #include <boost/utility.hpp>
00021 #include <tr1/tuple>
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "pdsdata/xtc/Src.hh"
00031 #include "psddl_psana/epics.ddl.h"
00032 #include "psddl_psana/EpicsLib.h"
00033 #include "PSEnv/Exceptions.h"
00034 #include "PSTime/Time.h"
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 namespace PSEnv {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 class EpicsStoreImpl {
00064 public:
00065
00066
00067 EpicsStoreImpl () ;
00068
00069
00070 ~EpicsStoreImpl () ;
00071
00072
00073 void store(const boost::shared_ptr<Psana::Epics::EpicsPvHeader>& pv, const Pds::Src& src, const std::string *pvName=NULL, long eventTag = -1);
00074
00075
00076 void storeAlias(const Pds::Src& src, int pvId, const std::string& alias);
00077
00078
00079 void names(std::vector<std::string>& names) const;
00080
00081
00082 void pvNames(std::vector<std::string>& names) const;
00083
00084
00085 void aliases(std::vector<std::string>& names) const;
00086
00087
00088 std::string alias(const std::string& pv) const;
00089
00090
00091 std::string pvName(const std::string& alias) const;
00092
00093
00094 template <typename T>
00095 boost::shared_ptr<T> getCtrl(const std::string& name) const {
00096 boost::shared_ptr<Psana::Epics::EpicsPvCtrlHeader> ptr = getCtrlImpl(name);
00097 return boost::dynamic_pointer_cast<T>(ptr);
00098 }
00099
00100
00101 template <typename T>
00102 boost::shared_ptr<T> getTime(const std::string& name) const {
00103 boost::shared_ptr<Psana::Epics::EpicsPvTimeHeader> ptr = getTimeImpl(name);
00104 return boost::dynamic_pointer_cast<T>(ptr);
00105 }
00106
00107
00108 struct TimeHeaderAndEventTag {
00109 boost::shared_ptr<Psana::Epics::EpicsPvTimeHeader> pv;
00110 long eventTag;
00111 TimeHeaderAndEventTag() : pv(), eventTag(-1) {};
00112 TimeHeaderAndEventTag(boost::shared_ptr<Psana::Epics::EpicsPvTimeHeader> _pv,
00113 long _eventTag) : pv(_pv), eventTag(_eventTag) {};
00114 };
00115
00116
00117
00118 TimeHeaderAndEventTag getTimeAndEventTag(const std::string& name) const;
00119
00120
00121 boost::shared_ptr<Psana::Epics::EpicsPvHeader> getAny(const std::string& name) const ;
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 void getStatus(const std::string& name, int& status, int& severity, PSTime::Time& time) const ;
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 template <typename T>
00146 T getValue(const std::string& name, unsigned idx=0) const
00147 {
00148 boost::shared_ptr<Psana::Epics::EpicsPvHeader> pv = getAny(name);
00149 if (not pv.get()) throw ExceptionEpicsName(ERR_LOC, name);
00150 try {
00151 return Psana::EpicsLib::getEpicsValue<T>(*pv, idx);
00152 } catch (const std::exception& ex) {
00153 throw ExceptionEpicsConversion(ERR_LOC, name, typeid(T), ex.what());
00154 }
00155 }
00156
00157 protected:
00158
00159
00160 boost::shared_ptr<Psana::Epics::EpicsPvCtrlHeader> getCtrlImpl(const std::string& name) const;
00161
00162
00163 boost::shared_ptr<Psana::Epics::EpicsPvTimeHeader> getTimeImpl(const std::string& name) const;
00164
00165 private:
00166
00167
00168 typedef std::tr1::tuple<uint32_t, uint32_t, int> PvId;
00169
00170
00171 typedef std::map<PvId, std::string> ID2Name;
00172
00173
00174 typedef std::map<std::string, PvId> Name2ID;
00175
00176
00177 typedef std::map<std::string, boost::shared_ptr<Psana::Epics::EpicsPvCtrlHeader> > CrtlMap;
00178
00179
00180 typedef std::map<std::string, TimeHeaderAndEventTag > TimeMap;
00181
00182
00183 ID2Name m_id2name;
00184 Name2ID m_name2id;
00185 ID2Name m_id2alias;
00186 Name2ID m_alias2id;
00187 CrtlMap m_ctrlMap;
00188 TimeMap m_timeMap;
00189
00190 };
00191
00192 }
00193
00194 #endif // PSENV_EPICSSTOREIMPL_H