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-2022 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 
24 #include <bitset>
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 // some attributes are not written by default and must be enabled via option fcd-output.attributes
36 #define DEFAULT_MASK (~((long long int)1 << SUMO_ATTR_VEHICLE))
37 
38 // ===========================================================================
39 // static members
40 // ===========================================================================
41 std::set<const MSEdge*> MSDevice_FCD::myEdgeFilter;
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 // ---------------------------------------------------------------------------
49 // static initialisation methods
50 // ---------------------------------------------------------------------------
51 void
53  oc.addOptionSubTopic("FCD Device");
54  insertDefaultAssignmentOptions("fcd", "FCD Device", oc);
55 
56  oc.doRegister("device.fcd.period", new Option_String("0"));
57  oc.addDescription("device.fcd.period", "FCD Device", "Recording period for FCD-data");
58 
59  oc.doRegister("device.fcd.radius", new Option_Float(0));
60  oc.addDescription("device.fcd.radius", "FCD Device", "Record objects in a radius around equipped vehicles");
61 }
62 
63 
64 void
65 MSDevice_FCD::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
67  if (equippedByDefaultAssignmentOptions(oc, "fcd", v, oc.isSet("fcd-output"))) {
68  MSDevice_FCD* device = new MSDevice_FCD(v, "fcd_" + v.getID());
69  into.push_back(device);
70  initOnce();
71  }
72 }
73 
74 
75 // ---------------------------------------------------------------------------
76 // MSDevice_FCD-methods
77 // ---------------------------------------------------------------------------
78 MSDevice_FCD::MSDevice_FCD(SUMOVehicle& holder, const std::string& id) :
79  MSVehicleDevice(holder, id) {
80 }
81 
82 
84 }
85 
86 
87 void
90  return;
91  }
94  if (oc.isSet("fcd-output.filter-edges.input-file")) {
95  const std::string file = oc.getString("fcd-output.filter-edges.input-file");
96  std::ifstream strm(file.c_str());
97  if (!strm.good()) {
98  throw ProcessError("Could not load names of edges for filtering fcd-output from '" + file + "'.");
99  }
100  while (strm.good()) {
101  std::string name;
102  strm >> name;
103  // maybe we're loading an edge-selection
104  if (StringUtils::startsWith(name, "edge:")) {
105  name = name.substr(5);
106  }
107  myEdgeFilter.insert(MSEdge::dictionary(name));
108  }
109  }
110  if (oc.isSet("fcd-output.attributes")) {
112  for (std::string attrName : oc.getStringVector("fcd-output.attributes")) {
113  if (!SUMOXMLDefinitions::Attrs.hasString(attrName)) {
114  WRITE_ERROR("Unknown attribute '" + attrName + "' to write in fcd output.");
115  continue;
116  }
117  int attr = SUMOXMLDefinitions::Attrs.get(attrName);
118  assert(attr < 63);
119  myWrittenAttributes |= ((long long int)1 << attr);
120  }
121  }
122  //std::cout << "mask=" << myWrittenAttributes << " binary=" << std::bitset<64>(myWrittenAttributes) << "\n";
123 }
124 
125 
126 void
128  myEdgeFilter.clear();
129  myEdgeFilterInitialized = false;
131 }
132 
133 
134 /****************************************************************************/
#define DEFAULT_MASK
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
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
static long long int myWrittenAttributes
bit mask for checking attributes to be written
Definition: MSDevice_FCD.h:111
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:107
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_FCD-options.
static bool myEdgeFilterInitialized
Definition: MSDevice_FCD.h:108
static void initOnce()
initialize edge filter and attribute mask (once)
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:137
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:205
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:885
Abstract in-vehicle device.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
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.
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static StringBijection< int > Attrs
The names of SUMO-XML attributes for use in netbuild.
T get(const std::string &str) const
static bool startsWith(const std::string &str, const std::string prefix)
Checks whether a given string starts with the prefix.