The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated 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

sensor.cpp 3.76 KB
Newer Older
1
2
3
//================================================================================
// Name        : sensor.cpp
// Author      : Michael Ott, Daniele Tafani
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 : Source file for Sensor class.
//================================================================================

//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2017-2019 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//================================================================================
27
28
29
30
31
32
33

#include <iostream>
#include <dcdb/sensor.h>
#include <dcdb/virtualsensor.h>

namespace DCDB {

34
  Sensor::Sensor(Connection* connection, const std::string& publicName) {
35
    /* Initialize the SensorConfig interface */
Michael Ott's avatar
Michael Ott committed
36
37
38
    sensorConfig = new SensorConfig(connection);

    this->connection = connection;
39
40
      
    /* Retrieve publicSensor info */
Michael Ott's avatar
Michael Ott committed
41
    switch (sensorConfig->getPublicSensorByName(publicSensor, publicName.c_str())) {
42
43
44
45
46
47
48
49
50
51
52
53
    case DCDB::SC_OK:
      break;
    case DCDB::SC_INVALIDSESSION:
      std::cout << "Invalid session." << std::endl;
      return;
    case DCDB::SC_UNKNOWNSENSOR:
      std::cout << "Unknown sensor: " << publicName << std::endl;
      return;
    default:
      std::cout << "Unknown error." << std::endl;
      return;
    }
Michael Ott's avatar
Michael Ott committed
54
  }
55
  
56
  Sensor::Sensor(Connection* connection, const PublicSensor& sensor) {
57
58
59
60
61
62
    /* Initialize the SensorConfig interface */
    sensorConfig = new SensorConfig(connection);
    
    this->connection = connection;
    publicSensor = sensor;
  }
Michael Ott's avatar
Michael Ott committed
63
64
65
66
67

  Sensor::~Sensor() {
    delete sensorConfig;
  }

68
  void Sensor::query(std::list<SensorDataStoreReading>& result, TimeStamp& start, TimeStamp& end, QueryAggregate aggregate, uint64_t tol_ns) {
Michael Ott's avatar
Michael Ott committed
69
    SensorDataStore sensorDataStore(connection);
70
71

    if (publicSensor.is_virtual) {
Michael Ott's avatar
Michael Ott committed
72
        VSensor vSen(connection, publicSensor);
73
74
75
76
        vSen.query(result, start, end);
    }
    else {
        /* Expand the pattern into a list of existing sensors in the time range */
Michael Ott's avatar
Michael Ott committed
77
78
        std::list<SensorId> sensorIds;
        switch (sensorConfig->getSensorListForPattern(sensorIds, publicSensor.pattern, start, end)) {
79
80
81
82
83
84
85
86
87
88
89
        case DCDB::SC_OK:
          break;
        case DCDB::SC_INVALIDPATTERN:
          std::cout << "Invalid pattern." << std::endl;
          return;
        default:
          std::cout << "Unknown error." << std::endl;
          return;
        }

        /* Iterate over the expanded list of sensorIds and output the results in CSV format */
90
91
92
93
94
95
96
97
        if(start.getRaw() != end.getRaw()) {
            for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
                sensorDataStore.query(result, *sit, start, end, aggregate);
            }
        } else {
            for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
                sensorDataStore.fuzzyQuery(result, *sit, start, tol_ns);
            }
98
99
100
        }
    }
  }
101
  
102
} /* namespace DCDB */