| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Pierre Aubert | ||
| 3 | Mail : pierre.aubert@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #ifndef __REPRESENTATION_H__ | ||
| 8 | #define __REPRESENTATION_H__ | ||
| 9 | |||
| 10 | #include <string> | ||
| 11 | #include "phoenix_data_stream.h" | ||
| 12 | #include "phoenix_path_stream.h" | ||
| 13 | #include "PString.h" | ||
| 14 | #include "MessageType.h" | ||
| 15 | #include "swarm_core_namespace_def.h" | ||
| 16 | |||
| 17 | #include "phoenix_type_stream.h" | ||
| 18 | #include "phoenix_data_stream.h" | ||
| 19 | #include "phoenix_check_stream.h" | ||
| 20 | |||
| 21 | ///@brief Basic Data exchanged in the swarm | ||
| 22 | class Swarm::Data{ | ||
| 23 | public: | ||
| 24 | Data(); | ||
| 25 | virtual ~Data(); | ||
| 26 | Data(const Data & other); | ||
| 27 | Data & operator = (const Data & other); | ||
| 28 | void setName(const PString & name); | ||
| 29 | void setDescription(const PString & description); | ||
| 30 | void setType(const PString & type); | ||
| 31 | void setValue(const DataStreamMsg & value); | ||
| 32 | const PString & getName() const; | ||
| 33 | PString & getName(); | ||
| 34 | const PString & getDescription() const; | ||
| 35 | PString & getDescription(); | ||
| 36 | const PString & getType() const; | ||
| 37 | PString & getType(); | ||
| 38 | const DataStreamMsg & getValue() const; | ||
| 39 | DataStreamMsg & getValue(); | ||
| 40 | |||
| 41 | ///Load the current Data with a stream | ||
| 42 | /** @param[out] ds : stream to be used | ||
| 43 | * @return true on success, false otherwise | ||
| 44 | */ | ||
| 45 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 46 | 87 | bool readWriteStream(Stream & ds){ | |
| 47 | 87 | bool b(true); | |
| 48 | 87 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name); | |
| 49 | 87 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description); | |
| 50 | 87 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_type); | |
| 51 | 87 | b &= DataStream<Stream, Mode, DataStreamMsg >::data_stream(ds, p_value); | |
| 52 | 87 | return b; | |
| 53 | } | ||
| 54 | |||
| 55 | protected: | ||
| 56 | void copyData(const Data & other); | ||
| 57 | private: | ||
| 58 | void initialisationData(); | ||
| 59 | ///Name of the Data | ||
| 60 | PString p_name; | ||
| 61 | ///Description of the Data | ||
| 62 | PString p_description; | ||
| 63 | ///Type of the Data | ||
| 64 | PString p_type; | ||
| 65 | ///Value of the Data | ||
| 66 | DataStreamMsg p_value; | ||
| 67 | }; | ||
| 68 | |||
| 69 | template<> | ||
| 70 | std::string phoenix_getTypeName<Swarm::Data>(); | ||
| 71 | |||
| 72 | ///@brief Generic Data serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 73 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 74 | struct DataStream<Stream, Mode, Swarm::Data>{ | ||
| 75 | ///Generic function to load/save/serialise/deserialise Data | ||
| 76 | /** @param[out] ds : stream to be used | ||
| 77 | * @param data : Data to be used | ||
| 78 | * @return true on success, false otherwise | ||
| 79 | */ | ||
| 80 | 87 | static bool data_stream(Stream & ds, Swarm::Data & data){ | |
| 81 | 87 | return data.readWriteStream<Stream, Mode>(ds); | |
| 82 | } | ||
| 83 | }; | ||
| 84 | |||
| 85 | ///@brief Generic Data Check function | ||
| 86 | template<> | ||
| 87 | struct CheckStream<Swarm::Data>{ | ||
| 88 | static bool check_stream(const std::string & fieldDescription, const Swarm::Data & data, const Swarm::Data & reference, std::ostream & out); | ||
| 89 | }; | ||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | |||
| 94 | ///@brief Basic function which can be called from an other Daemon | ||
| 95 | class Swarm::Function{ | ||
| 96 | public: | ||
| 97 | Function(); | ||
| 98 | virtual ~Function(); | ||
| 99 | Function(const Function & other); | ||
| 100 | Function & operator = (const Function & other); | ||
| 101 | void setName(const PString & name); | ||
| 102 | void setDescription(const PString & description); | ||
| 103 | void setVecParam(const std::vector<Swarm::Data> & vecParam); | ||
| 104 | void setReturnValue(const Swarm::Data & returnValue); | ||
| 105 | const PString & getName() const; | ||
| 106 | PString & getName(); | ||
| 107 | const PString & getDescription() const; | ||
| 108 | PString & getDescription(); | ||
| 109 | const std::vector<Swarm::Data> & getVecParam() const; | ||
| 110 | std::vector<Swarm::Data> & getVecParam(); | ||
| 111 | const Swarm::Data & getReturnValue() const; | ||
| 112 | Swarm::Data & getReturnValue(); | ||
| 113 | |||
| 114 | ///Load the current Function with a stream | ||
| 115 | /** @param[out] ds : stream to be used | ||
| 116 | * @return true on success, false otherwise | ||
| 117 | */ | ||
| 118 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 119 | bool readWriteStream(Stream & ds){ | ||
| 120 | bool b(true); | ||
| 121 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name); | ||
| 122 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description); | ||
| 123 | b &= DataStream<Stream, Mode, std::vector<Swarm::Data> >::data_stream(ds, p_vecParam); | ||
| 124 | b &= DataStream<Stream, Mode, Swarm::Data >::data_stream(ds, p_returnValue); | ||
| 125 | return b; | ||
| 126 | } | ||
| 127 | |||
| 128 | protected: | ||
| 129 | void copyFunction(const Function & other); | ||
| 130 | private: | ||
| 131 | void initialisationFunction(); | ||
| 132 | ///Name of the Function | ||
| 133 | PString p_name; | ||
| 134 | ///Description of the Function | ||
| 135 | PString p_description; | ||
| 136 | ///Vector of parameters of the Function | ||
| 137 | std::vector<Swarm::Data> p_vecParam; | ||
| 138 | ///Return value of the Function | ||
| 139 | Swarm::Data p_returnValue; | ||
| 140 | }; | ||
| 141 | |||
| 142 | template<> | ||
| 143 | std::string phoenix_getTypeName<Swarm::Function>(); | ||
| 144 | |||
| 145 | ///@brief Generic Function serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 146 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 147 | struct DataStream<Stream, Mode, Swarm::Function>{ | ||
| 148 | ///Generic function to load/save/serialise/deserialise Function | ||
| 149 | /** @param[out] ds : stream to be used | ||
| 150 | * @param data : Function to be used | ||
| 151 | * @return true on success, false otherwise | ||
| 152 | */ | ||
| 153 | static bool data_stream(Stream & ds, Swarm::Function & data){ | ||
| 154 | return data.readWriteStream<Stream, Mode>(ds); | ||
| 155 | } | ||
| 156 | }; | ||
| 157 | |||
| 158 | ///@brief Generic Function Check function | ||
| 159 | template<> | ||
| 160 | struct CheckStream<Swarm::Function>{ | ||
| 161 | static bool check_stream(const std::string & fieldDescription, const Swarm::Function & data, const Swarm::Function & reference, std::ostream & out); | ||
| 162 | }; | ||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | ///@brief Message exchanged by Daemons | ||
| 168 | class Swarm::Message{ | ||
| 169 | public: | ||
| 170 | Message(); | ||
| 171 | virtual ~Message(); | ||
| 172 | Message(const Message & other); | ||
| 173 | Message & operator = (const Message & other); | ||
| 174 | void setSendTime(const time_t & sendTime); | ||
| 175 | void setId(size_t id); | ||
| 176 | void setIsConfirmationNeeded(bool isConfirmationNeeded); | ||
| 177 | void setSender(const PString & sender); | ||
| 178 | void setVecRecver(const std::vector<PString> & vecRecver); | ||
| 179 | void setType(const MessageType::MessageType & type); | ||
| 180 | void setData(const Swarm::Data & data); | ||
| 181 | const time_t & getSendTime() const; | ||
| 182 | time_t & getSendTime(); | ||
| 183 | size_t getId() const; | ||
| 184 | size_t & getId(); | ||
| 185 | bool getIsConfirmationNeeded() const; | ||
| 186 | bool & getIsConfirmationNeeded(); | ||
| 187 | const PString & getSender() const; | ||
| 188 | PString & getSender(); | ||
| 189 | const std::vector<PString> & getVecRecver() const; | ||
| 190 | std::vector<PString> & getVecRecver(); | ||
| 191 | const MessageType::MessageType & getType() const; | ||
| 192 | MessageType::MessageType & getType(); | ||
| 193 | const Swarm::Data & getData() const; | ||
| 194 | Swarm::Data & getData(); | ||
| 195 | |||
| 196 | ///Load the current Message with a stream | ||
| 197 | /** @param[out] ds : stream to be used | ||
| 198 | * @return true on success, false otherwise | ||
| 199 | */ | ||
| 200 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 201 | 87 | bool readWriteStream(Stream & ds){ | |
| 202 | 87 | bool b(true); | |
| 203 | 87 | b &= DataStream<Stream, Mode, time_t >::data_stream(ds, p_sendTime); | |
| 204 | 87 | b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_id); | |
| 205 | 87 | b &= DataStream<Stream, Mode, bool >::data_stream(ds, p_isConfirmationNeeded); | |
| 206 | 87 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_sender); | |
| 207 | 87 | b &= DataStream<Stream, Mode, std::vector<PString> >::data_stream(ds, p_vecRecver); | |
| 208 | 87 | b &= DataStream<Stream, Mode, MessageType::MessageType >::data_stream(ds, p_type); | |
| 209 | 87 | b &= DataStream<Stream, Mode, Swarm::Data >::data_stream(ds, p_data); | |
| 210 | 87 | return b; | |
| 211 | } | ||
| 212 | |||
| 213 | protected: | ||
| 214 | void copyMessage(const Message & other); | ||
| 215 | private: | ||
| 216 | void initialisationMessage(); | ||
| 217 | ///Time when the message was sent | ||
| 218 | time_t p_sendTime; | ||
| 219 | ///Id of the message (will be usefull to trigger method when a transmission is confirmed) | ||
| 220 | size_t p_id; | ||
| 221 | ///True if the MESSAGE_CONFIRMATION is needed | ||
| 222 | bool p_isConfirmationNeeded; | ||
| 223 | ///Address of the Daemon which sends the message | ||
| 224 | PString p_sender; | ||
| 225 | ///Addresses of Daemons which receive the message | ||
| 226 | std::vector<PString> p_vecRecver; | ||
| 227 | ///Type of the message | ||
| 228 | MessageType::MessageType p_type; | ||
| 229 | ///Data in the message | ||
| 230 | Swarm::Data p_data; | ||
| 231 | }; | ||
| 232 | |||
| 233 | template<> | ||
| 234 | std::string phoenix_getTypeName<Swarm::Message>(); | ||
| 235 | |||
| 236 | ///@brief Generic Message serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 237 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 238 | struct DataStream<Stream, Mode, Swarm::Message>{ | ||
| 239 | ///Generic function to load/save/serialise/deserialise Message | ||
| 240 | /** @param[out] ds : stream to be used | ||
| 241 | * @param data : Message to be used | ||
| 242 | * @return true on success, false otherwise | ||
| 243 | */ | ||
| 244 | 87 | static bool data_stream(Stream & ds, Swarm::Message & data){ | |
| 245 | 87 | return data.readWriteStream<Stream, Mode>(ds); | |
| 246 | } | ||
| 247 | }; | ||
| 248 | |||
| 249 | ///@brief Generic Message Check function | ||
| 250 | template<> | ||
| 251 | struct CheckStream<Swarm::Message>{ | ||
| 252 | static bool check_stream(const std::string & fieldDescription, const Swarm::Message & data, const Swarm::Message & reference, std::ostream & out); | ||
| 253 | }; | ||
| 254 | |||
| 255 | |||
| 256 | |||
| 257 | |||
| 258 | ///@brief General statistics in the swarm | ||
| 259 | class Swarm::VecStat{ | ||
| 260 | public: | ||
| 261 | VecStat(); | ||
| 262 | virtual ~VecStat(); | ||
| 263 | VecStat(const VecStat & other); | ||
| 264 | VecStat & operator = (const VecStat & other); | ||
| 265 | void setNbEvent(const std::vector<size_t> & nbEvent); | ||
| 266 | void setStartTimestamp(const std::vector<time_t> & startTimestamp); | ||
| 267 | void setEndTimestamp(const std::vector<time_t> & endTimestamp); | ||
| 268 | void setMin(const std::vector<float> & min); | ||
| 269 | void setMax(const std::vector<float> & max); | ||
| 270 | void setAverage(const std::vector<float> & average); | ||
| 271 | void setRate(const std::vector<float> & rate); | ||
| 272 | void setVecRateQuantile(const std::vector<std::vector<float> > & vecRateQuantile); | ||
| 273 | void setRateEventBelowLowerBound(const std::vector<float> & rateEventBelowLowerBound); | ||
| 274 | void setRateEventAboveUpperBound(const std::vector<float> & rateEventAboveUpperBound); | ||
| 275 | const std::vector<size_t> & getNbEvent() const; | ||
| 276 | std::vector<size_t> & getNbEvent(); | ||
| 277 | const std::vector<time_t> & getStartTimestamp() const; | ||
| 278 | std::vector<time_t> & getStartTimestamp(); | ||
| 279 | const std::vector<time_t> & getEndTimestamp() const; | ||
| 280 | std::vector<time_t> & getEndTimestamp(); | ||
| 281 | const std::vector<float> & getMin() const; | ||
| 282 | std::vector<float> & getMin(); | ||
| 283 | const std::vector<float> & getMax() const; | ||
| 284 | std::vector<float> & getMax(); | ||
| 285 | const std::vector<float> & getAverage() const; | ||
| 286 | std::vector<float> & getAverage(); | ||
| 287 | const std::vector<float> & getRate() const; | ||
| 288 | std::vector<float> & getRate(); | ||
| 289 | const std::vector<std::vector<float> > & getVecRateQuantile() const; | ||
| 290 | std::vector<std::vector<float> > & getVecRateQuantile(); | ||
| 291 | const std::vector<float> & getRateEventBelowLowerBound() const; | ||
| 292 | std::vector<float> & getRateEventBelowLowerBound(); | ||
| 293 | const std::vector<float> & getRateEventAboveUpperBound() const; | ||
| 294 | std::vector<float> & getRateEventAboveUpperBound(); | ||
| 295 | |||
| 296 | ///Load the current VecStat with a stream | ||
| 297 | /** @param[out] ds : stream to be used | ||
| 298 | * @return true on success, false otherwise | ||
| 299 | */ | ||
| 300 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 301 | 6 | bool readWriteStream(Stream & ds){ | |
| 302 | 6 | bool b(true); | |
| 303 | 6 | b &= DataStream<Stream, Mode, std::vector<size_t> >::data_stream(ds, p_nbEvent); | |
| 304 | 6 | b &= DataStream<Stream, Mode, std::vector<time_t> >::data_stream(ds, p_startTimestamp); | |
| 305 | 6 | b &= DataStream<Stream, Mode, std::vector<time_t> >::data_stream(ds, p_endTimestamp); | |
| 306 | 6 | b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_min); | |
| 307 | 6 | b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_max); | |
| 308 | 6 | b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_average); | |
| 309 | 6 | b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_rate); | |
| 310 | 6 | b &= DataStream<Stream, Mode, std::vector<std::vector<float> > >::data_stream(ds, p_vecRateQuantile); | |
| 311 | 6 | b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_rateEventBelowLowerBound); | |
| 312 | 6 | b &= DataStream<Stream, Mode, std::vector<float> >::data_stream(ds, p_rateEventAboveUpperBound); | |
| 313 | 6 | return b; | |
| 314 | } | ||
| 315 | |||
| 316 | protected: | ||
| 317 | void copyVecStat(const VecStat & other); | ||
| 318 | private: | ||
| 319 | void initialisationVecStat(); | ||
| 320 | ///Number of events used to make this statistic | ||
| 321 | std::vector<size_t> p_nbEvent; | ||
| 322 | ///Timestamp where this stat started to be accumulated by the clock of the current daemon (TODO: need unit) | ||
| 323 | std::vector<time_t> p_startTimestamp; | ||
| 324 | ///Timestamp where this stat was finished to be accumulated by the clock of the current daemon (TODO: need unit) | ||
| 325 | std::vector<time_t> p_endTimestamp; | ||
| 326 | ///Minimum value of the stat | ||
| 327 | std::vector<float> p_min; | ||
| 328 | ///Maximum value of the stat | ||
| 329 | std::vector<float> p_max; | ||
| 330 | ///Mean of the stat | ||
| 331 | std::vector<float> p_average; | ||
| 332 | ///Number of events per second | ||
| 333 | std::vector<float> p_rate; | ||
| 334 | ///Vector of binned event rate per quantile (quartile decile, etc) | ||
| 335 | std::vector<std::vector<float> > p_vecRateQuantile; | ||
| 336 | ///Number of events below the lower boundary per second | ||
| 337 | std::vector<float> p_rateEventBelowLowerBound; | ||
| 338 | ///Number of events above the upper boundary per second | ||
| 339 | std::vector<float> p_rateEventAboveUpperBound; | ||
| 340 | }; | ||
| 341 | |||
| 342 | template<> | ||
| 343 | std::string phoenix_getTypeName<Swarm::VecStat>(); | ||
| 344 | |||
| 345 | ///@brief Generic VecStat serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 346 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 347 | struct DataStream<Stream, Mode, Swarm::VecStat>{ | ||
| 348 | ///Generic function to load/save/serialise/deserialise VecStat | ||
| 349 | /** @param[out] ds : stream to be used | ||
| 350 | * @param data : VecStat to be used | ||
| 351 | * @return true on success, false otherwise | ||
| 352 | */ | ||
| 353 | 6 | static bool data_stream(Stream & ds, Swarm::VecStat & data){ | |
| 354 | 6 | return data.readWriteStream<Stream, Mode>(ds); | |
| 355 | } | ||
| 356 | }; | ||
| 357 | |||
| 358 | ///@brief Generic VecStat Check function | ||
| 359 | template<> | ||
| 360 | struct CheckStream<Swarm::VecStat>{ | ||
| 361 | static bool check_stream(const std::string & fieldDescription, const Swarm::VecStat & data, const Swarm::VecStat & reference, std::ostream & out); | ||
| 362 | }; | ||
| 363 | |||
| 364 | |||
| 365 | |||
| 366 | |||
| 367 | ///@brief Statistics of a Daemon | ||
| 368 | class Swarm::Stat{ | ||
| 369 | public: | ||
| 370 | Stat(); | ||
| 371 | virtual ~Stat(); | ||
| 372 | Stat(const Stat & other); | ||
| 373 | Stat & operator = (const Stat & other); | ||
| 374 | void setName(const PString & name); | ||
| 375 | void setMapStatComputing(const std::map<PString, Swarm::VecStat > & mapStatComputing); | ||
| 376 | void setMapStatCommunication(const std::map<DaemonName, std::map<DataType, Swarm::VecStat > > & mapStatCommunication); | ||
| 377 | const PString & getName() const; | ||
| 378 | PString & getName(); | ||
| 379 | const std::map<PString, Swarm::VecStat > & getMapStatComputing() const; | ||
| 380 | std::map<PString, Swarm::VecStat > & getMapStatComputing(); | ||
| 381 | const std::map<DaemonName, std::map<DataType, Swarm::VecStat > > & getMapStatCommunication() const; | ||
| 382 | std::map<DaemonName, std::map<DataType, Swarm::VecStat > > & getMapStatCommunication(); | ||
| 383 | |||
| 384 | ///Load the current Stat with a stream | ||
| 385 | /** @param[out] ds : stream to be used | ||
| 386 | * @return true on success, false otherwise | ||
| 387 | */ | ||
| 388 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 389 | 6 | bool readWriteStream(Stream & ds){ | |
| 390 | 6 | bool b(true); | |
| 391 | 6 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name); | |
| 392 | 6 | b &= DataStream<Stream, Mode, std::map<PString, Swarm::VecStat > >::data_stream(ds, p_mapStatComputing); | |
| 393 | 6 | b &= DataStream<Stream, Mode, std::map<DaemonName, std::map<DataType, Swarm::VecStat > > >::data_stream(ds, p_mapStatCommunication); | |
| 394 | 6 | return b; | |
| 395 | } | ||
| 396 | |||
| 397 | protected: | ||
| 398 | void copyStat(const Stat & other); | ||
| 399 | private: | ||
| 400 | void initialisationStat(); | ||
| 401 | ///Name of the Daemon where the stats come from | ||
| 402 | PString p_name; | ||
| 403 | ///Map of the computing statistics (key: stat name, value vector of stat) | ||
| 404 | std::map<PString, Swarm::VecStat > p_mapStatComputing; | ||
| 405 | ///Map of the communication statistics (key: destination daemon name, value: {key: data type, value: vector of associated stats } | ||
| 406 | std::map<DaemonName, std::map<DataType, Swarm::VecStat > > p_mapStatCommunication; | ||
| 407 | }; | ||
| 408 | |||
| 409 | template<> | ||
| 410 | std::string phoenix_getTypeName<Swarm::Stat>(); | ||
| 411 | |||
| 412 | ///@brief Generic Stat serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 413 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 414 | struct DataStream<Stream, Mode, Swarm::Stat>{ | ||
| 415 | ///Generic function to load/save/serialise/deserialise Stat | ||
| 416 | /** @param[out] ds : stream to be used | ||
| 417 | * @param data : Stat to be used | ||
| 418 | * @return true on success, false otherwise | ||
| 419 | */ | ||
| 420 | 6 | static bool data_stream(Stream & ds, Swarm::Stat & data){ | |
| 421 | 6 | return data.readWriteStream<Stream, Mode>(ds); | |
| 422 | } | ||
| 423 | }; | ||
| 424 | |||
| 425 | ///@brief Generic Stat Check function | ||
| 426 | template<> | ||
| 427 | struct CheckStream<Swarm::Stat>{ | ||
| 428 | static bool check_stream(const std::string & fieldDescription, const Swarm::Stat & data, const Swarm::Stat & reference, std::ostream & out); | ||
| 429 | }; | ||
| 430 | |||
| 431 | |||
| 432 | |||
| 433 | |||
| 434 | ///@brief Accumulator of event occurence to build swarm statistics over a time period | ||
| 435 | class Swarm::StatAccumulator{ | ||
| 436 | public: | ||
| 437 | StatAccumulator(); | ||
| 438 | virtual ~StatAccumulator(); | ||
| 439 | StatAccumulator(const StatAccumulator & other); | ||
| 440 | StatAccumulator & operator = (const StatAccumulator & other); | ||
| 441 | void setNbEvent(size_t nbEvent); | ||
| 442 | void setSum(float sum); | ||
| 443 | void setMin(float min); | ||
| 444 | void setMax(float max); | ||
| 445 | void setVecHistogram(const std::vector<size_t> & vecHistogram); | ||
| 446 | void setHistLowerBound(float histLowerBound); | ||
| 447 | void setHistUpperBound(float histUpperBound); | ||
| 448 | void setNbEventBelowLowerBound(size_t nbEventBelowLowerBound); | ||
| 449 | void setNbEventAboveUpperBound(size_t nbEventAboveUpperBound); | ||
| 450 | size_t getNbEvent() const; | ||
| 451 | size_t & getNbEvent(); | ||
| 452 | float getSum() const; | ||
| 453 | float & getSum(); | ||
| 454 | float getMin() const; | ||
| 455 | float & getMin(); | ||
| 456 | float getMax() const; | ||
| 457 | float & getMax(); | ||
| 458 | const std::vector<size_t> & getVecHistogram() const; | ||
| 459 | std::vector<size_t> & getVecHistogram(); | ||
| 460 | float getHistLowerBound() const; | ||
| 461 | float & getHistLowerBound(); | ||
| 462 | float getHistUpperBound() const; | ||
| 463 | float & getHistUpperBound(); | ||
| 464 | size_t getNbEventBelowLowerBound() const; | ||
| 465 | size_t & getNbEventBelowLowerBound(); | ||
| 466 | size_t getNbEventAboveUpperBound() const; | ||
| 467 | size_t & getNbEventAboveUpperBound(); | ||
| 468 | |||
| 469 | ///Load the current StatAccumulator with a stream | ||
| 470 | /** @param[out] ds : stream to be used | ||
| 471 | * @return true on success, false otherwise | ||
| 472 | */ | ||
| 473 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 474 | bool readWriteStream(Stream & ds){ | ||
| 475 | bool b(true); | ||
| 476 | b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbEvent); | ||
| 477 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_sum); | ||
| 478 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_min); | ||
| 479 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_max); | ||
| 480 | b &= DataStream<Stream, Mode, std::vector<size_t> >::data_stream(ds, p_vecHistogram); | ||
| 481 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_histLowerBound); | ||
| 482 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_histUpperBound); | ||
| 483 | b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbEventBelowLowerBound); | ||
| 484 | b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_nbEventAboveUpperBound); | ||
| 485 | return b; | ||
| 486 | } | ||
| 487 | |||
| 488 | protected: | ||
| 489 | void copyStatAccumulator(const StatAccumulator & other); | ||
| 490 | private: | ||
| 491 | void initialisationStatAccumulator(); | ||
| 492 | ///Number of events used to make this statistic | ||
| 493 | size_t p_nbEvent; | ||
| 494 | ///Sum of all values | ||
| 495 | float p_sum; | ||
| 496 | ///Minimum value of the stat | ||
| 497 | float p_min; | ||
| 498 | ///Maximum value of the stat | ||
| 499 | float p_max; | ||
| 500 | ///Histogram to acccumulate event counts per quantile | ||
| 501 | std::vector<size_t> p_vecHistogram; | ||
| 502 | ///Minimum value in the histogram | ||
| 503 | float p_histLowerBound; | ||
| 504 | ///Maximum value in the histogram | ||
| 505 | float p_histUpperBound; | ||
| 506 | ///Number of events below the lower bound | ||
| 507 | size_t p_nbEventBelowLowerBound; | ||
| 508 | ///Number of events above the upper boundary | ||
| 509 | size_t p_nbEventAboveUpperBound; | ||
| 510 | }; | ||
| 511 | |||
| 512 | template<> | ||
| 513 | std::string phoenix_getTypeName<Swarm::StatAccumulator>(); | ||
| 514 | |||
| 515 | ///@brief Generic StatAccumulator serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 516 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 517 | struct DataStream<Stream, Mode, Swarm::StatAccumulator>{ | ||
| 518 | ///Generic function to load/save/serialise/deserialise StatAccumulator | ||
| 519 | /** @param[out] ds : stream to be used | ||
| 520 | * @param data : StatAccumulator to be used | ||
| 521 | * @return true on success, false otherwise | ||
| 522 | */ | ||
| 523 | static bool data_stream(Stream & ds, Swarm::StatAccumulator & data){ | ||
| 524 | return data.readWriteStream<Stream, Mode>(ds); | ||
| 525 | } | ||
| 526 | }; | ||
| 527 | |||
| 528 | ///@brief Generic StatAccumulator Check function | ||
| 529 | template<> | ||
| 530 | struct CheckStream<Swarm::StatAccumulator>{ | ||
| 531 | static bool check_stream(const std::string & fieldDescription, const Swarm::StatAccumulator & data, const Swarm::StatAccumulator & reference, std::ostream & out); | ||
| 532 | }; | ||
| 533 | |||
| 534 | |||
| 535 | |||
| 536 | |||
| 537 | ///@brief Accumulator of all events occurence on a Daemon (processing functions and communication latencies) to build swarm statistics over a time period | ||
| 538 | class Swarm::DaemonStatAccumulator{ | ||
| 539 | public: | ||
| 540 | DaemonStatAccumulator(); | ||
| 541 | virtual ~DaemonStatAccumulator(); | ||
| 542 | DaemonStatAccumulator(const DaemonStatAccumulator & other); | ||
| 543 | DaemonStatAccumulator & operator = (const DaemonStatAccumulator & other); | ||
| 544 | void setMapStatComputing(const std::map<PString, Swarm::StatAccumulator > & mapStatComputing); | ||
| 545 | void setMapStatCommunication(const std::map<DaemonName, std::map<DataType, Swarm::StatAccumulator > > & mapStatCommunication); | ||
| 546 | const std::map<PString, Swarm::StatAccumulator > & getMapStatComputing() const; | ||
| 547 | std::map<PString, Swarm::StatAccumulator > & getMapStatComputing(); | ||
| 548 | const std::map<DaemonName, std::map<DataType, Swarm::StatAccumulator > > & getMapStatCommunication() const; | ||
| 549 | std::map<DaemonName, std::map<DataType, Swarm::StatAccumulator > > & getMapStatCommunication(); | ||
| 550 | |||
| 551 | ///Load the current DaemonStatAccumulator with a stream | ||
| 552 | /** @param[out] ds : stream to be used | ||
| 553 | * @return true on success, false otherwise | ||
| 554 | */ | ||
| 555 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 556 | bool readWriteStream(Stream & ds){ | ||
| 557 | bool b(true); | ||
| 558 | b &= DataStream<Stream, Mode, std::map<PString, Swarm::StatAccumulator > >::data_stream(ds, p_mapStatComputing); | ||
| 559 | b &= DataStream<Stream, Mode, std::map<DaemonName, std::map<DataType, Swarm::StatAccumulator > > >::data_stream(ds, p_mapStatCommunication); | ||
| 560 | return b; | ||
| 561 | } | ||
| 562 | |||
| 563 | protected: | ||
| 564 | void copyDaemonStatAccumulator(const DaemonStatAccumulator & other); | ||
| 565 | private: | ||
| 566 | void initialisationDaemonStatAccumulator(); | ||
| 567 | ///Map of the computing statistics (key: stat name, value vector of stat) | ||
| 568 | std::map<PString, Swarm::StatAccumulator > p_mapStatComputing; | ||
| 569 | ///Map of the communication statistics (key: destination daemon name, value: {key: data type, value: vector of associated stats }) | ||
| 570 | std::map<DaemonName, std::map<DataType, Swarm::StatAccumulator > > p_mapStatCommunication; | ||
| 571 | }; | ||
| 572 | |||
| 573 | template<> | ||
| 574 | std::string phoenix_getTypeName<Swarm::DaemonStatAccumulator>(); | ||
| 575 | |||
| 576 | ///@brief Generic DaemonStatAccumulator serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 577 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 578 | struct DataStream<Stream, Mode, Swarm::DaemonStatAccumulator>{ | ||
| 579 | ///Generic function to load/save/serialise/deserialise DaemonStatAccumulator | ||
| 580 | /** @param[out] ds : stream to be used | ||
| 581 | * @param data : DaemonStatAccumulator to be used | ||
| 582 | * @return true on success, false otherwise | ||
| 583 | */ | ||
| 584 | static bool data_stream(Stream & ds, Swarm::DaemonStatAccumulator & data){ | ||
| 585 | return data.readWriteStream<Stream, Mode>(ds); | ||
| 586 | } | ||
| 587 | }; | ||
| 588 | |||
| 589 | ///@brief Generic DaemonStatAccumulator Check function | ||
| 590 | template<> | ||
| 591 | struct CheckStream<Swarm::DaemonStatAccumulator>{ | ||
| 592 | static bool check_stream(const std::string & fieldDescription, const Swarm::DaemonStatAccumulator & data, const Swarm::DaemonStatAccumulator & reference, std::ostream & out); | ||
| 593 | }; | ||
| 594 | |||
| 595 | |||
| 596 | |||
| 597 | |||
| 598 | ///@brief Describe a Daemon of the Swarm | ||
| 599 | class Swarm::DaemonConfig{ | ||
| 600 | public: | ||
| 601 | DaemonConfig(); | ||
| 602 | virtual ~DaemonConfig(); | ||
| 603 | DaemonConfig(const DaemonConfig & other); | ||
| 604 | DaemonConfig & operator = (const DaemonConfig & other); | ||
| 605 | void setHostName(const PString & hostName); | ||
| 606 | void setReceivingPort(size_t receivingPort); | ||
| 607 | void setName(const PString & name); | ||
| 608 | void setDescription(const PString & description); | ||
| 609 | void setMapTimeout(const std::map<PString, time_t> & mapTimeout); | ||
| 610 | void setStatNbBin(size_t statNbBin); | ||
| 611 | void setStatHistLowerBound(float statHistLowerBound); | ||
| 612 | void setStatHistUpperBound(float statHistUpperBound); | ||
| 613 | void setStatTimerPeriodMs(const time_t & statTimerPeriodMs); | ||
| 614 | void setDaemonStatAccumulator(const Swarm::DaemonStatAccumulator & daemonStatAccumulator); | ||
| 615 | void setStatDaemonName(const PString & statDaemonName); | ||
| 616 | const PString & getHostName() const; | ||
| 617 | PString & getHostName(); | ||
| 618 | size_t getReceivingPort() const; | ||
| 619 | size_t & getReceivingPort(); | ||
| 620 | const PString & getName() const; | ||
| 621 | PString & getName(); | ||
| 622 | const PString & getDescription() const; | ||
| 623 | PString & getDescription(); | ||
| 624 | const std::map<PString, time_t> & getMapTimeout() const; | ||
| 625 | std::map<PString, time_t> & getMapTimeout(); | ||
| 626 | size_t getStatNbBin() const; | ||
| 627 | size_t & getStatNbBin(); | ||
| 628 | float getStatHistLowerBound() const; | ||
| 629 | float & getStatHistLowerBound(); | ||
| 630 | float getStatHistUpperBound() const; | ||
| 631 | float & getStatHistUpperBound(); | ||
| 632 | const time_t & getStatTimerPeriodMs() const; | ||
| 633 | time_t & getStatTimerPeriodMs(); | ||
| 634 | const Swarm::DaemonStatAccumulator & getDaemonStatAccumulator() const; | ||
| 635 | Swarm::DaemonStatAccumulator & getDaemonStatAccumulator(); | ||
| 636 | const PString & getStatDaemonName() const; | ||
| 637 | PString & getStatDaemonName(); | ||
| 638 | |||
| 639 | ///Load the current DaemonConfig with a stream | ||
| 640 | /** @param[out] ds : stream to be used | ||
| 641 | * @return true on success, false otherwise | ||
| 642 | */ | ||
| 643 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 644 | bool readWriteStream(Stream & ds){ | ||
| 645 | bool b(true); | ||
| 646 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_hostName); | ||
| 647 | b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_receivingPort); | ||
| 648 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_name); | ||
| 649 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_description); | ||
| 650 | b &= DataStream<Stream, Mode, std::map<PString, time_t> >::data_stream(ds, p_mapTimeout); | ||
| 651 | b &= DataStream<Stream, Mode, size_t >::data_stream(ds, p_statNbBin); | ||
| 652 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_statHistLowerBound); | ||
| 653 | b &= DataStream<Stream, Mode, float >::data_stream(ds, p_statHistUpperBound); | ||
| 654 | b &= DataStream<Stream, Mode, time_t >::data_stream(ds, p_statTimerPeriodMs); | ||
| 655 | b &= DataStream<Stream, Mode, Swarm::DaemonStatAccumulator >::data_stream(ds, p_daemonStatAccumulator); | ||
| 656 | b &= DataStream<Stream, Mode, PString >::data_stream(ds, p_statDaemonName); | ||
| 657 | return b; | ||
| 658 | } | ||
| 659 | |||
| 660 | protected: | ||
| 661 | void copyDaemonConfig(const DaemonConfig & other); | ||
| 662 | private: | ||
| 663 | void initialisationDaemonConfig(); | ||
| 664 | ///Name of the host where the daemon is running | ||
| 665 | PString p_hostName; | ||
| 666 | ///Port which is used by the Daemon to receive messages | ||
| 667 | size_t p_receivingPort; | ||
| 668 | ///Name of the Daemon | ||
| 669 | PString p_name; | ||
| 670 | ///Description of the Daemon | ||
| 671 | PString p_description; | ||
| 672 | ///Map of the timeout for each daemon in the configuration file | ||
| 673 | std::map<PString, time_t> p_mapTimeout; | ||
| 674 | /// Number of bin for the histogram of the communication statistics | ||
| 675 | size_t p_statNbBin; | ||
| 676 | /// Lower bound for the histogram of the communication statistics | ||
| 677 | float p_statHistLowerBound; | ||
| 678 | /// Upper bound for the histogram of the communication statistics | ||
| 679 | float p_statHistUpperBound; | ||
| 680 | /// Period (in ms) to send statistics to the stat daemon | ||
| 681 | time_t p_statTimerPeriodMs; | ||
| 682 | ///Accumulator used to create statistics of the current Daemon | ||
| 683 | Swarm::DaemonStatAccumulator p_daemonStatAccumulator; | ||
| 684 | ///Name of the Daemon which is used to gather statistics of the swarm (empty if no stat daemon is used) | ||
| 685 | PString p_statDaemonName; | ||
| 686 | }; | ||
| 687 | |||
| 688 | template<> | ||
| 689 | std::string phoenix_getTypeName<Swarm::DaemonConfig>(); | ||
| 690 | |||
| 691 | ///@brief Generic DaemonConfig serialisation/deserialisation, load/save and size function for PhoenixDataStream | ||
| 692 | template<typename Stream, DataStreamMode::DataStreamMode Mode> | ||
| 693 | struct DataStream<Stream, Mode, Swarm::DaemonConfig>{ | ||
| 694 | ///Generic function to load/save/serialise/deserialise DaemonConfig | ||
| 695 | /** @param[out] ds : stream to be used | ||
| 696 | * @param data : DaemonConfig to be used | ||
| 697 | * @return true on success, false otherwise | ||
| 698 | */ | ||
| 699 | static bool data_stream(Stream & ds, Swarm::DaemonConfig & data){ | ||
| 700 | return data.readWriteStream<Stream, Mode>(ds); | ||
| 701 | } | ||
| 702 | }; | ||
| 703 | |||
| 704 | ///@brief Generic DaemonConfig Check function | ||
| 705 | template<> | ||
| 706 | struct CheckStream<Swarm::DaemonConfig>{ | ||
| 707 | static bool check_stream(const std::string & fieldDescription, const Swarm::DaemonConfig & data, const Swarm::DaemonConfig & reference, std::ostream & out); | ||
| 708 | }; | ||
| 709 | |||
| 710 | |||
| 711 | |||
| 712 | |||
| 713 | |||
| 714 | |||
| 715 | #endif | ||
| 716 | |||
| 717 |