| [a3427f] | 1 | /*
 | 
|---|
 | 2 |  * FragmentationResultContainer.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Mar 8, 2013
 | 
|---|
 | 5 |  *      Author: heber
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef FRAGMENTATIONRESULTCONTAINER_HPP_
 | 
|---|
 | 9 | #define FRAGMENTATIONRESULTCONTAINER_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
 | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
| [55e1bc] | 16 | #include <boost/serialization/access.hpp>
 | 
|---|
| [a2a2f7] | 17 | #include <boost/serialization/map.hpp>
 | 
|---|
 | 18 | #include <boost/serialization/split_member.hpp>
 | 
|---|
 | 19 | #include <boost/serialization/version.hpp>
 | 
|---|
| [a3427f] | 20 | #include "CodePatterns/Singleton.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
| [55e1bc] | 22 | #include <boost/filesystem/path.hpp>
 | 
|---|
| [a3427f] | 23 | #include <map>
 | 
|---|
 | 24 | 
 | 
|---|
| [d20ded] | 25 | #include "CodePatterns/Observer/Observable.hpp"
 | 
|---|
 | 26 | 
 | 
|---|
| [a3427f] | 27 | #ifdef HAVE_JOBMARKET
 | 
|---|
 | 28 | #include "JobMarket/types.hpp"
 | 
|---|
 | 29 | #else
 | 
|---|
 | 30 | typedef size_t JobId_t;
 | 
|---|
 | 31 | #endif
 | 
|---|
 | 32 | 
 | 
|---|
| [ea63cb] | 33 | #include "Fragmentation/EdgesPerFragment.hpp"
 | 
|---|
| [a3427f] | 34 | #include "Fragmentation/KeySetsContainer.hpp"
 | 
|---|
| [c8d13f5] | 35 | #include "Fragmentation/Summation/IndexSet.hpp"
 | 
|---|
 | 36 | #include "Fragmentation/Summation/Containers/FragmentationShortRangeResults.hpp"
 | 
|---|
| [a3427f] | 37 | #include "Fragmentation/Summation/Containers/MPQCData.hpp"
 | 
|---|
| [c8d13f5] | 38 | #include "Fragmentation/Summation/Containers/MPQCDataMap.hpp"
 | 
|---|
| [18ed8c] | 39 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 40 | #include "Fragmentation/Summation/Containers/VMGData.hpp"
 | 
|---|
 | 41 | #endif
 | 
|---|
 | 42 | 
 | 
|---|
 | 43 | /** This class stores results from lengthy fragmentation calculations, e.g.
 | 
|---|
 | 44 |  * coming out of FragmentationAutomationAction.
 | 
|---|
 | 45 |  *
 | 
|---|
 | 46 |  * The idea is that we can play around with results without having to recalculate
 | 
|---|
| [55e1bc] | 47 |  * results in between. Hence, we place results into this container which we may
 | 
|---|
 | 48 |  * full serialize.
 | 
|---|
| [a3427f] | 49 |  */
 | 
|---|
| [d20ded] | 50 | class FragmentationResultContainer :
 | 
|---|
 | 51 |     public Singleton<FragmentationResultContainer>,
 | 
|---|
 | 52 |     public Observable
 | 
|---|
| [a3427f] | 53 | {
 | 
|---|
 | 54 |   //!> Singleton patterns needs access to private cstor/dtor.
 | 
|---|
 | 55 |   friend class Singleton<FragmentationResultContainer>;
 | 
|---|
 | 56 | private:
 | 
|---|
 | 57 |   FragmentationResultContainer() :
 | 
|---|
| [d20ded] | 58 |     Observable("FragmentationResultContainer"),
 | 
|---|
| [a3427f] | 59 |     ResultsType(BothRanges)
 | 
|---|
 | 60 |   {}
 | 
|---|
 | 61 |   ~FragmentationResultContainer() {}
 | 
|---|
 | 62 | 
 | 
|---|
 | 63 | public:
 | 
|---|
 | 64 |   //!> typedef for short range data container
 | 
|---|
 | 65 |   typedef std::map<JobId_t, MPQCData> shortrangedata_t;
 | 
|---|
| [ea63cb] | 66 |   //!> use FragmentJobQueue's typedef here
 | 
|---|
 | 67 |   typedef FragmentationEdges::edges_per_fragment_t edges_per_fragment_t;
 | 
|---|
| [18ed8c] | 68 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 69 |   //!> typedef for long range data container
 | 
|---|
 | 70 |   typedef std::map<JobId_t, VMGData> longrangedata_t;
 | 
|---|
 | 71 | #endif
 | 
|---|
 | 72 | 
 | 
|---|
| [18ed8c] | 73 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 74 |   /** Adds a a set of both short and long range results.
 | 
|---|
 | 75 |    *
 | 
|---|
 | 76 |    * Adds all the containers to the ones present in this instance.
 | 
|---|
 | 77 |    *
 | 
|---|
 | 78 |    * \param _keysets
 | 
|---|
| [adb51ab] | 79 |    * \param _forcekeysetskeysets
 | 
|---|
| [ea63cb] | 80 |    * \param _edges_per_fragment
 | 
|---|
| [a3427f] | 81 |    * \param _shortrangedata
 | 
|---|
 | 82 |    * \param _longrangedata
 | 
|---|
 | 83 |    */
 | 
|---|
 | 84 |   void addFullResults(
 | 
|---|
 | 85 |       const KeySetsContainer &_keysets,
 | 
|---|
 | 86 |       const KeySetsContainer &_forcekeysets,
 | 
|---|
| [ea63cb] | 87 |       const edges_per_fragment_t &_edges_per_fragment,
 | 
|---|
| [a3427f] | 88 |       const shortrangedata_t &_shortrangedata,
 | 
|---|
 | 89 |       const longrangedata_t &_longrangedata
 | 
|---|
 | 90 |       );
 | 
|---|
 | 91 | #endif
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |   /** Adds a a set of short range results only.
 | 
|---|
 | 94 |    *
 | 
|---|
 | 95 |    * Adds all the containers to the ones present in this instance.
 | 
|---|
 | 96 |    *
 | 
|---|
 | 97 |    * \param _keysets
 | 
|---|
 | 98 |    * \param _forcekeysets
 | 
|---|
| [ea63cb] | 99 |    * \param _edges_per_fragment
 | 
|---|
| [a3427f] | 100 |    * \param _shortrangedata
 | 
|---|
 | 101 |    */
 | 
|---|
 | 102 |   void addShortRangeResults(
 | 
|---|
 | 103 |       const KeySetsContainer &_keysets,
 | 
|---|
 | 104 |       const KeySetsContainer &_forcekeysets,
 | 
|---|
| [ea63cb] | 105 |       const edges_per_fragment_t &_edges_per_fragment,
 | 
|---|
| [a3427f] | 106 |       const shortrangedata_t &_shortrangedata
 | 
|---|
 | 107 |       );
 | 
|---|
 | 108 | 
 | 
|---|
| [c8d13f5] | 109 |   /** Adds a a set of summed short range results.
 | 
|---|
 | 110 |    *
 | 
|---|
 | 111 |    * Adds all the containers to the ones present in this instance.
 | 
|---|
 | 112 |    *
 | 
|---|
 | 113 |    * \param _summedshortrange energy results per index set
 | 
|---|
 | 114 |    */
 | 
|---|
 | 115 |   void addShortRangeSummedResults(
 | 
|---|
 | 116 |       const FragmentationShortRangeResults::summedshortrange_t &_summedshortrange
 | 
|---|
 | 117 |       );
 | 
|---|
 | 118 | 
 | 
|---|
| [adb51ab] | 119 |   /** Adds given cycles to internal keyset list.
 | 
|---|
 | 120 |    *
 | 
|---|
 | 121 |    * \param _cycles keysets of cycles to add
 | 
|---|
 | 122 |    */
 | 
|---|
 | 123 |   void addCycles(const KeySetsContainer &_cycles)
 | 
|---|
 | 124 |   { cycles.insert(_cycles); }
 | 
|---|
 | 125 | 
 | 
|---|
| [a3427f] | 126 |   /** Clears all internal containers.
 | 
|---|
 | 127 |    *
 | 
|---|
 | 128 |    * \note Also resets ResultsType.
 | 
|---|
 | 129 |    */
 | 
|---|
 | 130 |   void clear()
 | 
|---|
 | 131 |   {
 | 
|---|
| [d20ded] | 132 |     OBSERVE;
 | 
|---|
| [a3427f] | 133 |     keysets.clear();
 | 
|---|
 | 134 |     forcekeysets.clear();
 | 
|---|
| [f83e26] | 135 |     cycles.clear();
 | 
|---|
| [a3427f] | 136 |     shortrangedata.clear();
 | 
|---|
| [c8d13f5] | 137 |     summedshortrange.clear();
 | 
|---|
| [ea63cb] | 138 |     edges_per_fragment.clear();
 | 
|---|
| [18ed8c] | 139 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 140 |     longrangedata.clear();
 | 
|---|
 | 141 | #endif
 | 
|---|
 | 142 |     ResultsType = BothRanges;
 | 
|---|
 | 143 |   }
 | 
|---|
 | 144 | 
 | 
|---|
 | 145 |   const KeySetsContainer &getKeySets() const { return keysets; }
 | 
|---|
| [adb51ab] | 146 |   const KeySetsContainer &getCycles() const { return cycles; }
 | 
|---|
| [a3427f] | 147 |   const KeySetsContainer &getForceKeySets() const  { return forcekeysets; }
 | 
|---|
 | 148 |   const shortrangedata_t& getShortRangeResults() const  { return shortrangedata; }
 | 
|---|
| [ea63cb] | 149 |   const FragmentationShortRangeResults::summedshortrange_t& getShortRangeSummedResults() const
 | 
|---|
 | 150 |   { return summedshortrange; }
 | 
|---|
 | 151 |   const edges_per_fragment_t& getEdgesPerFragment() const
 | 
|---|
 | 152 |   { return edges_per_fragment; }
 | 
|---|
| [18ed8c] | 153 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 154 |   const longrangedata_t& getLongRangeResults() const;
 | 
|---|
 | 155 | #endif
 | 
|---|
 | 156 |   bool areFullRangeResultsPresent() const { return (ResultsType == BothRanges); }
 | 
|---|
 | 157 | 
 | 
|---|
 | 158 | private:
 | 
|---|
 | 159 |   //!> indicates whether we contain short range only or both results
 | 
|---|
 | 160 |   enum ResultsType_t {
 | 
|---|
 | 161 |     ShortRangeOnly,
 | 
|---|
 | 162 |     BothRanges,
 | 
|---|
 | 163 |   } ResultsType;
 | 
|---|
 | 164 | 
 | 
|---|
 | 165 |   //!> container for all KeySet's without hydrogens to the jobs
 | 
|---|
 | 166 |   KeySetsContainer keysets;
 | 
|---|
 | 167 |   //!> container for all KeySet's with all except saturation hydrogen to the jobs
 | 
|---|
 | 168 |   KeySetsContainer forcekeysets;
 | 
|---|
 | 169 |   //!> container for all short-range results
 | 
|---|
 | 170 |   std::map<JobId_t, MPQCData> shortrangedata;
 | 
|---|
| [adb51ab] | 171 |   //! container of all cycle keysets
 | 
|---|
 | 172 |   KeySetsContainer cycles;
 | 
|---|
| [c8d13f5] | 173 |   //!> container for summed up results per index set
 | 
|---|
 | 174 |   FragmentationShortRangeResults::summedshortrange_t summedshortrange;
 | 
|---|
| [ea63cb] | 175 |   //!> container for the edge set per index set (starting at 0)
 | 
|---|
 | 176 |   edges_per_fragment_t edges_per_fragment;
 | 
|---|
| [a3427f] | 177 | 
 | 
|---|
| [18ed8c] | 178 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a3427f] | 179 |   //!> container for all long-range results
 | 
|---|
 | 180 |   std::map<JobId_t, VMGData> longrangedata;
 | 
|---|
 | 181 | #endif
 | 
|---|
| [55e1bc] | 182 | 
 | 
|---|
 | 183 |   friend class boost::serialization::access;
 | 
|---|
 | 184 |   // serialization
 | 
|---|
 | 185 |   template <typename Archive>
 | 
|---|
| [a2a2f7] | 186 |   void load(Archive& ar, const unsigned int version)
 | 
|---|
 | 187 |   {
 | 
|---|
 | 188 |     OBSERVE;
 | 
|---|
 | 189 |     ar & ResultsType;
 | 
|---|
 | 190 |     ar & keysets;
 | 
|---|
 | 191 |     ar & forcekeysets;
 | 
|---|
 | 192 |     ar & shortrangedata;
 | 
|---|
 | 193 |     if (version > 0)
 | 
|---|
 | 194 |       ar & cycles;
 | 
|---|
 | 195 |     if (version > 1)
 | 
|---|
 | 196 |       ar & summedshortrange;
 | 
|---|
| [ea63cb] | 197 |     if (version > 2)
 | 
|---|
 | 198 |       ar & edges_per_fragment;
 | 
|---|
| [18ed8c] | 199 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [a2a2f7] | 200 |     ar & longrangedata;
 | 
|---|
 | 201 | #endif
 | 
|---|
 | 202 |   }
 | 
|---|
 | 203 |   template <typename Archive>
 | 
|---|
 | 204 |   void save(Archive& ar, const unsigned int version) const
 | 
|---|
| [55e1bc] | 205 |   {
 | 
|---|
 | 206 |     ar & ResultsType;
 | 
|---|
 | 207 |     ar & keysets;
 | 
|---|
 | 208 |     ar & forcekeysets;
 | 
|---|
 | 209 |     ar & shortrangedata;
 | 
|---|
| [adb51ab] | 210 |     if (version > 0)
 | 
|---|
 | 211 |       ar & cycles;
 | 
|---|
| [c8d13f5] | 212 |     if (version > 1)
 | 
|---|
 | 213 |       ar & summedshortrange;
 | 
|---|
| [ea63cb] | 214 |     if (version > 2)
 | 
|---|
 | 215 |       ar & edges_per_fragment;
 | 
|---|
| [18ed8c] | 216 | #if defined(HAVE_JOBMARKET) && defined(HAVE_VMG)
 | 
|---|
| [55e1bc] | 217 |     ar & longrangedata;
 | 
|---|
 | 218 | #endif
 | 
|---|
 | 219 |   }
 | 
|---|
| [a2a2f7] | 220 |   BOOST_SERIALIZATION_SPLIT_MEMBER()
 | 
|---|
| [a3427f] | 221 | };
 | 
|---|
 | 222 | 
 | 
|---|
| [adb51ab] | 223 | // version for serialized information associated to FragmentationResultContainer
 | 
|---|
| [ea63cb] | 224 | BOOST_CLASS_VERSION(FragmentationResultContainer, 3)
 | 
|---|
| [adb51ab] | 225 | 
 | 
|---|
| [a3427f] | 226 | #endif /* FRAGMENTATIONRESULTCONTAINER_HPP_ */
 | 
|---|