MSDetectorControl Class Reference

#include <MSDetectorControl.h>


Detailed Description

Detectors container; responsible for string and output generation.

Definition at line 63 of file MSDetectorControl.h.


Public Types

Definitions of containers for different detector types
typedef NamedObjectCont
< MSE2Collector * > 
E2Dict
 Map of MSE2Collector by ID.
typedef std::vector
< MSE2Collector * > 
E2Vect
 Vector of MSE2Collector.
typedef NamedObjectCont
< MS_E2_ZS_CollectorOverLanes * > 
E2ZSOLDict
 Map of MS_E2_ZS_CollectorOverLanes by ID.
typedef std::vector
< MS_E2_ZS_CollectorOverLanes * > 
E2ZSOLVect
 Vector of MS_E2_ZS_CollectorOverLanes.
typedef NamedObjectCont
< MSE3Collector * > 
E3Dict
 Map of MSE3Collector by ID.
typedef std::vector
< MSE3Collector * > 
E3Vect
 Vector of MSE3Collector.
typedef NamedObjectCont
< MSInductLoop * > 
LoopDict
 Map of MSInductLoop by ID.
typedef std::vector
< MSInductLoop * > 
LoopVect
 Vector of MSInductLoop.
typedef NamedObjectCont
< MSRouteProbe * > 
RouteProbeDict
 Map of MSRouteProbe by ID.

Public Member Functions

void addDetectorAndInterval (MSDetectorFileOutput *det, OutputDevice *device, SUMOTime interval, SUMOTime begin=-1) throw ()
 Adds one of the detectors as a new MSDetectorFileOutput.
void close (SUMOTime step) throw (IOError)
 Closes the detector outputs.
 MSDetectorControl () throw ()
 Constructor.
void updateDetectors (SUMOTime step) throw ()
 Computes detector values.
void writeOutput (SUMOTime step, bool closing) throw (IOError)
 Writes the output to be generated within the given time step.
 ~MSDetectorControl () throw ()
 Destructor.
Methods for adding detectors that are coupled to an own OutputDevice
void add (MSMeanData_Harmonoise *mn) throw ()
 Adds a harmonoise mean data object.
void add (MS_E2_ZS_CollectorOverLanes *e2ol) throw (ProcessError)
 Adds a e2ol-detector coupled to an external output impulse giver.
void add (MSE2Collector *e2) throw (ProcessError)
 Adds a e2-detector coupled to an extern output impulse giver.
Methods for adding detectors that are coupled to an own OutputDevice
void add (MSRouteProbe *vp, OutputDevice &device, SUMOTime frequency, SUMOTime begin) throw (ProcessError)
 Adds a routeprobe into the containers.
void add (MSE3Collector *e3, OutputDevice &device, int splInterval) throw (ProcessError)
 Adds a e3-detector into the containers.
void add (MS_E2_ZS_CollectorOverLanes *e2ol, OutputDevice &device, int splInterval) throw (ProcessError)
 Adds a e2ol-detector into the containers.
void add (MSE2Collector *e2, OutputDevice &device, int splInterval) throw (ProcessError)
 Adds a e2-detector into the containers.
void add (MSInductLoop *il, OutputDevice &device, int splInterval) throw (ProcessError)
 Adds a induction loop into the containers.
Methods for retrieving detectors
const E2DictgetE2Detectors () const throw ()
 Returns the MSE2Detector-container.
const E2ZSOLDictgetE2OLDetectors () const throw ()
 Returns the MS_E2_ZS_CollectorOverLanes-container.
const E3DictgetE3Detectors () const throw ()
 Returns the MSE3Detector-container.
const LoopDictgetInductLoops () const throw ()
 Returns the MSInductLoop-container.

Protected Types

Structures needed for assigning detectors to intervals
typedef std::pair
< MSDetectorFileOutput
*, OutputDevice * > 
DetectorFilePair
 A pair of a Detector with it's associated file-stream.
typedef std::vector
< DetectorFilePair
DetectorFileVec
 Container holding DetectorFilePair (with the same interval).
typedef std::map< IntervalsKey,
DetectorFileVec
Intervals
 Association of intervals to DetectorFilePair containers.
typedef std::pair< SUMOTime,
SUMOTime
IntervalsKey
 Definition of the interval key.

Protected Attributes

std::vector
< MSMeanData_Harmonoise * > 
myHarmonoiseDetectors
 List of harmonoise detectors.
Intervals myIntervals
 Map that hold DetectorFileVec for given intervals.
std::map< IntervalsKey, SUMOTimemyLastCalls
 The map that holds the last call for each sample interval.
Dictionaries of different detector types
E2Dict myE2Detectors
 MSE2Collector dictionary.
E2ZSOLDict myE2OverLanesDetectors
 MS_E2_ZS_CollectorOverLanes dictionary.
E3Dict myE3Detectors
 MSE3Collector dictionary.
LoopDict myLoops
 MSInductLoop dictionary.
RouteProbeDict myRouteProbeDetectors
 MSRouteProbe dictionary.

Private Member Functions

 MSDetectorControl (const MSDetectorControl &)
 Invalidated copy constructor.
MSDetectorControloperator= (const MSDetectorControl &)
 Invalidated assignment operator.

Data Structures

struct  detectorEquals
 Returns true if detectors are equal. More...

Member Typedef Documentation

A pair of a Detector with it's associated file-stream.

Definition at line 397 of file MSDetectorControl.h.

typedef std::vector< DetectorFilePair > MSDetectorControl::DetectorFileVec [protected]

Container holding DetectorFilePair (with the same interval).

Definition at line 400 of file MSDetectorControl.h.

Map of MSE2Collector by ID.

Definition at line 77 of file MSDetectorControl.h.

typedef std::vector< MSE2Collector*> MSDetectorControl::E2Vect

Vector of MSE2Collector.

Definition at line 98 of file MSDetectorControl.h.

Map of MS_E2_ZS_CollectorOverLanes by ID.

Definition at line 83 of file MSDetectorControl.h.

Vector of MS_E2_ZS_CollectorOverLanes.

Definition at line 104 of file MSDetectorControl.h.

Map of MSE3Collector by ID.

Definition at line 80 of file MSDetectorControl.h.

typedef std::vector< MSE3Collector*> MSDetectorControl::E3Vect

Vector of MSE3Collector.

Definition at line 101 of file MSDetectorControl.h.

typedef std::map< IntervalsKey, DetectorFileVec > MSDetectorControl::Intervals [protected]

Association of intervals to DetectorFilePair containers.

Definition at line 406 of file MSDetectorControl.h.

typedef std::pair<SUMOTime, SUMOTime> MSDetectorControl::IntervalsKey [protected]

Definition of the interval key.

Definition at line 403 of file MSDetectorControl.h.

Map of MSInductLoop by ID.

Definition at line 74 of file MSDetectorControl.h.

typedef std::vector< MSInductLoop*> MSDetectorControl::LoopVect

Vector of MSInductLoop.

Definition at line 95 of file MSDetectorControl.h.

Map of MSRouteProbe by ID.

Definition at line 86 of file MSDetectorControl.h.


Constructor & Destructor Documentation

MSDetectorControl::MSDetectorControl (  )  throw ()

Constructor.

Definition at line 57 of file MSDetectorControl.cpp.

00057                                              {
00058 }

MSDetectorControl::~MSDetectorControl (  )  throw ()

Destructor.

Deletes all stored detectors.

Definition at line 61 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::clear(), myE2Detectors, myE2OverLanesDetectors, myE3Detectors, myLoops, and myRouteProbeDetectors.

00061                                               {
00062 #ifdef HAVE_MESOSIM
00063     myMesoLoops.clear();
00064 #endif
00065     myLoops.clear();
00066 #ifdef _MESSAGES
00067 #ifdef _DEBUG
00068     std::cout << "MSDetectorControl: clearing myMsgLoops" << std::endl;
00069 #endif
00070     myMsgLoops.clear();
00071 #endif
00072     myE2Detectors.clear();
00073     myE3Detectors.clear();
00074     myE2OverLanesDetectors.clear();
00075     myRouteProbeDetectors.clear();
00076 }

MSDetectorControl::MSDetectorControl ( const MSDetectorControl  )  [private]

Invalidated copy constructor.


Member Function Documentation

void MSDetectorControl::add ( MSMeanData_Harmonoise mn  )  throw ()

Adds a harmonoise mean data object.

The detector is pushed into the internal list.

Please note, that the detector control does NOT get responsible for the detector.

Parameters:
[in] mn The mean noise-detector to add

Definition at line 152 of file MSDetectorControl.cpp.

References myHarmonoiseDetectors.

00152                                                         {
00153     myHarmonoiseDetectors.push_back(mn);
00154 }

void MSDetectorControl::add ( MS_E2_ZS_CollectorOverLanes e2ol  )  throw (ProcessError)

Adds a e2ol-detector coupled to an external output impulse giver.

The detector is tried to be added into "myE2OverLanesDetectors". If the detector is already known (the id was already used for a similar detector), a ProcessError is thrown.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] e2ol The e2ol-detector to add
Exceptions:
ProcessError If the detector is already known

Definition at line 143 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), and myE2OverLanesDetectors.

00143                                                                             {
00144     // insert object into dictionary
00145     if (! myE2OverLanesDetectors.add(e2ol->getID(), e2ol)) {
00146         throw ProcessError("e2-overlanes-detector '" + e2ol->getID() + "' could not be build;\n (declared twice?)");
00147     }
00148 }

void MSDetectorControl::add ( MSE2Collector e2  )  throw (ProcessError)

Adds a e2-detector coupled to an extern output impulse giver.

The detector is tried to be added into "myE2Detectors". If the detector is already known (the id was already used for a similar detector), a ProcessError is thrown.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] e2 The e2-detector to add
Exceptions:
ProcessError If the detector is already known

Definition at line 134 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), and myE2Detectors.

00134                                                             {
00135     // insert object into dictionary
00136     if (! myE2Detectors.add(e2->getID(), e2)) {
00137         throw ProcessError("e2-detector '" + e2->getID() + "' could not be build;\n (declared twice?)");
00138     }
00139 }

void MSDetectorControl::add ( MSRouteProbe vp,
OutputDevice device,
SUMOTime  frequency,
SUMOTime  begin 
) throw (ProcessError)

Adds a routeprobe into the containers.

The Detector2File-mechanism is instantiated for the detector.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] vp The routeprobe to add
[in] device The device the routeprobe uses
[in] frequency The frequency of calling this routeprobe
[in] begin The begin of the first interval
Exceptions:
ProcessError If the detector is already known

Definition at line 168 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), addDetectorAndInterval(), and myRouteProbeDetectors.

00169                                                                                {
00170     // insert object into dictionary
00171     if (! myRouteProbeDetectors.add(vp->getID(), vp)) {
00172         throw ProcessError("routeprobe '" + vp->getID() + "' could not be build;\n (declared twice?)");
00173     }
00174     addDetectorAndInterval(vp, &device, frequency, begin);
00175 }

void MSDetectorControl::add ( MSE3Collector e3,
OutputDevice device,
int  splInterval 
) throw (ProcessError)

Adds a e3-detector into the containers.

The detector is tried to be added into "myE3Detectors". If the detector is already known (the id was already used for a similar detector), a ProcessError is thrown.

Otherwise, the Detector2File-mechanism is instantiated for the detector.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] e3 The e3-detector to add
[in] device The device the e3-detector uses
[in] splInterval The sample interval of the e3-detector
Exceptions:
ProcessError If the detector is already known

Definition at line 158 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), addDetectorAndInterval(), and myE3Detectors.

00158                                                                                                    {
00159     // insert object into dictionary
00160     if (! myE3Detectors.add(e3->getID(), e3)) {
00161         throw ProcessError("e3-detector '" + e3->getID() + "' could not be build;\n (declared twice?)");
00162     }
00163     addDetectorAndInterval(e3, &device, splInterval);
00164 }

void MSDetectorControl::add ( MS_E2_ZS_CollectorOverLanes e2ol,
OutputDevice device,
int  splInterval 
) throw (ProcessError)

Adds a e2ol-detector into the containers.

The detector is tried to be added into "myE2OverLanesDetectors". If the detector is already known (the id was already used for a similar detector), a ProcessError is thrown.

Otherwise, the Detector2File-mechanism is instantiated for the detector.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] e2ol The e2ol-detector to add
[in] device The device the e2ol-detector uses
[in] splInterval The sample interval of the e2ol-detector
Exceptions:
ProcessError If the detector is already known

Definition at line 124 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), addDetectorAndInterval(), and myE2OverLanesDetectors.

00124                                                                                                                    {
00125     // insert object into dictionary
00126     if (! myE2OverLanesDetectors.add(e2ol->getID(), e2ol)) {
00127         throw ProcessError("e2-overlanes-detector '" + e2ol->getID() + "' could not be build;\n (declared twice?)");
00128     }
00129     addDetectorAndInterval(e2ol, &device, splInterval);
00130 }

void MSDetectorControl::add ( MSE2Collector e2,
OutputDevice device,
int  splInterval 
) throw (ProcessError)

Adds a e2-detector into the containers.

The detector is tried to be added into "myE2Detectors". If the detector is already known (the id was already used for a similar detector), a ProcessError is thrown.

Otherwise, the Detector2File-mechanism is instantiated for the detector.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] e2 The e2-detector to add
[in] device The device the e2-detector uses
[in] splInterval The sample interval of the e2-detector
Exceptions:
ProcessError If the detector is already known

Definition at line 114 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), addDetectorAndInterval(), and myE2Detectors.

00114                                                                                                    {
00115     // insert object into dictionary
00116     if (! myE2Detectors.add(e2->getID(), e2)) {
00117         throw ProcessError("e2-detector '" + e2->getID() + "' could not be build;\n (declared twice?)");
00118     }
00119     addDetectorAndInterval(e2, &device, splInterval);
00120 }

void MSDetectorControl::add ( MSInductLoop il,
OutputDevice device,
int  splInterval 
) throw (ProcessError)

Adds a induction loop into the containers.

The detector is tried to be added into "myLoops". If the detector is already known (the id was already used for a similar detector), a ProcessError is thrown.

Otherwise, the Detector2File-mechanism is instantiated for the detector.

Please note, that the detector control gets responsible for the detector.

Parameters:
[in] il The induction loop to add
[in] device The device the loop uses
[in] splInterval The sample interval of the loop
Exceptions:
ProcessError If the detector is already known

Definition at line 104 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::add(), addDetectorAndInterval(), and myLoops.

Referenced by NLDetectorBuilder::buildE2Detector(), NLDetectorBuilder::buildInductLoop(), NLDetectorBuilder::buildRouteProbe(), NLDetectorBuilder::endE3Detector(), and MSMeanData_Harmonoise::MSMeanData_Harmonoise().

00104                                                                                                   {
00105     // insert object into dictionary
00106     if (! myLoops.add(il->getID(), il)) {
00107         throw ProcessError("induct loop '" + il->getID() + "' could not be build;\n (declared twice?)");
00108     }
00109     addDetectorAndInterval(il, &device, splInterval);
00110 }

void MSDetectorControl::addDetectorAndInterval ( MSDetectorFileOutput det,
OutputDevice device,
SUMOTime  interval,
SUMOTime  begin = -1 
) throw ()

Adds one of the detectors as a new MSDetectorFileOutput.

This method is used within the TrafficTower-extension of SUMO

Parameters:
[in] det The generator to add
[in] device The device to use
[in] interval The sample interval to use
[in] begin The start of the first sample interval to use

Definition at line 233 of file MSDetectorControl.cpp.

References OptionsCont::getOptions(), myIntervals, myLastCalls, string2time(), and WRITE_WARNING.

Referenced by add(), and NLDetectorBuilder::createEdgeLaneMeanData().

00236                                 {
00237     if (begin == -1) {
00238         begin = string2time(OptionsCont::getOptions().getString("begin"));
00239     }
00240     IntervalsKey key = std::make_pair(interval, begin);
00241     Intervals::iterator it = myIntervals.find(key);
00242     // Add command for given key only once to MSEventControl...
00243     if (it == myIntervals.end()) {
00244         DetectorFileVec detAndFileVec;
00245         detAndFileVec.push_back(std::make_pair(det, device));
00246         myIntervals.insert(std::make_pair(key, detAndFileVec));
00247         myLastCalls[key] = begin;
00248     } else {
00249         DetectorFileVec& detAndFileVec = it->second;
00250         if (find_if(detAndFileVec.begin(), detAndFileVec.end(), bind2nd(detectorEquals(), det)) == detAndFileVec.end()) {
00251             detAndFileVec.push_back(std::make_pair(det, device));
00252         } else {
00253             // detector already in container. Don't add several times
00254             WRITE_WARNING("MSDetector2File::addDetectorAndInterval: detector already in container. Ignoring.");
00255             return;
00256         }
00257     }
00258     det->writeXMLDetectorProlog(*device);
00259 }

void MSDetectorControl::close ( SUMOTime  step  )  throw (IOError)

Closes the detector outputs.

Goes through the intervals to write and writes the last step using the current simulation time as end.

Parameters:
[in] step The time step (the simulation has ended at)
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 80 of file MSDetectorControl.cpp.

References myIntervals, and writeOutput().

Referenced by MSNet::closeSimulation().

00080                                                      {
00081     // flush the last values
00082     writeOutput(step, true);
00083     // [...] files are closed on another place [...]
00084     myIntervals.clear();
00085 }

const E2Dict& MSDetectorControl::getE2Detectors (  )  const throw () [inline]

Returns the MSE2Detector-container.

Returns:
The container of MSE2Detector

Definition at line 334 of file MSDetectorControl.h.

References myE2Detectors.

Referenced by GUINet::initDetectors().

00334                                                  {
00335         return myE2Detectors;
00336     }

const E2ZSOLDict& MSDetectorControl::getE2OLDetectors (  )  const throw () [inline]

Returns the MS_E2_ZS_CollectorOverLanes-container.

Returns:
The container of MS_E2_ZS_CollectorOverLanes

Definition at line 352 of file MSDetectorControl.h.

References myE2OverLanesDetectors.

Referenced by GUINet::initDetectors().

00352                                                        {
00353         return myE2OverLanesDetectors;
00354     }

const E3Dict& MSDetectorControl::getE3Detectors (  )  const throw () [inline]

Returns the MSE3Detector-container.

Returns:
The container of MSE3Detector

Definition at line 343 of file MSDetectorControl.h.

References myE3Detectors.

Referenced by GUINet::initDetectors(), and TraCIServerAPI_MeMeDetector::processGet().

00343                                                  {
00344         return myE3Detectors;
00345     }

const LoopDict& MSDetectorControl::getInductLoops (  )  const throw () [inline]

Returns the MSInductLoop-container.

Returns:
The container of MSInductLoops

Definition at line 325 of file MSDetectorControl.h.

References myLoops.

Referenced by GUINet::initDetectors(), and TraCIServerAPI_InductionLoop::processGet().

00325                                                    {
00326         return myLoops;
00327     }

MSDetectorControl& MSDetectorControl::operator= ( const MSDetectorControl  )  [private]

Invalidated assignment operator.

void MSDetectorControl::updateDetectors ( SUMOTime  step  )  throw ()

Computes detector values.

Some detectors need to be touched each time step in order to compute values from the vehicles stored in their containers. This method goes through all of these detectors and forces a recomputation of the values.

The following detector types need an update:

Definition at line 194 of file MSDetectorControl.cpp.

References NamedObjectCont< T >::buildAndGetStaticVector(), myE2Detectors, myE3Detectors, and myHarmonoiseDetectors.

Referenced by MSNet::writeOutput().

00194                                                         {
00195     // update all detectors with inner containers
00196     // e2-detectors
00197     const std::vector<MSE2Collector*> &e2s = myE2Detectors.buildAndGetStaticVector();
00198     for (E2Vect::const_iterator i=e2s.begin(); i!=e2s.end(); ++i) {
00199         (*i)->update(step);
00200     }
00201     // e3-detectors
00202     const std::vector<MSE3Collector*> &e3s = myE3Detectors.buildAndGetStaticVector();
00203     for (E3Vect::const_iterator i=e3s.begin(); i!=e3s.end(); ++i) {
00204         (*i)->update(step);
00205     }
00206     // induct loops do not need to be updated...
00207     // vtypeprobes do not need to be updated...
00208     // ... but harmonoise
00209     for (std::vector<MSMeanData_Harmonoise*>::const_iterator i=myHarmonoiseDetectors.begin(); i!=myHarmonoiseDetectors.end(); ++i) {
00210         (*i)->update();
00211     }
00212 }

void MSDetectorControl::writeOutput ( SUMOTime  step,
bool  closing 
) throw (IOError)

Writes the output to be generated within the given time step.

Goes through the list of intervals. If one interval has ended within the given step or if the closing-flag is set and the output was not written in this step already, the writeXMLOutput method is called for all MSDetectorFileOutputs within this interval.

Parameters:
[in] step The current time step
[in] closing Whether the device is closed
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 215 of file MSDetectorControl.cpp.

References myIntervals, myLastCalls, and MSDetectorFileOutput::writeXMLOutput().

Referenced by close(), and MSNet::writeOutput().

00215                                                                          {
00216     for (Intervals::iterator i=myIntervals.begin(); i!=myIntervals.end(); ++i) {
00217         IntervalsKey interval = (*i).first;
00218         if (myLastCalls[interval] + interval.first <= step || (closing && myLastCalls[interval] < step)) {
00219             DetectorFileVec dfVec = (*i).second;
00220             SUMOTime startTime = myLastCalls[interval];
00221             // check whether at the end the output was already generated
00222             for (DetectorFileVec::iterator it = dfVec.begin(); it!=dfVec.end(); ++it) {
00223                 MSDetectorFileOutput* det = it->first;
00224                 det->writeXMLOutput(*(it->second), startTime, step);
00225             }
00226             myLastCalls[interval] = step;
00227         }
00228     }
00229 }


Field Documentation

MSE2Collector dictionary.

Definition at line 435 of file MSDetectorControl.h.

Referenced by add(), getE2Detectors(), updateDetectors(), and ~MSDetectorControl().

MS_E2_ZS_CollectorOverLanes dictionary.

Definition at line 441 of file MSDetectorControl.h.

Referenced by add(), getE2OLDetectors(), and ~MSDetectorControl().

MSE3Collector dictionary.

Definition at line 438 of file MSDetectorControl.h.

Referenced by add(), getE3Detectors(), updateDetectors(), and ~MSDetectorControl().

List of harmonoise detectors.

Definition at line 459 of file MSDetectorControl.h.

Referenced by add(), and updateDetectors().

Map that hold DetectorFileVec for given intervals.

Definition at line 453 of file MSDetectorControl.h.

Referenced by addDetectorAndInterval(), close(), and writeOutput().

The map that holds the last call for each sample interval.

Definition at line 456 of file MSDetectorControl.h.

Referenced by addDetectorAndInterval(), and writeOutput().

MSInductLoop dictionary.

Definition at line 432 of file MSDetectorControl.h.

Referenced by add(), getInductLoops(), and ~MSDetectorControl().

MSRouteProbe dictionary.

Definition at line 444 of file MSDetectorControl.h.

Referenced by add(), and ~MSDetectorControl().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:47 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6