Eclipse SUMO - Simulation of Urban MObility
MSDevice_FCD.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-2020 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 /****************************************************************************/
20 // A device which stands as an implementation FCD and which outputs movereminder calls
21 /****************************************************************************/
22 #include <config.h>
23 
28 #include <microsim/MSNet.h>
29 #include <microsim/MSLane.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSVehicle.h>
32 #include "MSDevice_FCD.h"
33 
34 // ===========================================================================
35 // static members
36 // ===========================================================================
37 std::set<const MSEdge*> MSDevice_FCD::myEdgeFilter;
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 // ---------------------------------------------------------------------------
44 // static initialisation methods
45 // ---------------------------------------------------------------------------
46 void
48  oc.addOptionSubTopic("FCD Device");
49  insertDefaultAssignmentOptions("fcd", "FCD Device", oc);
50 
51  oc.doRegister("device.fcd.period", new Option_String("0"));
52  oc.addDescription("device.fcd.period", "FCD Device", "Recording period for FCD-data");
53 
54  oc.doRegister("device.fcd.radius", new Option_Float(0));
55  oc.addDescription("device.fcd.radius", "FCD Device", "Record objects in a radius around equipped vehicles");
56 }
57 
58 
59 void
60 MSDevice_FCD::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
62  if (equippedByDefaultAssignmentOptions(oc, "fcd", v, oc.isSet("fcd-output"))) {
63  MSDevice_FCD* device = new MSDevice_FCD(v, "fcd_" + v.getID());
64  into.push_back(device);
67  }
68  }
69 }
70 
71 
72 // ---------------------------------------------------------------------------
73 // MSDevice_FCD-methods
74 // ---------------------------------------------------------------------------
75 MSDevice_FCD::MSDevice_FCD(SUMOVehicle& holder, const std::string& id) :
76  MSVehicleDevice(holder, id) {
77 }
78 
79 
81 }
82 
83 
84 void
87  if (OptionsCont::getOptions().isSet("fcd-output.filter-edges.input-file")) {
88  const std::string file = OptionsCont::getOptions().getString("fcd-output.filter-edges.input-file");
89  std::ifstream strm(file.c_str());
90  if (!strm.good()) {
91  throw ProcessError("Could not load names of edges for filtering fcd-output from '" + file + "'.");
92  }
93  while (strm.good()) {
94  std::string name;
95  strm >> name;
96  // maybe we're loading an edge-selection
97  if (StringUtils::startsWith(name, "edge:")) {
98  name = name.substr(5);
99  }
100  myEdgeFilter.insert(MSEdge::dictionary(name));
101  }
102  }
103 }
104 
105 
106 void
108  myEdgeFilter.clear();
109  myEdgeFilterInitialized = false;
110 }
111 
112 
113 /****************************************************************************/
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_FCD.h:46
static void cleanup()
resets the edge filter
MSDevice_FCD(SUMOVehicle &holder, const std::string &id)
Constructor.
~MSDevice_FCD()
Destructor.
static std::set< const MSEdge * > myEdgeFilter
spatial filter for FCD output
Definition: MSDevice_FCD.h:99
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
static void initEdgeFilter()
initialize edge filter (once)
static bool myEdgeFilterInitialized
Definition: MSDevice_FCD.h:100
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:134
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:204
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn't already in the dictionary....
Definition: MSEdge.cpp:814
Abstract in-vehicle device.
const std::string & getID() const
Returns the id.
Definition: Named.h:73
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Representation of a vehicle.
Definition: SUMOVehicle.h:58
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.