PSEvt/include/EventKey.h

Go to the documentation of this file.
00001 #ifndef PSEVT_EVENTKEY_H
00002 #define PSEVT_EVENTKEY_H
00003 
00004 //--------------------------------------------------------------------------
00005 // File and Version Information:
00006 //      $Id: EventKey.h 7525 2014-01-13 19:52:29Z salnikov@SLAC.STANFORD.EDU $
00007 //
00008 // Description:
00009 //      Class EventKey.
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------
00014 // C/C++ Headers --
00015 //-----------------
00016 #include <string>
00017 #include <iosfwd>
00018 #include <typeinfo>
00019 
00020 //----------------------
00021 // Base Class Headers --
00022 //----------------------
00023 
00024 //-------------------------------
00025 // Collaborating Class Headers --
00026 //-------------------------------
00027 #include "pdsdata/xtc/Src.hh"
00028 #include "pdsdata/xtc/ProcInfo.hh"
00029 
00030 //------------------------------------
00031 // Collaborating Class Declarations --
00032 //------------------------------------
00033 
00034 //              ---------------------
00035 //              -- Class Interface --
00036 //              ---------------------
00037 
00038 namespace PSEvt {
00039 
00040 /**
00041  *  @ingroup PSEvt
00042  *  
00043  *  @brief Class describing an address or key of the data object in event.
00044  *  
00045  *  Event key consists of three components - object type represented by 
00046  *  its typeinfo pointer, data source address, and string key. 
00047  *
00048  *  This software was developed for the LCLS project.  If you use all or 
00049  *  part of it, please give an appropriate acknowledgment.
00050  *
00051  *  @see Event
00052  *
00053  *  @version \$Id: EventKey.h 7525 2014-01-13 19:52:29Z salnikov@SLAC.STANFORD.EDU $
00054  *
00055  *  @author Andy Salnikov
00056  */
00057 
00058 class EventKey {
00059 public:
00060 
00061   /**
00062    *  @brief Constructor for EventKey.
00063    *  
00064    *  @param[in] typeinfo    Pointer to typeinfo object
00065    *  @param[in] src         Data source address
00066    *  @param[in] key         String key
00067    *  @param[in] alias       Alias name
00068    */
00069   EventKey (const std::type_info* typeinfo, const Pds::Src& src, const std::string& key,
00070       const std::string& alias=std::string())
00071     : m_typeinfo(typeinfo), m_src(src), m_key(key), m_alias(alias)
00072   {}
00073 
00074   /// default constructor
00075   EventKey() {};
00076 
00077   // Destructor
00078   ~EventKey () {}
00079 
00080   /// Returns special source address which is used for no-source data
00081   static Pds::Src noSource() { return Pds::Src(); }
00082 
00083   /// Returns special source address which is used for proxies that can serve
00084   /// any source address
00085   static Pds::Src anySource() { return Pds::ProcInfo(Pds::Level::NumberOfLevels, 0, 0); }
00086 
00087   /// Compare two keys
00088   bool operator<(const EventKey& other) const;
00089 
00090   /// Format the key
00091   void print(std::ostream& str) const;
00092 
00093   /// Returns pointer to typeinfo object
00094   const std::type_info* typeinfo() const {return m_typeinfo;}
00095   
00096   /// Returns data source address
00097   const Pds::Src& src() const {return m_src;}
00098   
00099   /// Returns string key
00100   const std::string& key() const {return m_key;}
00101   
00102   /// Returns alias name
00103   const std::string& alias() const {return m_alias;}
00104 
00105   /// Returns true if data source address is a valid address.
00106   bool validSrc() const { return not (m_src == Pds::Src()); }
00107   
00108 protected:
00109 
00110 private:
00111 
00112   // Data members
00113   const std::type_info* m_typeinfo; ///< Pointer to typeinfo object
00114   Pds::Src m_src;             ///< Data source address
00115   std::string m_key;          ///< String key
00116   std::string m_alias;        ///< Optional alias name
00117 
00118 };
00119 
00120 inline
00121 std::ostream&
00122 operator<<(std::ostream& out, const EventKey& key) {
00123   key.print(out);
00124   return out;
00125 }
00126 
00127 /**
00128  *   @brief Compare two Src objects, ignores process ID.
00129  *   
00130  *   When we specify source in psana we do not know or care about process ID,
00131  *   this is why we have to ignore it when we search for matching source.
00132  *   
00133  *   @return Negative number if lhs is lower than rhs, 0 if they are the same,
00134  *           positive number otherwise.
00135  */
00136 int cmpPdsSrc(const Pds::Src& lhs, const Pds::Src& rhs);
00137 
00138 } // namespace PSEvt
00139 
00140 namespace Pds {
00141 /// Helper operator to format Pds::Src to a standard stream
00142 std::ostream&
00143 operator<<(std::ostream& out, const Pds::Src& src);
00144 }
00145 
00146 #endif // PSEVT_EVENTKEY_H

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7