$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/CoreSupervisors/FEDataManagerSupervisor.h" 00002 00003 #include "../ARTDAQDataManager/ARTDAQDataManager.h" 00004 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00005 #include "otsdaq-core/DataManager/DataManager.h" 00006 #include "otsdaq-core/DataManager/DataManagerSingleton.h" 00007 00008 //#include "otsdaq-core/FECore/FEProducerVInterface.h" 00009 00010 using namespace ots; 00011 00012 XDAQ_INSTANTIATOR_IMPL(FEDataManagerSupervisor) 00013 00014 //======================================================================================================================== 00015 FEDataManagerSupervisor::FEDataManagerSupervisor(xdaq::ApplicationStub* s, 00016 bool artdaqDataManager) 00017 : FESupervisor(s) 00018 { 00019 __SUP_COUT__ << "Constructor." << __E__; 00020 00021 // WARNING THE ORDER IS IMPORTANT SINCE THE FIRST STATE MACHINE ELEMENT 00022 // WILL BE CALLED FIRST DURING TRANSITION!!!!! 00023 00024 // the FE Interfaces Manager is added first, and then the Data Manager 00025 // So on FSM transitions, front-ends will transition first. 00026 00027 // FEVInterfacesManager gets added in FESupervisor constructor 00028 __SUP_COUTV__(CoreSupervisorBase::theStateMachineImplementation_.size()); 00029 00030 // 00031 // CoreSupervisorBase::theStateMachineImplementation_.push_back( 00032 // new FEVInterfacesManager( 00033 // CorePropertySupervisorBase::getContextTreeNode(), 00034 // CorePropertySupervisorBase::supervisorConfigurationPath_ 00035 // ) 00036 // ); 00037 00038 if(artdaqDataManager) 00039 { 00040 __SUP_COUT__ << "Adding ARTDAQ Data Manager now...!" << __E__; 00041 CoreSupervisorBase::theStateMachineImplementation_.push_back( 00042 DataManagerSingleton::getInstance<ARTDAQDataManager>( 00043 CorePropertySupervisorBase::getContextTreeNode(), 00044 CorePropertySupervisorBase::getSupervisorConfigurationPath(), 00045 CorePropertySupervisorBase::getSupervisorUID())); 00046 } 00047 else 00048 { 00049 __SUP_COUT__ << "Adding Data Manager now...!" << __E__; 00050 CoreSupervisorBase::theStateMachineImplementation_.push_back( 00051 DataManagerSingleton::getInstance<DataManager>( 00052 CorePropertySupervisorBase::getContextTreeNode(), 00053 CorePropertySupervisorBase::getSupervisorConfigurationPath(), 00054 CorePropertySupervisorBase::getSupervisorUID())); 00055 } 00056 00057 extractDataManager(); 00058 00059 __SUP_COUT__ << "Constructed." << __E__; 00060 } // end constructor() 00061 00062 //======================================================================================================================== 00063 FEDataManagerSupervisor::~FEDataManagerSupervisor(void) 00064 { 00065 __SUP_COUT__ << "Destroying..." << __E__; 00066 00067 // theStateMachineImplementation_ is reset and the object it points to deleted in 00068 // ~CoreSupervisorBase() This destructor must happen before the CoreSupervisor 00069 // destructor 00070 00071 DataManagerSingleton::deleteInstance(CoreSupervisorBase::getSupervisorUID()); 00072 theStateMachineImplementation_.pop_back(); 00073 00074 __SUP_COUT__ << "Destructed." << __E__; 00075 } // end destructor() 00076 00077 //======================================================================================================================== 00078 // transitionConfiguring 00079 // swap order of state machine vector for configuring 00080 // so that DataManager gets configured first. 00081 void FEDataManagerSupervisor::transitionConfiguring(toolbox::Event::Reference e) 00082 { 00083 __SUP_COUT__ << "transitionConfiguring" << __E__; 00084 00085 // Data Manager needs to be configured (instantiate buffers) 00086 // before FEVinterfaceManager configures (creates interfaces) 00087 00088 if(theStateMachineImplementation_.size() != 2) 00089 { 00090 __SUP_SS__ << "State machine size is not 2! It is " 00091 << theStateMachineImplementation_.size() << ". What happened??" 00092 << __E__; 00093 __SUP_SS_THROW__; 00094 } 00095 00096 VStateMachine* p = theStateMachineImplementation_[0]; 00097 theStateMachineImplementation_[0] = theStateMachineImplementation_[1]; 00098 theStateMachineImplementation_[1] = p; 00099 00100 CoreSupervisorBase::transitionConfiguring(e); 00101 00102 { // print buffer status 00103 __SUP_SS__; 00104 // theDataManager_->dumpStatus((std::ostream*)&ss); 00105 std::cout << ss.str() << __E__; 00106 } 00107 00108 // At this point the buffers have been made with producers and consumers 00109 // then the FEs (including FEProducers) were made. 00110 // Producers (including FEProducers) and Consumers attach to their DataManager 00111 // Buffer during their construction. 00112 00113 // revert state machine order back 00114 theStateMachineImplementation_[1] = theStateMachineImplementation_[0]; 00115 theStateMachineImplementation_[0] = p; 00116 00117 } // end transitionConfiguring() 00118 00119 //======================================================================================================================== 00120 // transitionStarting 00121 // swap order of state machine vector for starting 00122 // so that DataManager gets configured first. 00123 // buffers need to be ready before FEs start writing to them 00124 void FEDataManagerSupervisor::transitionStarting(toolbox::Event::Reference e) 00125 { 00126 __SUP_COUT__ << "transitionStarting" << __E__; 00127 00128 // Data Manager needs to be started (start buffers) 00129 // before FEVinterfaceManager starts (interfaces write) 00130 00131 if(theStateMachineImplementation_.size() != 2) 00132 { 00133 __SUP_SS__ << "State machine size is not 2! It is " 00134 << theStateMachineImplementation_.size() << ". What happened??" 00135 << __E__; 00136 } 00137 00138 VStateMachine* p = theStateMachineImplementation_[0]; 00139 theStateMachineImplementation_[0] = theStateMachineImplementation_[1]; 00140 theStateMachineImplementation_[1] = p; 00141 00142 CoreSupervisorBase::transitionStarting(e); 00143 00144 // revert state machine order back 00145 theStateMachineImplementation_[1] = theStateMachineImplementation_[0]; 00146 theStateMachineImplementation_[0] = p; 00147 00148 } // end transitionStarting() 00149 00150 //======================================================================================================================== 00151 // transitionResuming 00152 // swap order of state machine vector for resuming 00153 // so that DataManager gets configured first. 00154 // buffers need to be ready before FEs start writing to them 00155 void FEDataManagerSupervisor::transitionResuming(toolbox::Event::Reference e) 00156 { 00157 __SUP_COUT__ << "transitionStarting" << __E__; 00158 00159 // Data Manager needs to be resumed (resume buffers) 00160 // before FEVinterfaceManager resumes (interfaces write) 00161 00162 if(theStateMachineImplementation_.size() != 2) 00163 { 00164 __SUP_SS__ << "State machine size is not 2! It is " 00165 << theStateMachineImplementation_.size() << ". What happened??" 00166 << __E__; 00167 } 00168 00169 VStateMachine* p = theStateMachineImplementation_[0]; 00170 theStateMachineImplementation_[0] = theStateMachineImplementation_[1]; 00171 theStateMachineImplementation_[1] = p; 00172 00173 CoreSupervisorBase::transitionResuming(e); 00174 00175 // revert state machine order back 00176 theStateMachineImplementation_[1] = theStateMachineImplementation_[0]; 00177 theStateMachineImplementation_[0] = p; 00178 00179 } // end transitionResuming() 00180 00181 //======================================================================================================================== 00182 // extractDataManager 00183 // 00184 // locates theDataManager in state machines vector and 00185 // returns 0 if not found. 00186 // 00187 // Note: this code assumes a CoreSupervisorBase has only one 00188 // DataManager in its vector of state machines 00189 DataManager* FEDataManagerSupervisor::extractDataManager() 00190 { 00191 theDataManager_ = 0; 00192 00193 for(unsigned int i = 0; i < theStateMachineImplementation_.size(); ++i) 00194 { 00195 try 00196 { 00197 theDataManager_ = 00198 dynamic_cast<DataManager*>(theStateMachineImplementation_[i]); 00199 if(!theDataManager_) 00200 { 00201 // dynamic_cast returns null pointer on failure 00202 __SUP_SS__ << "Dynamic cast failure!" << __E__; 00203 __SUP_COUT_ERR__ << ss.str(); 00204 __SUP_SS_THROW__; 00205 } 00206 __SUP_COUT__ << "State Machine " << i << " WAS of type DataManager" << __E__; 00207 00208 break; 00209 } 00210 catch(...) 00211 { 00212 __SUP_COUT__ << "State Machine " << i << " was NOT of type DataManager" 00213 << __E__; 00214 } 00215 } 00216 00217 __SUP_COUT__ << "theDataManager pointer = " << theDataManager_ << __E__; 00218 00219 return theDataManager_; 00220 } // end extractDataManager()