tdaq-develop-2025-02-12
FEDataManagerSupervisor.cc
1 #include "otsdaq/CoreSupervisors/FEDataManagerSupervisor.h"
2 
3 #include "../ARTDAQDataManager/ARTDAQDataManager.h"
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 #include "otsdaq/DataManager/DataManager.h"
6 #include "otsdaq/DataManager/DataManagerSingleton.h"
7 
8 // #include "otsdaq/FECore/FEProducerVInterface.h"
9 
10 using namespace ots;
11 
12 XDAQ_INSTANTIATOR_IMPL(FEDataManagerSupervisor)
13 
14 //==============================================================================
15 FEDataManagerSupervisor::FEDataManagerSupervisor(xdaq::ApplicationStub* s,
16  bool artdaqDataManager)
17  : FESupervisor(s)
18 {
19  __SUP_COUT__ << "Constructor." << __E__;
20 
21  // WARNING THE ORDER IS IMPORTANT SINCE THE FIRST STATE MACHINE ELEMENT
22  // WILL BE CALLED FIRST DURING TRANSITION!!!!!
23 
24  // the FE Interfaces Manager is added first, and then the Data Manager
25  // So on FSM transitions, front-ends will transition first.
26 
27  // FEVInterfacesManager gets added in FESupervisor constructor
28  __SUP_COUTV__(CoreSupervisorBase::theStateMachineImplementation_.size());
29 
30  //
31  // CoreSupervisorBase::theStateMachineImplementation_.push_back(
32  // new FEVInterfacesManager(
33  // CorePropertySupervisorBase::getContextTreeNode(),
34  // CorePropertySupervisorBase::supervisorConfigurationPath_
35  // )
36  // );
37 
38  if(artdaqDataManager)
39  {
40  __SUP_COUT__ << "Adding ARTDAQ Data Manager now...!" << __E__;
41  CoreSupervisorBase::theStateMachineImplementation_.push_back(
42  DataManagerSingleton::getInstance<ARTDAQDataManager>(
43  CorePropertySupervisorBase::getContextTreeNode(),
44  CorePropertySupervisorBase::getSupervisorConfigurationPath(),
45  CorePropertySupervisorBase::getSupervisorUID()));
46  }
47  else
48  {
49  __SUP_COUT__ << "Adding Data Manager now...!" << __E__;
50  CoreSupervisorBase::theStateMachineImplementation_.push_back(
51  DataManagerSingleton::getInstance<DataManager>(
52  CorePropertySupervisorBase::getContextTreeNode(),
53  CorePropertySupervisorBase::getSupervisorConfigurationPath(),
54  CorePropertySupervisorBase::getSupervisorUID()));
55  }
56 
57  extractDataManager();
58 
59  __SUP_COUT__ << "Constructed." << __E__;
60 } // end constructor()
61 
62 //==============================================================================
63 FEDataManagerSupervisor::~FEDataManagerSupervisor(void)
64 {
65  __SUP_COUT__ << "Destroying..." << __E__;
66 
67  // theStateMachineImplementation_ is reset and the object it points to deleted in
68  // ~CoreSupervisorBase() This destructor must happen before the CoreSupervisor
69  // destructor
70 
71  DataManagerSingleton::deleteInstance(CoreSupervisorBase::getSupervisorUID());
72  theStateMachineImplementation_.pop_back();
73 
74  __SUP_COUT__ << "Destructed." << __E__;
75 } // end destructor()
76 
77 //==============================================================================
81 void FEDataManagerSupervisor::transitionConfiguring(toolbox::Event::Reference e)
82 {
83  __SUP_COUT__ << "transitionConfiguring" << __E__;
84 
85  theDataManager_->parentSupervisorHasFrontends_ = true;
86 
87  // Data Manager needs to be configured (instantiate buffers)
88  // before FEVinterfaceManager configures (creates interfaces)
89 
90  if(theStateMachineImplementation_.size() != 2)
91  {
92  __SUP_SS__ << "State machine size is not 2! It is "
93  << theStateMachineImplementation_.size() << ". What happened??"
94  << __E__;
95  __SUP_SS_THROW__;
96  }
97 
98  VStateMachine* p = theStateMachineImplementation_[0];
99  theStateMachineImplementation_[0] = theStateMachineImplementation_[1];
100  theStateMachineImplementation_[1] = p;
101 
102  CoreSupervisorBase::transitionConfiguring(e);
103 
104  { // print buffer status
105  __SUP_SS__;
106  // theDataManager_->dumpStatus((std::ostream*)&ss);
107  std::cout << ss.str() << __E__;
108  }
109 
110  // At this point the buffers have been made with producers and consumers
111  // then the FEs (including FEProducers) were made.
112  // Producers (including FEProducers) and Consumers attach to their DataManager
113  // Buffer during their construction.
114 
115  // revert state machine order back
116  theStateMachineImplementation_[1] = theStateMachineImplementation_[0];
117  theStateMachineImplementation_[0] = p;
118 
119 } // end transitionConfiguring()
120 
121 //==============================================================================
126 void FEDataManagerSupervisor::transitionStarting(toolbox::Event::Reference e)
127 {
128  __SUP_COUT__ << "transitionStarting" << __E__;
129 
130  // Data Manager needs to be started (start buffers)
131  // before FEVinterfaceManager starts (interfaces write)
132 
133  if(theStateMachineImplementation_.size() != 2)
134  {
135  __SUP_SS__ << "State machine size is not 2! It is "
136  << theStateMachineImplementation_.size() << ". What happened??"
137  << __E__;
138  }
139 
140  VStateMachine* p = theStateMachineImplementation_[0];
141  theStateMachineImplementation_[0] = theStateMachineImplementation_[1];
142  theStateMachineImplementation_[1] = p;
143 
144  CoreSupervisorBase::transitionStarting(e);
145 
146  // revert state machine order back
147  theStateMachineImplementation_[1] = theStateMachineImplementation_[0];
148  theStateMachineImplementation_[0] = p;
149 
150 } // end transitionStarting()
151 
152 //==============================================================================
157 void FEDataManagerSupervisor::transitionResuming(toolbox::Event::Reference e)
158 {
159  __SUP_COUT__ << "transitionStarting" << __E__;
160 
161  // Data Manager needs to be resumed (resume buffers)
162  // before FEVinterfaceManager resumes (interfaces write)
163 
164  if(theStateMachineImplementation_.size() != 2)
165  {
166  __SUP_SS__ << "State machine size is not 2! It is "
167  << theStateMachineImplementation_.size() << ". What happened??"
168  << __E__;
169  }
170 
171  VStateMachine* p = theStateMachineImplementation_[0];
172  theStateMachineImplementation_[0] = theStateMachineImplementation_[1];
173  theStateMachineImplementation_[1] = p;
174 
175  CoreSupervisorBase::transitionResuming(e);
176 
177  // revert state machine order back
178  theStateMachineImplementation_[1] = theStateMachineImplementation_[0];
179  theStateMachineImplementation_[0] = p;
180 
181 } // end transitionResuming()
182 
183 //==============================================================================
191 DataManager* FEDataManagerSupervisor::extractDataManager()
192 {
193  theDataManager_ = 0;
194 
195  for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i)
196  {
197  try
198  {
199  theDataManager_ =
200  dynamic_cast<DataManager*>(theStateMachineImplementation_[i]);
201  if(!theDataManager_)
202  {
203  // dynamic_cast returns null pointer on failure
204  throw(std::runtime_error(""));
205  }
206  __SUP_COUT__ << "State Machine " << i << " WAS of type DataManager" << __E__;
207 
208  break;
209  }
210  catch(...)
211  {
212  __SUP_COUT__ << "State Machine " << i << " was NOT of type DataManager"
213  << __E__;
214  }
215  }
216 
217  __SUP_COUT__ << "theDataManager pointer = " << theDataManager_ << __E__;
218 
219  return theDataManager_;
220 } // end extractDataManager()
bool parentSupervisorHasFrontends_
Definition: DataManager.h:99
static void deleteInstance(std::string instanceUID)
There is no way I can realize that the singletonized class has been deleted!
virtual void transitionConfiguring(toolbox::Event::Reference e) override
virtual void transitionStarting(toolbox::Event::Reference e) override
virtual void transitionResuming(toolbox::Event::Reference e) override