00001 #ifndef PSEVT_SOURCE_H 00002 #define PSEVT_SOURCE_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: Source.h 7815 2014-03-09 07:47:26Z salnikov@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class Source. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 #include <string> 00017 #include <iosfwd> 00018 00019 //---------------------- 00020 // Base Class Headers -- 00021 //---------------------- 00022 00023 //------------------------------- 00024 // Collaborating Class Headers -- 00025 //------------------------------- 00026 #include "PSEvt/AliasMap.h" 00027 #include "pdsdata/xtc/BldInfo.hh" 00028 #include "pdsdata/xtc/DetInfo.hh" 00029 #include "pdsdata/xtc/ProcInfo.hh" 00030 00031 //------------------------------------ 00032 // Collaborating Class Declarations -- 00033 //------------------------------------ 00034 00035 // --------------------- 00036 // -- Class Interface -- 00037 // --------------------- 00038 00039 namespace PSEvt { 00040 00041 /** 00042 * @ingroup PSEvt 00043 * 00044 * @brief This class implements source matching for finding data 00045 * inside event. 00046 * 00047 * Event dictionary has to support location of the event data without 00048 * complete source address specification. This class provides facility 00049 * for matching the data source address against partially-specified 00050 * match. 00051 * 00052 * This software was developed for the LCLS project. If you use all or 00053 * part of it, please give an appropriate acknowledgment. 00054 * 00055 * @see Event 00056 * 00057 * @version \$Id: Source.h 7815 2014-03-09 07:47:26Z salnikov@SLAC.STANFORD.EDU $ 00058 * 00059 * @author Andrei Salnikov 00060 */ 00061 00062 class Source { 00063 public: 00064 00065 /** 00066 * @brief Helper class which provides logic for matching Source values to Src instances. 00067 * 00068 * This is an abstraction of the set of addresses. Having this set one can ask 00069 * questions like: 00070 * - does a specific address (Pds::Src instance) belong to the set (match() method). 00071 * - does other set (another SrcMatch instance) contains this set completely (so that 00072 * for example one could ask question like "will this set match cspad-only devices") 00073 * - check if this is a special "no-source" match (matching only data that do not come 00074 * from any device) 00075 * - check if this is "exact" match (matching only one specific device, or no-source) 00076 * 00077 * Internal representation of this object is Pds::Src instance with some special 00078 * bit patterns representing special cases. This representation may change if these 00079 * patterns become unavailable (if DAQ decides to use them for some purpose). 00080 */ 00081 class SrcMatch { 00082 public: 00083 00084 SrcMatch(const Pds::Src& src) : m_src(src) {} 00085 00086 /// Match source with Pds::Src object. 00087 bool match(const Pds::Src& src) const; 00088 00089 /// Returns true if set of addresses matched by this instance is 00090 /// contained entirely in the set of addresses matched by an argument. 00091 bool in(const SrcMatch& other) const; 00092 00093 /// Returns true if matches no-source only 00094 bool isNoSource() const { return m_src == Pds::Src(); } 00095 00096 /// Returns true if it is exact match, no-source is also exact. 00097 bool isExact() const; 00098 00099 /// Returns internal Src representation, this representation can be changed at any 00100 /// moment, client code should not rely on existence of this data. 00101 const Pds::Src& src() const { return m_src; } 00102 00103 private: 00104 Pds::Src m_src; 00105 }; 00106 00107 /// Special enum type to signify objects without source 00108 enum NoSource { 00109 null ///< Special constant to be used as argument for constructor 00110 }; 00111 00112 /** 00113 * @brief Make source which matches objects without source only. 00114 */ 00115 explicit Source(NoSource) 00116 : m_src() 00117 { 00118 } 00119 00120 /** 00121 * @brief Make source which matches any source. 00122 * 00123 * This object will match any source. 00124 */ 00125 Source(); 00126 00127 /** 00128 * @brief Exact match for source. 00129 * 00130 * This object will match fully-specified source. Note that Source(Pds::Src()) 00131 * is equivalent to Source(null). 00132 */ 00133 explicit Source(const Pds::Src& src); 00134 00135 /** 00136 * @brief Exact match for DetInfo source. 00137 * 00138 * This object will match fully-specified DetInfo source. 00139 */ 00140 Source(Pds::DetInfo::Detector det, uint32_t detId, Pds::DetInfo::Device dev, uint32_t devId); 00141 00142 /** 00143 * @brief Exact match for BldInfo. 00144 * 00145 * This object will match fully-specified BldInfo source. 00146 */ 00147 explicit Source(Pds::BldInfo::Type type); 00148 00149 /** 00150 * @brief Matching specified via string. 00151 * 00152 * Argument string can be either alias name or match string in one of these formats: 00153 * "" - match anything 00154 * "DetInfo(det.detId:dev.devId)" - fully or partially specified DetInfo 00155 * "det.detId:dev.devId" - same as above 00156 * "DetInfo(det-detId|dev.devId)" - same as above 00157 * "det-detId|dev.devId" - same as above 00158 * "BldInfo(type)" - fully specified BldInfo 00159 * "type" - same as above 00160 * "BldInfo()" - any BldInfo 00161 * "ProcInfo(ipAddr)" - fully specified ProcInfo 00162 * "ProcInfo()" - any ProcInfo 00163 */ 00164 explicit Source(const std::string& spec); 00165 00166 /** 00167 * @brief Assign a string specification. 00168 */ 00169 Source& operator=(const std::string& spec); 00170 00171 /** 00172 * @brief Returns object which can be used to match Src instances. 00173 * 00174 * If Source instance was constructed from a string then this method tries to 00175 * resolve string as an alias. If alias is not found then it tries to parse 00176 * the string according to the definitions above. If parsing fails then exception 00177 * is thrown. 00178 * 00179 * @param[in] amap Alias map instance. 00180 * 00181 * @throw PSEvt::ExceptionSourceFormat if string cannot be parsed 00182 */ 00183 SrcMatch srcMatch(const AliasMap& amap) const; 00184 00185 /// Format Source contents. 00186 void print(std::ostream& out) const; 00187 00188 protected: 00189 00190 private: 00191 00192 Pds::Src m_src; 00193 std::string m_str; 00194 00195 }; 00196 00197 /// Helper operator to format Source to a standard stream 00198 inline std::ostream& 00199 operator<<(std::ostream& out, const Source& src) 00200 { 00201 src.print(out); 00202 return out; 00203 } 00204 00205 } // namespace PSEvt 00206 00207 #endif // PSEVT_SOURCE_H