Changeset 13838 for trunk/FACT++/src/mcp.cc
- Timestamp:
- 05/23/12 17:06:08 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/mcp.cc
r13794 r13838 26 26 27 27 #include "DimDescriptionService.h" 28 #include "DimState.h" 28 29 29 30 // ------------------------------------------------------------------------ 30 31 31 class StateMachineMCP : public StateMachineDim , public DimInfoHandler32 class StateMachineMCP : public StateMachineDim 32 33 { 33 /*34 int Wrap(boost::function<void()> f)35 {36 f();37 return T::GetCurrentState();38 }39 40 boost::function<int(const EventImp &)> Wrapper(boost::function<void()> func)41 {42 return bind(&StateMachineMCP::Wrap, this, func);43 }*/44 45 34 private: 46 35 enum states_t … … 61 50 }; 62 51 63 DimServiceInfoList fNetwork; 64 65 pair<Time, int> fStatusDim; 66 pair<Time, int> fStatusFTM; 67 pair<Time, int> fStatusFAD; 68 pair<Time, int> fStatusLog; 69 pair<Time, int> fStatusRC; 70 71 DimStampedInfo fDim; 72 DimStampedInfo fFTM; 73 DimStampedInfo fFAD; 74 DimStampedInfo fLog; 75 DimStampedInfo fRC; 52 DimServiceInfoListImp fNetwork; 53 54 DimVersion fDim; 55 DimState fDimFTM; 56 DimState fDimFAD; 57 DimState fDimLog; 58 DimState fDimRC; 76 59 77 60 DimDescribedService fService; 78 61 79 pair<Time, int> GetNewState(DimStampedInfo &info) const 80 { 81 const bool disconnected = info.getSize()==0; 82 83 // Make sure getTimestamp is called _before_ getTimestampMillisecs 84 const int tsec = info.getTimestamp(); 85 const int tms = info.getTimestampMillisecs(); 86 87 return make_pair(Time(tsec, tms*1000), 88 disconnected ? -2 : info.getQuality()); 89 } 90 91 void infoHandler() 92 { 93 DimInfo *curr = getInfo(); // get current DimInfo address 94 if (!curr) 62 const State GetState(const DimState &s) const 63 { 64 return fNetwork.GetState(s.name(), s.state()); 65 } 66 67 void PrintState(const DimState &state) const 68 { 69 const State rc = GetState(state); 70 71 Out() << state.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 72 Out() << kBold << state.name() << ": "; 73 if (rc.index==-3) 74 { 75 Out() << kReset << "Offline" << endl; 95 76 return; 96 97 if (curr==&fFTM) 98 { 99 fStatusFTM = GetNewState(fFTM); 100 return; 101 } 102 103 if (curr==&fFAD) 104 { 105 fStatusFAD = GetNewState(fFAD); 106 return; 107 } 108 109 if (curr==&fLog) 110 { 111 fStatusLog = GetNewState(fLog); 112 return; 113 } 114 115 if (curr==&fRC) 116 { 117 fStatusRC = GetNewState(fRC); 118 return; 119 } 120 121 if (curr==&fDim) 122 { 123 fStatusDim = GetNewState(fDim); 124 fStatusDim.second = curr->getSize()==4 ? curr->getInt() : 0; 125 return; 126 } 127 } 128 129 bool CheckEventSize(size_t has, const char *name, size_t size) 130 { 131 if (has==size) 132 return true; 133 134 ostringstream msg; 135 msg << name << " - Received event has " << has << " bytes, but expected " << size << "."; 136 Fatal(msg); 137 return false; 138 } 139 140 int SetVerbosity(const EventImp &) 141 { 142 /* 143 if (!CheckEventSize(evt.GetSize(), "SetVerbosity", 1)) 144 return T::kSM_FatalError; 145 146 fFSC.SetVerbose(evt.GetBool()); 147 148 */ 77 } 78 if (rc.index==-2) 79 Out() << state.state(); 80 else 81 Out() << rc.name << "[" << rc.index << "]"; 82 Out() << kReset << " - " << kBlue << rc.comment << endl; 83 } 84 85 int Print() const 86 { 87 Out() << fDim.time().GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 88 Out() << kBold << "DIM_DNS: " << fDim.version() << endl; 89 90 PrintState(fDim); 91 PrintState(fDimFTM); 92 PrintState(fDimFAD); 93 PrintState(fDimLog); 94 PrintState(fDimRC); 149 95 150 96 return GetCurrentState(); 151 97 } 152 98 153 154 void PrintState(const pair<Time,int> &state, const char *server) 155 { 156 const State rc = fNetwork.GetState(server, state.second); 157 158 Out() << state.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 159 Out() << kBold << server << ": "; 160 Out() << rc.name << "[" << rc.index << "]"; 161 Out() << kReset << " - " << kBlue << rc.comment << endl; 162 } 163 164 int Print() 165 { 166 Out() << fStatusDim.first.GetAsStr("%H:%M:%S.%f").substr(0, 12) << " - "; 167 Out() << kBold << "DIM_DNS: "; 168 if (fStatusDim.second==0) 169 Out() << "Offline" << endl; 170 else 171 Out() << "V" << fStatusDim.second/100 << 'r' << fStatusDim.second%100 << endl; 172 173 PrintState(fStatusFTM, "FTM_CONTROL"); 174 PrintState(fStatusFAD, "FAD_CONTROL"); 175 PrintState(fStatusLog, "DATA_LOGGER"); 176 PrintState(fStatusRC, "RATE_CONTROL"); 177 99 int GetReady() 100 { 178 101 return GetCurrentState(); 179 102 } 180 103 181 int GetReady()182 {183 return GetCurrentState();184 }185 186 104 int StopRun(const EventImp &) 187 105 { 188 if (f StatusFTM.second==FTM::kTriggerOn)106 if (fDimFTM.state()==FTM::kTriggerOn) 189 107 { 190 108 Message("Stopping FTM"); … … 193 111 194 112 // FIXME: Do step 2 only when FTM is stopped 195 if (f StatusFAD.second==FAD::kConnected)113 if (fDimFAD.state()==FAD::kConnected) 196 114 { 197 115 //Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", bool(false)); … … 213 131 /* 214 132 // FIMXE: Handle error states! 215 if (f StatusLog.second>=20)//kSM_NightlyOpen133 if (fDimLog.state()>=20)//kSM_NightlyOpen 216 134 Dim::SendCommand("DATA_LOGGER/STOP"); 217 135 218 if (f StatusLog.second==0)136 if (fDimLog.state()==0) 219 137 Dim::SendCommand("DATA_LOGGER/WAIT_FOR_RUN_NUMBER"); 220 138 221 if (f StatusFAD.second==FAD::kConnected)139 if (fDimFAD.state()==FAD::kConnected) 222 140 { 223 141 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", bool(false)); … … 225 143 } 226 144 227 if (f StatusFTM.second==FTM::kTakingData)145 if (fDimFTM.state()==FTM::kTakingData) 228 146 Dim::SendCommand("FTM_CONTROL/STOP"); 229 147 … … 237 155 int StartRun(const EventImp &evt) 238 156 { 239 if (f StatusFTM.second==-2)157 if (fDimFTM.state()==-2) 240 158 { 241 159 Error("No connection to ftmcontrol (see PRINT)."); 242 160 return GetCurrentState(); 243 161 } 244 if (f StatusFAD.second==-2)162 if (fDimFAD.state()==-2) 245 163 { 246 164 Warn("No connection to fadcontrol (see PRINT)."); 247 165 return GetCurrentState(); 248 166 } 249 if (f StatusLog.second==-2)167 if (fDimLog.state()==-2) 250 168 { 251 169 Warn("No connection to datalogger (see PRINT)."); 252 170 return GetCurrentState(); 253 171 } 254 if (f StatusRC.second==-2)172 if (fDimRC.state()==-2) 255 173 { 256 174 Warn("No connection to ratecontrol (see PRINT)."); … … 332 250 //poll_one(); 333 251 334 if ( fStatusDim.second==0)252 if (!fDim.online()) 335 253 return kStateDimNetworkNA; 336 254 337 if (f StatusFTM.second>= FTM::kConnected &&338 f StatusFAD.second>= FAD::kConnected &&339 f StatusLog.second>= kSM_Ready)255 if (fDimFTM.state() >= FTM::kConnected && 256 fDimFAD.state() >= FAD::kConnected && 257 fDimLog.state() >= kSM_Ready) 340 258 { 341 259 if (GetCurrentState()==kStateConfiguring1) 342 260 { 343 if (f StatusLog.second<30/*kSM_WaitForRun*/)261 if (fDimLog.state()<30/*kSM_WaitForRun*/) 344 262 { 345 263 Message("Starting datalogger"); … … 355 273 { 356 274 // FIMXE: Reset in case of error 357 if ((/*f StatusFTM.second!= FTM::kConfiguring2 &&*/358 f StatusFTM.second!= FTM::kConfigured) ||359 f StatusLog.second<30 || fStatusLog.second>0xff)275 if ((/*fDimFTM.state() != FTM::kConfiguring2 &&*/ 276 fDimFTM.state() != FTM::kConfigured) || 277 fDimLog.state()<30 || fDimLog.state()>0xff) 360 278 return GetCurrentState(); 361 279 … … 374 292 if (GetCurrentState()==kStateConfiguring3) 375 293 { 376 if (f StatusFTM.second!= FTM::kConfigured ||377 f StatusFAD.second!= FAD::kConfigured ||378 f StatusRC.second< 6)294 if (fDimFTM.state() != FTM::kConfigured || 295 fDimFAD.state() != FAD::kConfigured || 296 fDimRC.state() < 6) 379 297 return GetCurrentState(); 380 298 … … 387 305 if (GetCurrentState()==kStateConfigured) 388 306 { 389 if (f StatusFTM.second!= FTM::kTriggerOn)307 if (fDimFTM.state() != FTM::kTriggerOn) 390 308 return GetCurrentState(); 391 309 … … 397 315 if (GetCurrentState()==kStateTriggerOn) 398 316 { 399 if (f StatusFAD.second!= FAD::kWritingData)317 if (fDimFAD.state() != FAD::kWritingData) 400 318 return GetCurrentState(); 401 319 … … 407 325 if (GetCurrentState()==kStateTakingData) 408 326 { 409 if (f StatusFTM.second==FTM::kTriggerOn &&410 f StatusFAD.second==FAD::kWritingData)327 if (fDimFTM.state()==FTM::kTriggerOn && 328 fDimFAD.state()==FAD::kWritingData) 411 329 return kStateTakingData; 412 330 … … 418 336 419 337 /* 420 if (f StatusFTM.second>= FTM::kConnected &&421 f StatusFAD.second>= FAD::kConnected &&422 f StatusLog.second>= kSM_Ready)338 if (fDimFTM.state() >= FTM::kConnected && 339 fDimFAD.state() >= FAD::kConnected && 340 fDimLog.state() >= kSM_Ready) 423 341 return kStateIdle; 424 342 */ 425 if (f StatusFTM.second>-2 &&426 f StatusFAD.second>-2 &&427 f StatusLog.second>-2 &&428 f StatusRC.second>-2)343 if (fDimFTM.state() >-2 && 344 fDimFAD.state() >-2 && 345 fDimLog.state() >-2 && 346 fDimRC.state() >-2) 429 347 return kStateConnected; 430 348 431 if (f StatusFTM.second>-2 ||432 f StatusFAD.second>-2 ||433 f StatusLog.second>-2 ||434 f StatusRC.second>-2)349 if (fDimFTM.state() >-2 || 350 fDimFAD.state() >-2 || 351 fDimLog.state() >-2 || 352 fDimRC.state() >-2) 435 353 return kStateConnecting; 436 354 … … 440 358 public: 441 359 StateMachineMCP(ostream &out=cout) : StateMachineDim(out, "MCP"), 442 fStatusDim(make_pair(Time(), -2)), 443 fStatusFTM(make_pair(Time(), -2)), 444 fStatusFAD(make_pair(Time(), -2)), 445 fStatusLog(make_pair(Time(), -2)), 446 fDim("DIS_DNS/VERSION_NUMBER", (void*)NULL, 0, this), 447 fFTM("FTM_CONTROL/STATE", (void*)NULL, 0, this), 448 fFAD("FAD_CONTROL/STATE", (void*)NULL, 0, this), 449 fLog("DATA_LOGGER/STATE", (void*)NULL, 0, this), 450 fRC("RATE_CONTROL/STATE", (void*)NULL, 0, this), 360 fDimFTM("FTM_CONTROL"), 361 fDimFAD("FAD_CONTROL"), 362 fDimLog("DATA_LOGGER"), 363 fDimRC("RATE_CONTROL"), 451 364 fService("MCP/CONFIGURATION", "X:1;X:1;C", "Run configuration information" 452 365 "|MaxTime[s]:Maximum time before the run gets stopped" … … 461 374 // deletion and creation of threads and more. 462 375 376 fDim.Subscribe(*this); 377 fDimFTM.Subscribe(*this); 378 fDimFAD.Subscribe(*this); 379 fDimLog.Subscribe(*this); 380 fDimRC.Subscribe(*this); 381 463 382 // State names 464 383 AddStateName(kStateDimNetworkNA, "DimNetworkNotAvailable", … … 513 432 "is also propagated to FTM and FAD"); 514 433 515 // Verbosity commands516 AddEvent("SET_VERBOSE", "B:1")517 (bind(&StateMachineMCP::SetVerbosity, this, placeholders::_1))518 ("set verbosity state"519 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");520 521 434 AddEvent("PRINT") 522 435 (bind(&StateMachineMCP::Print, this)) … … 526 439 int EvalOptions(Configuration &) 527 440 { 528 //SetEndpoint(conf.Get<string>("addr"));529 530 //fFSC.SetVerbose(!conf.Get<bool>("quiet"));531 532 441 return -1; 533 442 }
Note:
See TracChangeset
for help on using the changeset viewer.