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 4.6 KB
Newer Older
1
2
3
//================================================================================
// Name        : sensorcache.h
// Author      : Michael Ott
Micha Müller's avatar
Micha Müller committed
4
// Contact     : info@dcdb.it
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright   : Leibniz Supercomputing Centre
// Description :
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2016-2019 Leibniz Supercomputing Centre
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//================================================================================
Alessio Netti's avatar
Alessio Netti committed
27
28
29
30
31
32
33
34
35
36
37
38
39

#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;

40
41
42
43
44
/**
 * @brief
 *
 * @ingroup ca
 */
Alessio Netti's avatar
Alessio Netti committed
45
46
47
48
49
50
class SensorCache {
public:
	SensorCache(uint64_t maxHistory=60000000000);
	virtual ~SensorCache();

	/**
51
	* @brief        Returns a reference to the internal sensor cache map.
Alessio Netti's avatar
Alessio Netti committed
52
	**/
53
	sensorCache_t& getSensorMap();
Alessio Netti's avatar
Alessio Netti committed
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

	/**
	* @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.
	**/
89
//	int64_t getSensor(std::string topic, uint64_t avg=0);
Alessio Netti's avatar
Alessio Netti committed
90
91
92
93
94
95
96
97
98

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

	/**
	* @brief        Removes all obsolete entries from the cache
	*
99
	* @details      entries in the cache whose latest sensor reading is older than "now" - t nanoseconds are
Alessio Netti's avatar
Alessio Netti committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
	*				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_ */