1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSMeanData_Emissions.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Michael Behrisch
13 /// @date    Mon, 10.05.2004
14 /// @version $Id$
15 ///
16 // Emission data collector for edges/lanes
17 /****************************************************************************/
18 #ifndef MSMeanData_Emissions_h
19 #define MSMeanData_Emissions_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <vector>
28 #include <set>
29 #include <limits>
30 #include <utils/emissions/PollutantsInterface.h>
31 #include "MSMeanData.h"
32 
33 
34 // ===========================================================================
35 // class declarations
36 // ===========================================================================
37 class OutputDevice;
38 class MSLane;
39 
40 
41 // ===========================================================================
42 // class definitions
43 // ===========================================================================
44 /**
45  * @class MSMeanData_Emissions
46  * @brief Emission data collector for edges/lanes
47  *
48  * This structure does not contain the data itself, it is stored within
49  *  MSLaneMeanDataValues-MoveReminder objects.
50  *
51  * This class is used to build the output, optionally, in the case
52  *  of edge-based dump, aggregated over the edge's lanes.
53  *
54  * @todo consider error-handling on write (using IOError)
55  */
56 class MSMeanData_Emissions : public MSMeanData {
57 public:
58     /**
59      * @class MSLaneMeanDataValues
60      * @brief Data structure for mean (aggregated) edge/lane values
61      *
62      * Structure holding values that describe the emissions aggregated
63      *  over some seconds.
64      */
65     class MSLaneMeanDataValues : public MSMeanData::MeanDataValues {
66     public:
67         /** @brief Constructor */
68         MSLaneMeanDataValues(MSLane* const lane, const double length, const bool doAdd,
69                              const MSMeanData_Emissions* parent);
70 
71         /** @brief Destructor */
72         virtual ~MSLaneMeanDataValues();
73 
74 
75         /** @brief Resets values so they may be used for the next interval
76          */
77         void reset(bool afterWrite = false);
78 
79 
80         /** @brief Add the values of this to the given one and store them there
81          *
82          * @param[in] val The meandata to add to
83          */
84         void addTo(MSMeanData::MeanDataValues& val) const;
85 
86 
87         /** @brief Writes output values into the given stream
88          *
89          * @param[in] dev The output device to write the data into
90          * @param[in] prefix The xml prefix to write (mostly the lane / edge id)
91          * @param[in] numLanes The total number of lanes for which the data was collected
92          * @param[in] length The length of the object for which the data was collected
93          * @exception IOError If an error on writing occurs (!!! not yet implemented)
94          */
95         void write(OutputDevice& dev, const SUMOTime period,
96                    const double numLanes, const double defaultTravelTime,
97                    const int numVehicles = -1) const;
98 
99 
100     protected:
101         /** @brief Internal notification about the vehicle moves
102          *  @see MSMoveReminder::notifyMoveInternal()
103          */
104         void notifyMoveInternal(const SUMOTrafficObject& veh, const double /* frontOnLane */, const double timeOnLane, const double /*meanSpeedFrontOnLane*/, const double meanSpeedVehicleOnLane, const double travelledDistanceFrontOnLane, const double travelledDistanceVehicleOnLane, const double /* meanLengthOnLane */);
105 
106 
107     private:
108         /// @brief Collected values
109         PollutantsInterface::Emissions myEmissions;
110     };
111 
112 
113 public:
114     /** @brief Constructor
115      *
116      * @param[in] id The id of the detector
117      * @param[in] dumpBegin Begin time of dump
118      * @param[in] dumpEnd End time of dump
119      * @param[in] useLanes Information whether lane-based or edge-based dump shall be generated
120      * @param[in] withEmpty Information whether empty lanes/edges shall be written
121      * @param[in] printDefaults Information whether defaults for empty lanes/edges shall be written
122      * @param[in] withInternal Information whether internal lanes/edges shall be written
123      * @param[in] trackVehicles Information whether vehicles shall be tracked
124      * @param[in] maxTravelTime the maximum travel time to use when calculating per vehicle output
125      * @param[in] minSamples the minimum number of sample seconds before the values are valid
126      * @param[in] vTypes the set of vehicle types to consider
127      */
128     MSMeanData_Emissions(const std::string& id,
129                          const SUMOTime dumpBegin, const SUMOTime dumpEnd,
130                          const bool useLanes, const bool withEmpty,
131                          const bool printDefaults, const bool withInternal,
132                          const bool trackVehicles,
133                          const double minSamples, const double maxTravelTime,
134                          const std::string& vTypes);
135 
136 
137     /// @brief Destructor
138     virtual ~MSMeanData_Emissions();
139 
140 
141 
142 protected:
143     /** @brief Create an instance of MeanDataValues
144      *
145      * @param[in] lane The lane to create for
146      * @param[in] doAdd whether to add the values as reminder to the lane
147      */
148     MSMeanData::MeanDataValues* createValues(MSLane* const lane, const double length, const bool doAdd) const;
149 
150 
151 
152 private:
153     /// @brief Invalidated copy constructor.
154     MSMeanData_Emissions(const MSMeanData_Emissions&);
155 
156     /// @brief Invalidated assignment operator.
157     MSMeanData_Emissions& operator=(const MSMeanData_Emissions&);
158 
159 };
160 
161 
162 #endif
163 
164 /****************************************************************************/
165 
166