21 namespace ba = boost::asio;
22 namespace bs = boost::system;
67 if (fDimFadControl.
state()==FAD::State::kRunInProgress)
72 if (now<fTimer+boost::posix_time::milliseconds(fInterval))
73 return GetCurrentState();
79 (rst.rise<rst.set && (now.
JD()>rst.rise && now.
JD()<rst.set)) ||
80 (rst.rise>rst.set && (now.
JD()<rst.set || now.
JD()>rst.rise));
87 const uint32_t night = fStartDate>0 ? fStartDate :
Time().
NightAsInt()-1;
95 const string name = fAuxPath +
Tools::Form(
"/%04d/%02d/%02d/%08d.FAD_CONTROL_EVENT_DATA.fits", night/10000, (night/100)%100, night%100, night);
100 Error(
string(
"Failed to open "+name+
": ")+strerror(errno));
114 catch (
const runtime_error &e)
119 Error(
"Failed to open "+name+
": "+e.what());
131 catch (
const runtime_error &e) { }
133 Info(
"File "+name+
" open.");
140 vector<float> sorted;
150 if (fQoS & FAD::EventHeader::kAll)
153 for (
int i=0;
i<1440;
i++)
156 for (
int i=8;
i<1440;
i+=9)
161 sort(sorted.begin(), sorted.end());
163 const double med = sorted[719];
165 vector<float>
dev(1440);
166 for (
int i=0;
i<1440;
i++)
167 dev[
i] = fabs(sorted[
i]-med);
168 sort(dev.begin(), dev.end());
170 const double deviation = dev[uint32_t(0.682689477208650697*1440)];
176 if (sorted[1439-3]>med+deviation*5)
180 const double scale = max(0.25f, sorted[1436]);
185 out << scale <<
'\n';
186 out << setprecision(3);
189 out << fEvt <<
'\n' << fRun <<
"\nDEMO\x7f";
191 out <<
"DEMO\nDEMO\nDEMO\x7f";
199 vector<uint8_t> val(1440);
200 for (uint64_t
i=0;
i<1440;
i++)
202 float range = nearbyint(126*fMax[
i]/scale);
207 val[
i] = (uint8_t)range;
210 const char *ptr =
reinterpret_cast<char*
>(val.data());
211 out.write(ptr, val.size()*
sizeof(uint8_t));
217 ofstream(fOutPath+
"/cam-fadcontrol-eventdata.bin") << out.str();
245 fDimFadControl(
"FAD_CONTROL"), fStartDate(0), fNight(0), fIn(0), fMax(1440)
252 "Event server stopped.");
254 "Reading events file and writing to output.");
256 "No events are processed, either the sun is down or fadctrl in kRunInProgress.");
261 (
"Start serving the smartfact camera file");
265 (
"Start serving the smartfact camera file with the events from the given date" 266 "|uint32[yyyymmdd]:Integer representing the date from which the data should be read");
270 (
"Stop serving the smartfact camera file");
279 fAuxPath = conf.
Get<
string>(
"aux-path");
280 fOutPath = conf.
Get<
string>(
"out-path");
281 fInterval = conf.
Get<uint32_t>(
"interval");
294 return Main::execute<T, StateMachineEventServer>(conf);
299 po::options_description control(
"Event server options");
300 control.add_options()
301 (
"aux-path", var<string>(
"/fact/aux"),
"The root path to the auxilary files.")
302 (
"out-path", var<string>(
"www/smartfact/data"),
"Path where the output camera file should be written.")
303 (
"interval", var<uint32_t>(5000),
"Interval of updates in milliseconds.")
321 "The event server copies events from fits files to the smartfact data.\n" 323 "Usage: evtserver [-c type] [OPTIONS]\n" 324 " or: evtserver [OPTIONS]\n";
330 Main::PrintHelp<StateMachineEventServer>();
350 int main(
int argc,
const char* argv[])
363 if (!conf.
Has(
"console"))
368 return RunShell<LocalStream>(conf);
380 if (conf.
Get<
int>(
"console")==0)
381 return RunShell<LocalShell>(conf);
383 return RunShell<LocalConsole>(conf);
virtual void Subscribe(StateMachineImp &imp)
Mainloop running, state machine in operation.
uint64_t JavaDate() const
A general base-class describing events issues in a state machine.
void SetupConfiguration(Configuration &conf)
Adds some functionality to boost::posix_time::ptime for our needs.
int EvalOptions(Configuration &conf)
void SetPrintUsage(const std::function< void(void)> &func)
T Get(const std::string &var)
uint32_t NightAsInt() const
const int32_t & state() const
StateMachineEventServer(ostream &out=cout)
bool SetVecAddress(const std::string &name, std::vector< T > &vec)
int StartDate(const EventImp &evt)
bool GetNextRow(bool check=true)
void SetupConfiguration(Configuration &conf)
int main(int argc, const char *argv[])
bool Has(const std::string &var)
void AddOptions(const po::options_description &opt, bool visible=true)
Commandline parsing, resource file parsing and database access.
DimDescribedState fDimFadControl
RstTime GetSolarRst(double jd, const LnLatPosn &obs, double hrz=LN_SOLAR_STANDART_HORIZON)
int RunShell(Configuration &conf)
Class for a state machine implementation within a DIM network.
int Execute()
Is called continously to execute actions in the current state.
Error states should be between 0x100 and 0xffff.
Return to feeserver c CVS log Up to[MAIN] dcscvs FeeServer feeserver src Wed FeeServer_v0 v0 dev
bool DoParse(int argc, const char **argv, const std::function< void()> &func=std::function< void()>())
bool SetRefAddress(const std::string &name, T &ptr)
~StateMachineEventServer()