MSMeanData_HBEFA Class Reference

#include <MSMeanData_HBEFA.h>

Inheritance diagram for MSMeanData_HBEFA:

MSMeanData MSDetectorFileOutput

Detailed Description

Emission data collector for edges/lanes.

This structure does not contain the data itself, it is stored within MSLaneMeanDataValues-MoveReminder objects. This class is used to build the output, optionally, in the case of edge-based dump, aggregated over the edge's lanes.

Todo:
consider error-handling on write (using IOError)

Definition at line 60 of file MSMeanData_HBEFA.h.


Public Member Functions

void init (const std::vector< MSEdge * > &edges, const bool withInternal) throw ()
 Adds the value collectors to all relevant edges.
 MSMeanData_HBEFA (const std::string &id, const SUMOTime dumpBegin, const SUMOTime dumpEnd, const bool useLanes, const bool withEmpty, const bool trackVehicles, const SUMOReal minSamples, const SUMOReal maxTravelTime, const std::set< std::string > vTypes) throw ()
 Constructor.
void update () throw ()
 Updates the detector.
virtual ~MSMeanData_HBEFA () throw ()
 Destructor.
Virtual methods to implement by derived classes
virtual void reset ()
 Resets collected values.
Methods inherited from MSDetectorFileOutput.
void writeXMLDetectorProlog (OutputDevice &dev) const throw (IOError)
 Opens the XML-output using "netstats" as root element.
void writeXMLOutput (OutputDevice &dev, SUMOTime startTime, SUMOTime stopTime) throw (IOError)
 Writes collected values into the given stream.

Protected Member Functions

MSMeanData::MeanDataValuescreateValues (MSLane *const lane, const bool doAdd) const throw (IOError)
 Create an instance of MeanDataValues.
void resetOnly (SUMOTime stopTime) throw ()
 Resets network value in order to allow processing of the next interval.
virtual void writeEdge (OutputDevice &dev, const std::vector< MeanDataValues * > &edgeValues, MSEdge *edge, SUMOTime startTime, SUMOTime stopTime) throw (IOError)
 Writes edge values into the given stream.
bool writePrefix (OutputDevice &dev, const MeanDataValues &values, const std::string prefix) const throw (IOError)
 Checks for emptiness and writes prefix into the given stream.

Protected Attributes

const SUMOReal myMaxTravelTime
 the maximum travel time to write
const SUMOReal myMinSamples
 the minimum sample seconds
const std::set< std::string > myVehicleTypes
 The vehicle types to look for (empty means all).

Private Member Functions

 MSMeanData_HBEFA (const MSMeanData_HBEFA &)
 Invalidated copy constructor.
MSMeanData_HBEFAoperator= (const MSMeanData_HBEFA &)
 Invalidated assignment operator.

Data Structures

class  MSLaneMeanDataValues
 Data structure for mean (aggregated) edge/lane values. More...

Constructor & Destructor Documentation

MSMeanData_HBEFA::MSMeanData_HBEFA ( const std::string &  id,
const SUMOTime  dumpBegin,
const SUMOTime  dumpEnd,
const bool  useLanes,
const bool  withEmpty,
const bool  trackVehicles,
const SUMOReal  minSamples,
const SUMOReal  maxTravelTime,
const std::set< std::string >  vTypes 
) throw ()

Constructor.

Parameters:
[in] id The id of the detector
[in] dumpBegin Begin time of dump
[in] dumpEnd End time of dump
[in] useLanes Information whether lane-based or edge-based dump shall be generated
[in] withEmpty Information whether empty lanes/edges shall be written
[in] trackVehicles Information whether vehicles shall be tracked
[in] maxTravelTime the maximum travel time to use when calculating per vehicle output
[in] minSamples the minimum number of sample seconds before the values are valid
[in] vTypes the set of vehicle types to consider

Definition at line 162 of file MSMeanData_HBEFA.cpp.

00168         : MSMeanData(id, dumpBegin, dumpEnd, useLanes, withEmpty, trackVehicles, maxTravelTime, minSamples, vTypes) {
00169 }

MSMeanData_HBEFA::~MSMeanData_HBEFA (  )  throw () [virtual]

Destructor.

Definition at line 172 of file MSMeanData_HBEFA.cpp.

00172 {}

MSMeanData_HBEFA::MSMeanData_HBEFA ( const MSMeanData_HBEFA  )  [private]

Invalidated copy constructor.


Member Function Documentation

MSMeanData::MeanDataValues * MSMeanData_HBEFA::createValues ( MSLane *const   lane,
const bool  doAdd 
) const throw (IOError) [protected, virtual]

Create an instance of MeanDataValues.

Parameters:
[in] lane The lane to create for
[in] doAdd whether to add the values as reminder to the lane

Implements MSMeanData.

Definition at line 176 of file MSMeanData_HBEFA.cpp.

References MSMeanData::myVehicleTypes.

00176                                                                                          {
00177     return new MSLaneMeanDataValues(lane, doAdd, &myVehicleTypes, this);
00178 }

void MSMeanData::init ( const std::vector< MSEdge * > &  edges,
const bool  withInternal 
) throw () [inherited]

Adds the value collectors to all relevant edges.

Parameters:
[in] edges the edges to use
[in] withInternal Information whether internal lanes/edges shall be written

Definition at line 204 of file MSMeanData.cpp.

References MSMeanData::createValues(), MSEdge::EDGEFUNCTION_INTERNAL, MSMeanData::MeanDataValueTracker::MeanDataValueTracker(), MSMeanData::myAmEdgeBased, MSMeanData::myEdges, MSMeanData::myMeasures, MSMeanData::myTrackVehicles, and MSMeanData::MeanDataValues::myVehicleTypes.

Referenced by NLDetectorBuilder::createEdgeLaneMeanData().

00204                                                                                  {
00205     for (std::vector<MSEdge*>::const_iterator e = edges.begin(); e != edges.end(); ++e) {
00206         if (withInternal || (*e)->getPurpose() != MSEdge::EDGEFUNCTION_INTERNAL) {
00207             myEdges.push_back(*e);
00208             myMeasures.push_back(std::vector<MeanDataValues*>());
00209 #ifdef HAVE_MESOSIM
00210             if (MSGlobals::gUseMesoSim) {
00211                 MESegment *s = MSGlobals::gMesoNet->getSegmentForEdge(**e);
00212                 while (s!=0) {
00213                     myMeasures.back().push_back(createValues(0, false));
00214                     s->addDetector(myMeasures.back().back());
00215                     s = s->getNextSegment();
00216                 }
00217                 continue;
00218             }
00219 #endif
00220             if (myAmEdgeBased && myTrackVehicles) {
00221                 myMeasures.back().push_back(new MeanDataValueTracker(0, &myVehicleTypes, this));
00222             }
00223             const std::vector<MSLane*> &lanes = (*e)->getLanes();
00224             for (std::vector<MSLane*>::const_iterator lane = lanes.begin(); lane != lanes.end(); ++lane) {
00225                 if (myTrackVehicles) {
00226                     if (myAmEdgeBased) {
00227                         (*lane)->addMoveReminder(myMeasures.back().back());
00228                     } else {
00229                         myMeasures.back().push_back(new MeanDataValueTracker(*lane, &myVehicleTypes, this));
00230                     }
00231                 } else {
00232                     myMeasures.back().push_back(createValues(*lane, true));
00233                 }
00234             }
00235         }
00236     }
00237 }

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

Invalidated assignment operator.

virtual void MSDetectorFileOutput::reset (  )  [inline, virtual, inherited]

Resets collected values.

Please note that this is only a "hack" for coupled-tls-outputs.

See also:
Command_SaveTLCoupledLaneDet
Todo:
Reckeck/refactor

Reimplemented in MSE2Collector, MSE3Collector, and MSInductLoop.

Definition at line 97 of file MSDetectorFileOutput.h.

Referenced by Command_SaveTLCoupledLaneDet::execute().

00097 { }

void MSMeanData::resetOnly ( SUMOTime  stopTime  )  throw () [protected, inherited]

Resets network value in order to allow processing of the next interval.

Goes through the lists of edges and starts "resetOnly" for each edge.

Parameters:
[in] edge The last time step that is reported

Reimplemented in MSMeanData_Net.

Definition at line 244 of file MSMeanData.cpp.

References MSMeanData::myEdges, and MSMeanData::myMeasures.

Referenced by MSMeanData::writeXMLOutput().

00244                                                {
00245 #ifdef HAVE_MESOSIM
00246     if (MSGlobals::gUseMesoSim) {
00247         std::vector<MSEdge*>::iterator edge = myEdges.begin();
00248         for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i, ++edge) {
00249             MESegment *s = MSGlobals::gMesoNet->getSegmentForEdge(**edge);
00250             for (std::vector<MeanDataValues*>::const_iterator j=(*i).begin(); j!=(*i).end(); ++j) {
00251                 s->prepareMeanDataForWriting(*(*j), stopTime);
00252                 (*j)->reset();
00253                 s = s->getNextSegment();
00254             }
00255         }
00256         return;
00257     }
00258 #endif
00259     for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i) {
00260         for (std::vector<MeanDataValues*>::const_iterator j=(*i).begin(); j!=(*i).end(); ++j) {
00261             (*j)->reset();
00262         }
00263     }
00264 }

void MSMeanData::update (  )  throw () [inherited]

Updates the detector.

Definition at line 381 of file MSMeanData.cpp.

References MSMeanData::myMeasures.

00381                            {
00382     for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i) {
00383         const std::vector<MeanDataValues*> &lm = *i;
00384         for (std::vector<MeanDataValues*>::const_iterator j=lm.begin(); j!=lm.end(); ++j) {
00385             (*j)->update();
00386         }
00387     }
00388 }

void MSMeanData::writeEdge ( OutputDevice dev,
const std::vector< MeanDataValues * > &  edgeValues,
MSEdge edge,
SUMOTime  startTime,
SUMOTime  stopTime 
) throw (IOError) [protected, virtual, inherited]

Writes edge values into the given stream.

microsim: It is checked whether the dump shall be generated edge- or lane-wise. In the first case, the lane-data are collected and aggregated and written directly. In the second case, "writeLane" is used to write each lane's state.

Parameters:
[in] dev The output device to write the data into
[in] edgeValues List of this edge's value collectors
[in] edge The edge to write the dump of
[in] startTime First time step the data were gathered
[in] stopTime Last time step the data were gathered
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 268 of file MSMeanData.cpp.

References MSMeanData::MeanDataValues::addTo(), MSMeanData::createValues(), MSLane::getID(), MSMoveReminder::getLane(), MSLane::getLength(), MSMeanData::myAmEdgeBased, MSMeanData::myDumpEmpty, MSMeanData::myTrackVehicles, MSMeanData::MeanDataValues::reset(), SUMOReal, MSMeanData::MeanDataValues::write(), and MSMeanData::writePrefix().

Referenced by MSMeanData_Net::writeEdge(), and MSMeanData::writeXMLOutput().

00270                                                                                           {
00271     std::vector<MeanDataValues*>::const_iterator lane;
00272     if (!myAmEdgeBased) {
00273         bool writeCheck = myDumpEmpty;
00274         if (!writeCheck) {
00275             for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
00276                 if (!(*lane)->isEmpty()) {
00277                     writeCheck = true;
00278                     break;
00279                 }
00280             }
00281         }
00282         if (writeCheck) {
00283             dev.openTag("edge")<<" id=\""<<edge->getID()<<"\">\n";
00284         }
00285         for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
00286             MeanDataValues& meanData = **lane;
00287             if (writePrefix(dev, meanData, "<lane id=\""+meanData.getLane()->getID())) {
00288                 meanData.write(dev, stopTime - startTime,
00289                                1.f, meanData.getLane()->getLength());
00290             }
00291             if (myTrackVehicles) {
00292                 ((MeanDataValueTracker&)meanData).clearFirst();
00293             } else {
00294                 meanData.reset();
00295             }
00296         }
00297         if (writeCheck) {
00298             dev.closeTag();
00299         }
00300     } else {
00301         if (myTrackVehicles) {
00302             MeanDataValues& meanData = **edgeValues.begin();
00303             if (writePrefix(dev, meanData, "<edge id=\""+edge->getID())) {
00304                 meanData.write(dev, stopTime - startTime,
00305                                (SUMOReal)edge->getLanes().size(), edge->getLanes()[0]->getLength());
00306             }
00307         } else {
00308             MeanDataValues* sumData = createValues(0, false);
00309             for (lane = edgeValues.begin(); lane != edgeValues.end(); ++lane) {
00310                 MeanDataValues& meanData = **lane;
00311                 meanData.addTo(*sumData);
00312                 meanData.reset();
00313             }
00314             if (writePrefix(dev, *sumData, "<edge id=\""+edge->getID())) {
00315                 sumData->write(dev, stopTime - startTime,
00316                                (SUMOReal)edge->getLanes().size(), edge->getLanes()[0]->getLength());
00317             }
00318             delete sumData;
00319         }
00320     }
00321 }

bool MSMeanData::writePrefix ( OutputDevice dev,
const MeanDataValues values,
const std::string  prefix 
) const throw (IOError) [protected, inherited]

Checks for emptiness and writes prefix into the given stream.

Parameters:
[in] dev The output device to write the data into
[in] values The values to check for emptiness
[in] prefix The xml prefix to write (mostly the lane / edge id)
Returns:
whether further output should be generated
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Definition at line 325 of file MSMeanData.cpp.

References MSMeanData::myDumpEmpty.

Referenced by MSMeanData_Net::writeEdge(), and MSMeanData::writeEdge().

00325                                                                                                                     {
00326     if (myDumpEmpty || !values.isEmpty()) {
00327         dev.indent() << prefix << "\" sampledSeconds=\"" << values.getSamples();
00328         return true;
00329     }
00330     return false;
00331 }

void MSMeanData::writeXMLDetectorProlog ( OutputDevice dev  )  const throw (IOError) [virtual, inherited]

Opens the XML-output using "netstats" as root element.

Parameters:
[in] dev The output device to write the root into
See also:
MSDetectorFileOutput::writeXMLDetectorProlog
Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Implements MSDetectorFileOutput.

Definition at line 375 of file MSMeanData.cpp.

00375                                                                          {
00376     dev.writeXMLHeader("netstats");
00377 }

void MSMeanData::writeXMLOutput ( OutputDevice dev,
SUMOTime  startTime,
SUMOTime  stopTime 
) throw (IOError) [virtual, inherited]

Writes collected values into the given stream.

At first, it is checked whether the values for the current interval shall be written. If not, a reset is performed, only, using "resetOnly". Otherwise, both the list of single-lane edges and the list of multi-lane edges are gone through and each edge is written using "writeEdge".

Parameters:
[in] dev The output device to write the data into
[in] startTime First time step the data were gathered
[in] stopTime Last time step the data were gathered
See also:
MSDetectorFileOutput::writeXMLOutput

write

Exceptions:
IOError If an error on writing occurs (!!! not yet implemented)

Implements MSDetectorFileOutput.

Definition at line 335 of file MSMeanData.cpp.

References DELTA_T, MIN2(), MSMeanData::myDumpBegin, MSMeanData::myDumpEnd, MSMeanData::myEdges, MSMeanData::myID, MSMeanData::myMeasures, MSMeanData::myPendingIntervals, MSMeanData::myTrackVehicles, MSMeanData::resetOnly(), time2string(), and MSMeanData::writeEdge().

00336                                                                                  {
00337     // check whether this dump shall be written for the current time
00338     size_t numReady = myDumpBegin < stopTime && myDumpEnd-DELTA_T >= startTime;
00339     if (myTrackVehicles && myDumpBegin < stopTime) {
00340         myPendingIntervals.push_back(std::make_pair(startTime, stopTime));
00341         numReady = myPendingIntervals.size();
00342         for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i) {
00343             for (std::vector<MeanDataValues*>::const_iterator j=(*i).begin(); j!=(*i).end(); ++j) {
00344                 numReady = MIN2(numReady, ((MeanDataValueTracker*)*j)->getNumReady());
00345                 if (numReady == 0) {
00346                     break;
00347                 }
00348             }
00349             if (numReady == 0) {
00350                 break;
00351             }
00352         }
00353     }
00354     if (numReady == 0) {
00355         resetOnly(stopTime);
00356     }
00357     while (numReady-- > 0) {
00358         if (!myPendingIntervals.empty()) {
00359             startTime = myPendingIntervals.front().first;
00360             stopTime = myPendingIntervals.front().second;
00361             myPendingIntervals.pop_front();
00362         }
00363         dev.openTag("interval")<<" begin=\""<<time2string(startTime)<<"\" end=\""<<
00364         time2string(stopTime)<<"\" "<<"id=\""<<myID<<"\">\n";
00365         std::vector<MSEdge*>::iterator edge = myEdges.begin();
00366         for (std::vector<std::vector<MeanDataValues*> >::const_iterator i=myMeasures.begin(); i!=myMeasures.end(); ++i, ++edge) {
00367             writeEdge(dev, (*i), *edge, startTime, stopTime);
00368         }
00369         dev.closeTag();
00370     }
00371 }


Field Documentation

const SUMOReal MSMeanData::myMaxTravelTime [protected, inherited]

const SUMOReal MSMeanData::myMinSamples [protected, inherited]

const std::set<std::string> MSMeanData::myVehicleTypes [protected, inherited]

The vehicle types to look for (empty means all).

Definition at line 386 of file MSMeanData.h.

Referenced by MSMeanData_Net::createValues(), createValues(), and MSMeanData_Harmonoise::createValues().


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

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