Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

sensorcache.h 3.36 KB
Newer Older
Alessio Netti's avatar
Alessio Netti committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * SensorCache.h
 *
 *  Created on: 3 Aug 2016
 *      Author: ottmi
 */

#ifndef COLLECTAGENT_SENSORCACHE_H_
#define COLLECTAGENT_SENSORCACHE_H_

#include <map>
#include <dcdb/sensorid.h>
#include <dcdb/timestamp.h>
#include "cacheentry.h"

using namespace DCDB;

typedef std::map<SensorId, CacheEntry> sensorCache_t;

class SensorCache {
public:
	SensorCache(uint64_t maxHistory=60000000000);
	virtual ~SensorCache();

	/**
	* @brief        Returns a constant reference to the internal sensor cache map.
	**/
	const sensorCache_t& getSensorMap();

	/**
	* @brief        Store a sensor reading in the SensorCache.
	*
	* @param sid    The SensorId of the sensor to be cached.
    * @param ts     The timestamp of the sensor reading.
    * @param val    The actual sensor reading.
	* @return       Returns true if the topic string was valid and the data field of the object was populated.
	**/
	void storeSensor(SensorId sid, uint64_t ts, int64_t val);

	/**
    * @brief        Return a sensor reading or the average of the last readings
    *               from the SensorCache.
    *
    * @param sid    The SensorId of the sensor to be looked up in the cache.
    * @param avg    If avg > 0: denotes the length of the average aggregation window in nanoseconds.
    * @return       If avg == 0 :The sensor reading of the corresponding cache entry.
    *               If avg > 0 the average of the last readings is returned.
    * @throws       std::invalid_argument if the SensorId doesn't exist in the SensorCache.
    * @throws       std::out_of_range if the sid was found in the cache entry but is outdated.
    **/
	int64_t getSensor(SensorId sid, uint64_t avg=0);

	/**
	* @brief        Return a sensor reading or the average of the last readings
    *               from the SensorCache.
	*
	* @param topic  The topic of the sensor to be looked up in the cache. May contain wildcards.
	* @param avg    If avg > 0: denotes the length of the average aggregation window in nanoseconds.
	* @return       If avg == 0 :The sensor reading of the corresponding cache entry.
    *               If avg > 0 the average of the last readings is returned.
	* @throws       std::invalid_argument if the topic couldn't be found in the SensorCache.
	* @throws       std::out_of_range if the topic was found in the cache entry but is outdated.
	**/
	int64_t getSensor(std::string topic, uint64_t avg=0);

	/**
    * @brief        Dump the contents of the SensorCache to stdout.
    **/
	void dump();

	/**
	* @brief        Removes all obsolete entries from the cache
	*
	*				All entries in the cache whose latest sensor reading is older than "now" - t nanoseconds are
	*				removed.
	*
	* @param t		The threshold in nanoseconds for entries that must be removed
	* @return		The number of purged cache entries
	**/
	uint64_t clean(uint64_t t);

    /**
    * @brief  Set a new maximum cache length.
    *
    * @param maxHistory: new sensor cache length value.
    **/
	void setMaxHistory(uint64_t maxHistory) { this->_maxHistory = maxHistory; }

    /**
    * @brief  Returns the current maximum sensor cache length
    *
    * @return Current maximum sensor cache length
    */
	uint64_t getMaxHistory() { return this->_maxHistory; }

private:
	// Map containing the single sensor caches
	sensorCache_t sensorCache;
	// Global maximum allowed time frame for the sensor caches
	uint64_t _maxHistory;

};

#endif /* COLLECTAGENT_SENSORCACHE_H_ */