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-2018 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 
30 #include <microsim/MSNet.h>
31 #include <microsim/MSLane.h>
32 #include <microsim/MSEdge.h>
33 #include <microsim/MSVehicle.h>
34 #include "MSDevice_Tripinfo.h"
35 #include "MSDevice_FCD.h"
36 
37 // ===========================================================================
38 // static members
39 // ===========================================================================
40 std::set<const MSEdge*> MSDevice_FCD::myEdgeFilter;
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // static initialisation methods
48 // ---------------------------------------------------------------------------
49 void
51  oc.addOptionSubTopic("FCD Device");
52  insertDefaultAssignmentOptions("fcd", "FCD Device", oc);
53 
54  oc.doRegister("device.fcd.period", new Option_String("0"));
55  oc.addDescription("device.fcd.period", "FCD Device", "Recording period for FCD-data");
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 
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
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:788
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:101
Representation of a vehicle.
Definition: SUMOVehicle.h:60
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:102
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:121
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:208
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
Definition: MSDevice_FCD.h:48
A storage for options typed value containers)
Definition: OptionsCont.h:92
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)
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.