Changeset 14161 for trunk/FACT++/src/smartfact.cc
- Timestamp:
- 06/12/12 23:41:39 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r14145 r14161 9 9 #include "Database.h" 10 10 #endif 11 12 #include <sys/stat.h> //for file stats 11 13 12 14 #include "Dim.h" … … 358 360 class StateMachineSmartFACT : public StateMachineDim 359 361 { 362 public: 363 static bool fIsServer; 364 360 365 private: 361 366 enum states_t … … 391 396 deque<string> fMcpConfigurationHist; 392 397 398 bool fLastRunFinishedWithZeroEvents; 399 393 400 enum weather_t { kWeatherBegin=0, kTemp = kWeatherBegin, kDew, kHum, kPress, kWind, kGusts, kDir, kWeatherEnd = kDir+1 }; 394 401 deque<float> fMagicWeatherHist[kWeatherEnd]; … … 427 434 428 435 deque<float> fFtmControlTriggerRateHist; 429 uint32_t fFtmControlNewRunStarted; 430 uint32_t fFtmControlTriggerRateTooLow; 436 int32_t fFtmControlTriggerRateTooLow; 431 437 432 438 float fFtmPatchThresholdMed; … … 748 754 out << "</#><br/>"; 749 755 fMcpConfigurationHist.push_back(out.str()); 756 757 fLastRunFinishedWithZeroEvents = fFadControlNumEvents==0; 750 758 } 751 759 … … 1284 1292 } 1285 1293 1286 const double crate = d.Get<float>(20);// Camera rate1294 const float *crate = d.Ptr<float>(20); // Camera rate 1287 1295 1288 1296 // New run started 1289 if (crate<0) 1290 { 1291 fFtmControlNewRunStarted = 0; 1292 fFtmControlTriggerRateTooLow = 0; 1297 if (*crate<0) 1298 { 1299 fFtmControlTriggerRateTooLow = -1; 1293 1300 return GetCurrentState(); 1294 1301 } … … 1298 1305 // by the MCP. Hence, we get a warning. So we have to require 1299 1306 // two consecutive low rates. 1300 if ( crate<0.1)1307 if (*crate<0.1) 1301 1308 fFtmControlTriggerRateTooLow++; 1302 1309 else 1303 1310 fFtmControlTriggerRateTooLow=0; 1304 1311 1305 fFtmControlNewRunStarted++; 1306 1307 const float *brates = d.Ptr<float>(24); // Board rate 1308 const float *prates = d.Ptr<float>(24+40*sizeof(float)); // Patch rate 1312 const float *brates = crate + 1; // Board rate 1313 const float *prates = brates+40; // Patch rate 1309 1314 1310 1315 // Store a history of the last 60 entries 1311 fFtmControlTriggerRateHist.push_back( crate);1312 if (fFtmControlTriggerRateHist.size()> 60)1316 fFtmControlTriggerRateHist.push_back(*crate); 1317 if (fFtmControlTriggerRateHist.size()>300) 1313 1318 fFtmControlTriggerRateHist.pop_front(); 1314 1319 … … 1325 1330 out << setprecision(3); 1326 1331 out << d.GetJavaDate() << '\n'; 1327 out << HTML::kWhite << '\t' << crate << '\n';1332 out << HTML::kWhite << '\t' << *crate << '\n'; 1328 1333 1329 1334 ofstream(fPath+"/trigger.data") << out.str(); 1330 1335 1331 const Statistics bstat(vector<float>(brates, brates+ 40));1336 const Statistics bstat(vector<float>(brates, brates+ 40)); 1332 1337 const Statistics pstat(vector<float>(prates, prates+160)); 1333 1338 … … 1572 1577 const float *ptr = d.Ptr<float>(4); 1573 1578 1574 double avg = 1579 double avg =0; 1575 1580 int num = 0; 1576 1581 1577 1582 for (const float *t=ptr; t<ptr+4; t++) 1578 if (*t>0 )1583 if (*t>0 && *t<=100) 1579 1584 { 1580 1585 avg += *t; … … 1582 1587 } 1583 1588 1584 fFscControlHumidityAvg = avg/num;1589 fFscControlHumidityAvg = num>0 ? avg/num : 0; 1585 1590 1586 1591 return GetCurrentState(); … … 2044 2049 2045 2050 newerr |= SetError(bias_on && fFeedbackCalibration.size()>0 && fBiasControlCurrentMed>80, 2046 "Median current exceeds 80µA/pix ");2051 "Median current exceeds 80µA/pix exceeds 80µA/pix"); 2047 2052 newerr |= SetError(bias_on && fFeedbackCalibration.size()>0 && fBiasControlCurrentMax>100, 2048 2053 "Maximum current exceeds 100µA/pix"); … … 2059 2064 "Sensor temperature exceeds outside temperature by more than 8°C"); 2060 2065 2061 newerr |= SetError(fFtmControl NewRunStarted>0 && fFtmControlTriggerRateTooLow>1&& fDimMcp.state()==MCP::State::kTakingData,2066 newerr |= SetError(fFtmControlTriggerRateTooLow>2 && fDimMcp.state()==MCP::State::kTakingData, 2062 2067 "Trigger rate below 100mHz during data taking"); 2063 2068 … … 2072 2077 fFeedbackCalibration.size()==0, 2073 2078 "Bias voltage switched on, but bias crate not calibrated"); 2079 2080 newerr |= SetError(fLastRunFinishedWithZeroEvents, 2081 "Last run finshed, but contained zero events."); 2082 2083 fLastRunFinishedWithZeroEvents = false; 2074 2084 2075 2085 // FTM in Connected instead of Idle --> power cyclen … … 2343 2353 { 2344 2354 string col = HTML::kGreen; 2345 if (fFtmControlTriggerRateHist.size()>0 && fFtmControlNewRunStarted>0)2355 if (fFtmControlTriggerRateHist.size()>0) 2346 2356 { 2347 2357 if (fFtmControlTriggerRateHist.back()<15) … … 2474 2484 2475 2485 public: 2476 StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, "SMART_FACT"),2486 StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, fIsServer?"SMART_FACT":""), 2477 2487 fLastAstroCalc(boost::date_time::neg_infin), 2478 2488 fPath("www/smartfact/data"), … … 2481 2491 fMcpConfigurationMaxTime(0), 2482 2492 fMcpConfigurationMaxEvents(0), 2493 fLastRunFinishedWithZeroEvents(false), 2483 2494 fTngWeatherDustTime(Time::none), 2484 2495 fBiasControlVoltageMed(0), … … 2614 2625 fDatabase = conf.Get<string>("source-database"); 2615 2626 2627 struct stat st; 2628 if (stat(fPath.c_str(), &st)) 2629 { 2630 Error(fPath+" does not exist!"); 2631 return 2; 2632 } 2633 2634 if ((st.st_mode&S_IFDIR)==0) 2635 { 2636 Error(fPath+" not a directory!"); 2637 return 3; 2638 } 2639 2640 if ((st.st_mode&S_IWUSR)==0) 2641 { 2642 Error(fPath+" has no write permission!"); 2643 return 4; 2644 } 2645 2646 if ((st.st_mode&S_IXUSR)==0) 2647 { 2648 Error(fPath+" has no execute permission!"); 2649 return 5; 2650 } 2651 2616 2652 ostringstream out; 2617 2653 out << Time().JavaDate() << '\n'; 2618 2654 2619 ofstream(fPath+"/errorhist.data") << out.str();2620 ofstream(fPath+"/error.data") << out.str();2655 ofstream(fPath+"/errorhist.data") << out.str(); 2656 ofstream(fPath+"/error.data") << out.str(); 2621 2657 2622 2658 return -1; 2623 2659 } 2624 2660 }; 2661 2662 bool StateMachineSmartFACT::fIsServer = false; 2625 2663 2626 2664 // ------------------------------------------------------------------------ … … 2631 2669 int RunShell(Configuration &conf) 2632 2670 { 2671 StateMachineSmartFACT::fIsServer = !conf.Get<bool>("client"); 2633 2672 return Main::execute<T, StateMachineSmartFACT>(conf); 2634 2673 } … … 2641 2680 ("path", var<string>("www/smartfact/data"), "Output path for the data-files") 2642 2681 ("source-database", var<string>(), "Database link as in\n\tuser:password@server[:port]/database.") 2682 ("client", po_bool(false), "For a standalone client choose this option.") 2643 2683 ; 2644 2684
Note:
See TracChangeset
for help on using the changeset viewer.