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-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 /****************************************************************************/
17 // A device which stands as an implementation FCD and which outputs movereminder calls
18 /****************************************************************************/
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
29 #include <microsim/MSNet.h>
30 #include <microsim/MSLane.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSVehicle.h>
33 #include "MSDevice_FCD.h"
34 
35 // ===========================================================================
36 // static members
37 // ===========================================================================
38 std::set<const MSEdge*> MSDevice_FCD::myEdgeFilter;
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 // ---------------------------------------------------------------------------
45 // static initialisation methods
46 // ---------------------------------------------------------------------------
47 void
49  oc.addOptionSubTopic("FCD Device");
50  insertDefaultAssignmentOptions("fcd", "FCD Device", oc);
51 
52  oc.doRegister("device.fcd.period", new Option_String("0"));
53  oc.addDescription("device.fcd.period", "FCD Device", "Recording period for FCD-data");
54 }
55 
56 
57 void
58 MSDevice_FCD::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
60  if (equippedByDefaultAssignmentOptions(oc, "fcd", v, oc.isSet("fcd-output"))) {
61  MSDevice_FCD* device = new MSDevice_FCD(v, "fcd_" + v.getID());
62  into.push_back(device);
65  }
66  }
67 }
68 
69 
70 // ---------------------------------------------------------------------------
71 // MSDevice_FCD-methods
72 // ---------------------------------------------------------------------------
73 MSDevice_FCD::MSDevice_FCD(SUMOVehicle& holder, const std::string& id) :
74  MSVehicleDevice(holder, id) {
75 }
76 
77 
79 }
80 
81 
82 void
85  if (OptionsCont::getOptions().isSet("fcd-output.filter-edges.input-file")) {
86  const std::string file = OptionsCont::getOptions().getString("fcd-output.filter-edges.input-file");
87  std::ifstream strm(file.c_str());
88  if (!strm.good()) {
89  throw ProcessError("Could not load names of edges for filtering fcd-output from '" + file + "'.");
90  }
91  while (strm.good()) {
92  std::string name;
93  strm >> name;
94  // maybe we're loading an edge-selection
95  if (StringUtils::startsWith(name, "edge:")) {
96  name = name.substr(5);
97  }
98  myEdgeFilter.insert(MSEdge::dictionary(name));
99  }
100  }
101 }
102 
103 
104 void
106  myEdgeFilter.clear();
107  myEdgeFilterInitialized = false;
108 }
109 
110 /****************************************************************************/
111 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
static void cleanup()
resets the edge filter
static bool dictionary(const std::string &id, MSEdge *edge)
Inserts edge into the static dictionary Returns true if the key id isn&#39;t already in the dictionary...
Definition: MSEdge.cpp:804
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
static std::set< const MSEdge * > myEdgeFilter
spatial filter for FCD output
Definition: MSDevice_FCD.h:102
Representation of a vehicle.
Definition: SUMOVehicle.h:61
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
~MSDevice_FCD()
Destructor.
static bool myEdgeFilterInitialized
Definition: MSDevice_FCD.h:103
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
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:126
MSDevice_FCD(SUMOVehicle &holder, const std::string &id)
Constructor.
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
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
Definition: MSDevice_FCD.h:49
A storage for options typed value containers)
Definition: OptionsCont.h:90
Abstract in-vehicle device.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static void initEdgeFilter()
initialize edge filter (once)