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 
MSDevice_FCD::insertOptions
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
Definition: MSDevice_FCD.cpp:48
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:136
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:202
MSDevice_FCD::buildVehicleDevices
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
Definition: MSDevice_FCD.cpp:58
SUMOVehicle
Representation of a vehicle.
Definition: SUMOVehicle.h:61
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
MSDevice_FCD
A device which collects info on the vehicle trip (mainly on departure and arrival)
Definition: MSDevice_FCD.h:49
MSDevice_FCD::myEdgeFilterInitialized
static bool myEdgeFilterInitialized
Definition: MSDevice_FCD.h:103
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:473
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:105
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:804
OutputDevice.h
OptionsCont::doRegister
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
ProcessError
Definition: UtilExceptions.h:40
MSDevice_FCD::myEdgeFilter
static std::set< const MSEdge * > myEdgeFilter
spatial filter for FCD output
Definition: MSDevice_FCD.h:102
Option_String
Definition: Option.h:401
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:90
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:142
MSDevice_FCD::~MSDevice_FCD
~MSDevice_FCD()
Destructor.
Definition: MSDevice_FCD.cpp:78
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:523
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:204
config.h
MSDevice_FCD.h
MSDevice_FCD::initEdgeFilter
static void initEdgeFilter()
initialize edge filter (once)
Definition: MSDevice_FCD.cpp:83
MSLane.h
MSDevice_FCD::MSDevice_FCD
MSDevice_FCD(SUMOVehicle &holder, const std::string &id)
Constructor.
Definition: MSDevice_FCD.cpp:73
MSVehicleDevice
Abstract in-vehicle device.
Definition: MSVehicleDevice.h:55