PSEvt/src/EventKey.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 // File and Version Information:
00003 //      $Id: EventKey.cpp 7525 2014-01-13 19:52:29Z salnikov@SLAC.STANFORD.EDU $
00004 //
00005 // Description:
00006 //      Class EventKey...
00007 //
00008 // Author List:
00009 //      Andrei Salnikov
00010 //
00011 //------------------------------------------------------------------------
00012 
00013 //-----------------------
00014 // This Class's Header --
00015 //-----------------------
00016 #include "PSEvt/EventKey.h"
00017 #include "PSEvt/TypeInfoUtils.h"
00018  
00019 //-----------------
00020 // C/C++ Headers --
00021 //-----------------
00022 #include <iostream>
00023 #include <cxxabi.h>
00024 #include <stdlib.h>
00025 
00026 //-------------------------------
00027 // Collaborating Class Headers --
00028 //-------------------------------
00029 #include "pdsdata/xtc/BldInfo.hh"
00030 #include "pdsdata/xtc/DetInfo.hh"
00031 #include "pdsdata/xtc/ProcInfo.hh"
00032 
00033 //-----------------------------------------------------------------------
00034 // Local Macros, Typedefs, Structures, Unions and Forward Declarations --
00035 //-----------------------------------------------------------------------
00036 
00037 namespace {
00038 
00039 
00040   void printDetInfo(std::ostream& str, const Pds::DetInfo& src)
00041   {
00042     str << "DetInfo(";
00043     if (src.detector() == 0xff) {
00044       str << '*';
00045     } else {
00046       str << Pds::DetInfo::name(src.detector());
00047     }
00048     str << '.';
00049     if (src.detId() == 0xff) {
00050       str << '*';
00051     } else {
00052       str << src.detId();
00053     }
00054     str << ':';
00055     if (src.device() == 0xff) {
00056       str << '*';
00057     } else {
00058       str << Pds::DetInfo::name(src.device());
00059     }
00060     str << '.';
00061     if (src.devId() == 0xff) {
00062       str << '*';
00063     } else {
00064       str << src.devId();
00065     }
00066     str << ')';
00067   }
00068 
00069   void printBldInfo(std::ostream& str, const Pds::BldInfo& src)
00070   {
00071     str << "BldInfo(";
00072     if (unsigned(src.type()) != 0xffffffff) str << Pds::BldInfo::name(src);
00073     str << ')';
00074   }
00075 
00076   void printProcInfo(std::ostream& str, const Pds::ProcInfo& src)
00077   {
00078     uint32_t ip = src.ipAddr();
00079     str << "ProcInfo(" 
00080         << ((ip>>24)&0xff) 
00081         << '.' << ((ip>>16)&0xff)
00082         << '.' << ((ip>>8)&0xff) 
00083         << '.' << (ip&0xff) 
00084         << ", pid=" << src.processId() 
00085         << ')';
00086   }
00087 
00088   void print(std::ostream& str, const Pds::Src& src)
00089   {
00090     if (src.level() == Pds::Level::Source) {
00091       printDetInfo(str, static_cast<const Pds::DetInfo&>(src));
00092     } else if (src.level() == Pds::Level::Reporter) {
00093       printBldInfo(str, static_cast<const Pds::BldInfo&>(src));
00094     } else if (src.level() == Pds::Level::NumberOfLevels) {
00095       // special match-anything source, empty string
00096     } else {
00097       printProcInfo(str, static_cast<const Pds::ProcInfo&>(src));
00098     }
00099   }
00100   
00101   void print(std::ostream& str, const std::type_info* typeinfo)
00102   {
00103     str << PSEvt::TypeInfoUtils::typeInfoRealName(typeinfo);
00104   }
00105 
00106 }
00107 
00108 
00109 //              ----------------------------------------
00110 //              -- Public Function Member Definitions --
00111 //              ----------------------------------------
00112 
00113 namespace PSEvt {
00114 
00115 bool 
00116 EventKey::operator<(const EventKey& other) const 
00117 {
00118   int src_diff = PSEvt::cmpPdsSrc(this->m_src, other.m_src);
00119   if (src_diff<0) return true;
00120   if (src_diff>0) return false;
00121   if( TypeInfoUtils::lessTypeInfoPtr()(m_typeinfo, other.m_typeinfo) ) return true;
00122   if( TypeInfoUtils::lessTypeInfoPtr()(other.m_typeinfo, m_typeinfo) ) return false;
00123   if (m_key < other.m_key) return true;
00124   return false;
00125 }
00126 
00127 
00128 // format the key
00129 void 
00130 EventKey::print(std::ostream& str) const
00131 {
00132   str << "EventKey(type=";
00133   ::print(str, m_typeinfo);
00134   if (m_src == anySource()) {
00135     str << ", src=AnySource";
00136   } else if (validSrc()) {
00137     str << ", src=";
00138     ::print(str, m_src);
00139   }
00140   if (not m_alias.empty()) {
00141     str << ", alias=\"" << m_alias << "\"";
00142   }
00143   if (not m_key.empty()) {
00144     str << ", key=" << m_key; 
00145   }
00146   str << ')';
00147 }
00148 
00149 // Compare two Src objects, ignores process ID.
00150 int cmpPdsSrc(const Pds::Src& lhs, const Pds::Src& rhs)
00151 {
00152   // ignore PID in comparison
00153   int diff = int(lhs.level()) - int(rhs.level());
00154   if (diff != 0) return diff;
00155   return int(lhs.phy()) - int(rhs.phy());
00156 }
00157 
00158 
00159 } // namespace PSEvt
00160 
00161 namespace Pds {
00162 // Helper method to format Pds::Src to a standard stream
00163 std::ostream&
00164 operator<<(std::ostream& out, const Pds::Src& src)
00165 {
00166   ::print(out, src);
00167   return out;
00168 }
00169 }

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7