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 /****************************************************************************/
16 // A device which stands as an implementation FCD and which outputs movereminder calls
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
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 
55 
56 void
57 MSDevice_FCD::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
59  if (equippedByDefaultAssignmentOptions(oc, "fcd", v, oc.isSet("fcd-output"))) {
60  MSDevice_FCD* device = new MSDevice_FCD(v, "fcd_" + v.getID());
61  into.push_back(device);
64  }
65  }
66 }
67 
68 
69 // ---------------------------------------------------------------------------
70 // MSDevice_FCD-methods
71 // ---------------------------------------------------------------------------
72 MSDevice_FCD::MSDevice_FCD(SUMOVehicle& holder, const std::string& id) :
73  MSVehicleDevice(holder, id) {
74 }
75 
76 
78 }
79 
80 
81 void
84  if (OptionsCont::getOptions().isSet("fcd-output.filter-edges.input-file")) {
85  const std::string file = OptionsCont::getOptions().getString("fcd-output.filter-edges.input-file");
86  std::ifstream strm(file.c_str());
87  if (!strm.good()) {
88  throw ProcessError("Could not load names of edges for filtering fcd-output from '" + file + "'.");
89  }
90  while (strm.good()) {
91  std::string name;
92  strm >> name;
93  // maybe we're loading an edge-selection
94  if (StringUtils::startsWith(name, "edge:")) {
95  name = name.substr(5);
96  }
97  myEdgeFilter.insert(MSEdge::dictionary(name));
98  }
99  }
100 }
101 
102 
103 void
105  myEdgeFilter.clear();
106  myEdgeFilterInitialized = false;
107 }
108 
109 /****************************************************************************/
110 
MSDevice_FCD::insertOptions
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
Definition: MSDevice_FCD.cpp:47
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
MSNet.h
OptionsCont.h
SUMOTrafficObject::getID
virtual const std::string & getID() const =0
Get the vehicle's ID.
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
MSDevice_FCD::buildVehicleDevices
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice_FCD.cpp:57
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:60
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
MSDevice_FCD
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_FCD.h:48
MSDevice_FCD::myEdgeFilterInitialized
static bool myEdgeFilterInitialized
Definition: MSDevice_FCD.h:102
MSEdge.h
MSVehicle.h
SUMOVehicle.h
OptionsCont::addDescription
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
Definition: OptionsCont.cpp:469
MSDevice::insertDefaultAssignmentOptions
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::cleanup
static void cleanup()
resets the edge filter
Definition: MSDevice_FCD.cpp:104
MSEdge::dictionary
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:765
OutputDevice.h
OptionsCont::doRegister
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:74
ProcessError
Definition: UtilExceptions.h:39
MSDevice_FCD::myEdgeFilter
static std::set< const MSEdge * > myEdgeFilter
spatial filter for FCD output
Definition: MSDevice_FCD.h:101
Option_String
Definition: Option.h:399
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
StringUtils::startsWith
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.
Definition: StringUtils.cpp:174
MSDevice_FCD::~MSDevice_FCD
~MSDevice_FCD()
Destructor.
Definition: MSDevice_FCD.cpp:77
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:519
StringUtils.h
MSDevice::equippedByDefaultAssignmentOptions
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:203
config.h
MSDevice_FCD.h
MSDevice_FCD::initEdgeFilter
static void initEdgeFilter()
initialize edge filter (once)
Definition: MSDevice_FCD.cpp:82
MSLane.h
MSDevice_FCD::MSDevice_FCD
MSDevice_FCD(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice_FCD.cpp:72
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:54