Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2024 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 MSDetectorFileOutput.h
15 : /// @author Christian Roessel
16 : /// @author Daniel Krajzewicz
17 : /// @author Sascha Krieg
18 : /// @author Michael Behrisch
19 : /// @author Jakob Erdmann
20 : /// @date 2004-11-23
21 : ///
22 : // Base of value-generating classes (detectors)
23 : /****************************************************************************/
24 : #pragma once
25 : #include <config.h>
26 :
27 : #include <string>
28 : #include <set>
29 :
30 : #include <utils/common/Named.h>
31 : #include <utils/common/Parameterised.h>
32 : #include <utils/common/SUMOTime.h>
33 : #include <microsim/MSNet.h>
34 :
35 :
36 : // ===========================================================================
37 : // class declarations
38 : // ===========================================================================
39 : class OutputDevice;
40 : class GUIDetectorWrapper;
41 : class SUMOTrafficObject;
42 : class MSTransportable;
43 : class MSEdge;
44 :
45 :
46 : // ===========================================================================
47 : // class definitions
48 : // ===========================================================================
49 : enum DetectorUsage {
50 : DU_USER_DEFINED,
51 : DU_SUMO_INTERNAL,
52 : DU_TL_CONTROL
53 : };
54 :
55 : /**
56 : * @class MSDetectorFileOutput
57 : * @brief Base of value-generating classes (detectors)
58 : *
59 : * Pure virtual base class for classes (e.g. MSInductLoop) that should produce
60 : * XML-output.
61 : */
62 : class MSDetectorFileOutput : public Named, public Parameterised {
63 : public:
64 : /// @brief Constructor
65 : MSDetectorFileOutput(const std::string& id, const std::string& vTypes, const std::string& nextEdges = "", const int detectPersons = false);
66 :
67 : /// @brief (virtual) destructor
68 75246 : virtual ~MSDetectorFileOutput() { }
69 :
70 :
71 : /// @name Virtual methods to implement by derived classes
72 : /// @{
73 :
74 : /** @brief Write the generated output to the given device
75 : * @param[in] dev The output device to write the data into
76 : * @param[in] startTime First time step the data were gathered
77 : * @param[in] stopTime Last time step the data were gathered
78 : * @exception IOError If an error on writing occurs
79 : */
80 : virtual void writeXMLOutput(OutputDevice& dev,
81 : SUMOTime startTime, SUMOTime stopTime) = 0;
82 :
83 :
84 : /** @brief Open the XML-output
85 : *
86 : * The implementing function should open an xml element using
87 : * OutputDevice::writeXMLHeader.
88 : *
89 : * @param[in] dev The output device to write the root into
90 : * @exception IOError If an error on writing occurs
91 : */
92 : virtual void writeXMLDetectorProlog(OutputDevice& dev) const = 0;
93 :
94 :
95 : /** @brief Resets collected values
96 : *
97 : * Please note that this is only a "hack" for coupled-tls-outputs.
98 : *
99 : * @see Command_SaveTLCoupledLaneDet
100 : * @todo Reckeck/refactor
101 : */
102 0 : virtual void reset() { }
103 :
104 :
105 : /** @brief Updates the detector (computes values)
106 : *
107 : * @param[in] step The current time step
108 : */
109 2647023 : virtual void detectorUpdate(const SUMOTime step) {
110 : UNUSED_PARAMETER(step);
111 2647023 : }
112 :
113 :
114 : /** @brief Builds the graphical representation
115 : *
116 : * Meant to be overridden by graphical versions of the detectors
117 : * @return A wrapper for the detector which performs the user I/O within the GUI
118 : */
119 31 : virtual GUIDetectorWrapper* buildDetectorGUIRepresentation() {
120 31 : return 0;
121 : }
122 :
123 :
124 : /** @brief Checks whether the detector measures vehicles of the given type.
125 : *
126 : * @param[in] veh the vehicle of which the type is checked.
127 : * @return whether it should be measured
128 : */
129 : bool vehicleApplies(const SUMOTrafficObject& veh) const;
130 :
131 : bool personApplies(const MSTransportable& p, int dir) const;
132 :
133 :
134 : /** @brief Checks whether the detector is type specific.
135 : *
136 : * @return whether vehicle types are considered
137 : */
138 : bool isTyped() const {
139 : return !myVehicleTypes.empty();
140 : }
141 :
142 : const std::set<std::string>& getVehicleTypes() const {
143 0 : return myVehicleTypes;
144 : }
145 :
146 : inline bool detectPersons() const {
147 448565144 : return myDetectPersons != 0;
148 : }
149 :
150 : /** @brief Remove all vehicles before quick-loading state */
151 0 : virtual void clearState(SUMOTime /*step*/) {};
152 :
153 : protected:
154 : /// @brief The vehicle types to look for (empty means all)
155 : std::set<std::string> myVehicleTypes;
156 :
157 : /// @brief The upcoming edges to filter by (empty means no filtering)
158 : std::vector<const MSEdge*> myNextEdges;
159 :
160 : /// @brief Whether pedestrians shall be detected instead of vehicles
161 : const int myDetectPersons;
162 :
163 : private:
164 : /// @brief Invalidated copy constructor.
165 : MSDetectorFileOutput(const MSDetectorFileOutput&);
166 :
167 : /// @brief Invalidated assignment operator.
168 : MSDetectorFileOutput& operator=(const MSDetectorFileOutput&);
169 :
170 :
171 : };
|