PSEvt/include/DamageMap.h

Go to the documentation of this file.
00001 #ifndef PSEVT_DAMAGEMAP_H
00002 #define PSEVT_DAMAGEMAP_H
00003 
00004 #include <map>
00005 #include <iostream>
00006 #include <vector>
00007 #include <utility>
00008 
00009 #include "pdsdata/xtc/Damage.hh"
00010 #include "PSEvt/EventKey.h"
00011 
00012 namespace PSEvt {
00013 
00014 /**
00015  *  @ingroup PSEvt
00016  *  
00017  *  @brief Class to map EventKeys to their xtc damage values, and to hold Src only damage
00018  *  
00019  *  If a Psana Input Module records damage during event processing, for objects placed 
00020  *  in either the EventStore or ConfigStore, the input module should place an instance of 
00021  *  DamageMap in the Event.  Any damage to objects placed into the Event or ConfigStore 
00022  *  should be added to the DamageMap with the same EventKey used to store the object in the 
00023  *  Event or ConfigStore.  Damage associated only with a Pds::Src value should also be placed
00024  *  in the DamageMap. Src damage should always contain the DroppedContribution bit.  If it
00025  *  is not present, the damage value is ignored.
00026  *
00027  *  Modules can then look for the DamageMap in the Event and find out if there was any
00028  *  damage for specific EventKey's, as well as find out if dropped contributions (src damage)
00029  *  were present. This kind of damage implies a split event.
00030  *
00031  *  This software was developed for the LCLS project.  If you use all or 
00032  *  part of it, please give an appropriate acknowledgment.
00033  *
00034  *  @see EventKey
00035  *
00036  *  @version \$Id:
00037  *
00038  *  @author David Schneider
00039  */
00040 
00041 class DamageMap {
00042 public:
00043   typedef std::map<PSEvt::EventKey, Pds::Damage> MapImpl;
00044   typedef MapImpl::iterator iterator;
00045   typedef MapImpl::const_iterator const_iterator;
00046 
00047   /**
00048    * @brief add damage to DamageMap.  Works the same as std::map::operator[]
00049    */
00050   Pds::Damage & operator[](const PSEvt::EventKey &eventKey) { return m_map[eventKey]; }
00051 
00052   iterator begin() { return m_map.begin(); }
00053   iterator end() {return m_map.end(); }
00054   /**
00055    * @brief finds damage in the DamageMap. Tries two keys if eventKey has key string.
00056    *
00057    * EventKey's have three componenents, type, Src and key, where key is a string that
00058    * users may create, typically for data derived from original data in the Psana Event store.  
00059    * If no damage has been recorded for the given key, and the given key includes a string 
00060    * component, find() will also look for damage associated with the corresponding EventKey 
00061    * where the string component is blank.
00062    *
00063    * @param[in] eventKey  EventKey to look up damage for
00064    * @return iterator to eventKey position in map. 
00065    */
00066   iterator find(const PSEvt::EventKey &eventKey);
00067 
00068   const_iterator begin() const { return m_map.begin(); }
00069   const_iterator end() const { return m_map.end(); }
00070   /**
00071    * @brief const version of find(), see documentation for find().
00072    */
00073   const_iterator find(const PSEvt::EventKey &eventKey) const;
00074   
00075   void addSrcDamage(Pds::Src src, Pds::Damage damage);
00076   bool splitEvent() const { return m_droppedContribs.size()>0; }
00077 
00078   /**
00079    * @brief returns a histogram of damage values in the DamageMap associated with EventKeys 
00080    *
00081    * distinct Damage values are mapped to their frequency within the DamageMap.  No reporting
00082    * is provided for Src damage - use getSrcDroppedContributions or splitEvent for this
00083    */
00084   std::map<uint32_t, int> damageCounts() const;
00085 
00086   /**
00087    * @brief returns the list of src only damage for the event.  
00088    *
00089    * All damage values will contain the DroppedContribution bit.
00090    */
00091   const std::vector<std::pair<Pds::Src,Pds::Damage> > & getSrcDroppedContributions() const { return m_droppedContribs; }
00092 
00093  private:
00094   MapImpl m_map;
00095   std::vector<std::pair<Pds::Src,Pds::Damage> > m_droppedContribs;
00096   
00097 };
00098    
00099 std::ostream & operator<<(std::ostream &, const DamageMap &);
00100 
00101 }; // namespace
00102 
00103 #endif
00104 

Generated on 19 Dec 2016 for PSANAclasses by  doxygen 1.4.7