source: XIOS/dev/dev_trunk_omp/src/filter/output_pin.cpp @ 1671

Last change on this file since 1671 was 1671, checked in by yushan, 5 years ago

MARK: branch merged with trunk @1663. One output graph file with output file names in file writer filter.

File size: 3.7 KB
Line 
1#include "output_pin.hpp"
2#include "exception.hpp"
3#include "workflow_graph.hpp"
4
5namespace xios
6{
7  COutputPin::COutputPin(CGarbageCollector& gc, bool manualTrigger /*= false*/, bool buildWorkflowGraph /* =false */)
8    : gc(gc)
9    , manualTrigger(manualTrigger)
10    , buildWorkflowGraph(buildWorkflowGraph)
11  {
12    if (buildWorkflowGraph)
13    {
14      filterId = InvalidableObject::count;
15      InvalidableObject::count++;
16    }
17  }
18
19  StdString COutputPin::GetName(void)
20  {
21    return StdString("Output pin");
22  }
23
24  void COutputPin::connectOutput(std::shared_ptr<CInputPin> inputPin, size_t inputSlot)
25  {
26    if (!inputPin)
27      ERROR("void COutputPin::connectOutput(CInputPin* inputPin, size_t inputSlot)",
28            "The input pin cannot be null.");
29
30    outputs.push_back(std::make_pair(inputPin, inputSlot));
31
32    if (canBeTriggered())
33      inputPin->setInputTrigger(inputSlot, this);
34  }
35
36  void COutputPin::onOutputReady(CDataPacketPtr packet)
37  {
38    if (!packet)
39      ERROR("void COutputPin::onOutputReady(CDataPacketPtr packet)",
40            "The packet cannot be null.");
41
42    if (buildWorkflowGraph)
43    {
44        if(CWorkflowGraph::mapFilterTimestamps_ptr==0) CWorkflowGraph::mapFilterTimestamps_ptr = new std::unordered_map <int, vector<Time> >;
45      if(CWorkflowGraph::timestamps_ptr==0) CWorkflowGraph::timestamps_ptr = new set<Time>;
46      (*CWorkflowGraph::mapFilterTimestamps_ptr)[this->getFilterId()].push_back(packet->timestamp);
47        CWorkflowGraph::timestamps_ptr->insert(packet->timestamp);
48    }
49
50    if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden
51    {
52      outputPackets[packet->timestamp] = packet;
53      gc.registerObject(this, packet->timestamp);
54    }
55    else
56      deliverOuput(packet);
57  }
58
59  void COutputPin::deliverOuput(CDataPacketPtr packet)
60  {
61    if (!packet)
62      ERROR("void COutputPin::deliverOuput(CDataPacketPtr packet)",
63            "The packet cannot be null.");
64
65    std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd;
66    for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
67      it->first->setInput(it->second, packet);
68  }
69
70  void COutputPin::trigger(Time timestamp)
71  {
72    if (manualTrigger) // Don't use canBeTriggered here, this function is virtual and can be overriden
73    {
74      std::map<Time, CDataPacketPtr>::iterator it = outputPackets.find(timestamp);
75      if (it != outputPackets.end())
76      {
77        gc.unregisterObject(this, timestamp);
78        deliverOuput(it->second);
79        outputPackets.erase(it);
80      }
81    }
82  }
83
84  bool COutputPin::canBeTriggered() const
85  {
86    return manualTrigger;
87  }
88
89  bool COutputPin::mustAutoTrigger() const
90  {
91    std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd;
92    for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
93    {
94      if (it->first->mustAutoTrigger())
95        return true;
96    }
97
98    return false;
99  }
100
101  void COutputPin::setOutputTriggers()
102  {
103    std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::iterator it, itEnd;
104    for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
105      it->first->setInputTrigger(it->second, this);
106  }
107
108  bool COutputPin::isDataExpected(const CDate& date) const
109  {
110    std::vector<std::pair<std::shared_ptr<CInputPin>, size_t> >::const_iterator it, itEnd;
111    for (it = outputs.begin(), itEnd = outputs.end(); it != itEnd; ++it)
112    {
113      if (it->first->isDataExpected(date))
114        return true;
115    }
116
117    return false;
118  }
119
120  void COutputPin::invalidate(Time timestamp)
121  {
122    outputPackets.erase(outputPackets.begin(), outputPackets.lower_bound(timestamp));
123  }
124
125  int COutputPin::getFilterId(void)
126  {
127    return filterId;
128  }
129
130} // namespace xios
Note: See TracBrowser for help on using the repository browser.