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