Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libsumo/MeanData.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file MeanData.cpp
15
/// @author Jakob Erdmann
16
/// @date 16.03.2020
17
///
18
// C++ TraCI client API implementation
19
/****************************************************************************/
20
#include <config.h>
21
22
#include <microsim/MSNet.h>
23
#include <microsim/MSEdge.h>
24
#include <microsim/output/MSDetectorControl.h>
25
#include <microsim/output/MSMeanData.h>
26
#include <libsumo/TraCIConstants.h>
27
#include "Helper.h"
28
#include "MeanData.h"
29
30
31
namespace libsumo {
32
// ===========================================================================
33
// static member initializations
34
// ===========================================================================
35
SubscriptionResults MeanData::mySubscriptionResults;
36
ContextSubscriptionResults MeanData::myContextSubscriptionResults;
37
38
39
// ===========================================================================
40
// static member definitions
41
// ===========================================================================
42
std::vector<std::string>
43
MeanData::getIDList() {
44
std::vector<std::string> ids;
45
for (const auto& item : MSNet::getInstance()->getDetectorControl().getMeanData()) {
46
ids.push_back(item.first);
47
}
48
std::sort(ids.begin(), ids.end());
49
return ids;
50
}
51
52
int
53
MeanData::getIDCount() {
54
return (int)getIDList().size();
55
}
56
57
58
std::string
59
MeanData::getParameter(const std::string& /* dataID */, const std::string& /* param */) {
60
return "";
61
}
62
63
LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(MeanData)
64
65
void
66
MeanData::setParameter(const std::string& /* dataID */, const std::string& /* key */, const std::string& /* value */) {
67
//MSMeanData* r = const_cast<MSMeanData*>(getMeanData(dataID));
68
//r->setParameter(key, value);
69
}
70
71
72
LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(MeanData, MEANDATA)
73
74
75
MSMeanData*
76
MeanData::getMeanData(const std::string& id) {
77
auto mdMap = MSNet::getInstance()->getDetectorControl().getMeanData();
78
auto it = mdMap.find(id);
79
if (it == mdMap.end() || it->second.size() == 0) {
80
throw TraCIException("MeanData '" + id + "' is not known");
81
}
82
if (it->second.size() > 1) {
83
WRITE_WARNINGF(TL("Found % meanData definitions with id '%'."), toString(it->second.size()), id);
84
}
85
return it->second.front();
86
}
87
88
89
std::shared_ptr<VariableWrapper>
90
MeanData::makeWrapper() {
91
return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
92
}
93
94
95
bool
96
MeanData::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
97
switch (variable) {
98
case TRACI_ID_LIST:
99
return wrapper->wrapStringList(objID, variable, getIDList());
100
case ID_COUNT:
101
return wrapper->wrapInt(objID, variable, getIDCount());
102
case libsumo::VAR_PARAMETER:
103
paramData->readUnsignedByte();
104
return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
105
case libsumo::VAR_PARAMETER_WITH_KEY:
106
paramData->readUnsignedByte();
107
return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
108
default:
109
return false;
110
}
111
}
112
113
}
114
115
116
/****************************************************************************/
117
118