604 if (!conf.DoParse(argc, argv,
PrintHelp))
609 const int enter = conf.Has(
"enter-schedule-into-database") ? (conf.Get<
bool>(
"enter-schedule-into-database") ? 1 : -1) : 0;
610 if (enter && !conf.Has(
"schedule-database"))
611 throw runtime_error(
"enter-schedule-into-database required schedule-database.");
614 if (conf.Has(
"date"))
615 time.
SetFromStr(conf.Get<
string>(
"date")+
" 12:00:00");
617 if (enter && floor(time.
JD())<ceil(
Time().
JD()))
618 throw runtime_error(
"Only future schedules can be entered into the database.");
623 const double startup_offset = conf.Get<
double>(
"startup.offset")/60/24;
625 const double angle_sun_set = conf.Get<
double>(
"data-taking.start");
626 const double angle_sun_rise = conf.Get<
double>(
"data-taking.end");
628 if (startup_offset<0 || startup_offset>120)
629 throw runtime_error(
"Only values [0;120] are allowed for startup.offset");
631 if (angle_sun_set>-6)
632 throw runtime_error(
"datataking.start not allowed before sun at -6deg");
634 if (angle_sun_rise>-6)
635 throw runtime_error(
"datataking.end not allowed after sun at -6deg");
643 const double sunset = ceil(sun_set.set*24*60) /24/60 + 1e-9;
644 const double sunrise = floor(sun_rise.rise*24*60)/24/60 + 1e-9;
648 cout <<
"Date: " <<
Time(floor(sunset)).
GetAsStr() <<
"\n";
649 cout <<
"Set: " <<
Time(sunset).
GetAsStr() <<
" [" <<
Time(sun_set.set) <<
"]\n";
650 cout <<
"Rise: " <<
Time(sunrise).
GetAsStr() <<
" [" <<
Time(sun_rise.rise) <<
"]\n";
655 cout <<
"Global zenith distance: " << Source::max_zd <<
" deg\n";
661 const vector<string> ourcenames = conf.Vec<
string>(
"source");
662 const vector<string> sourcenames = conf.Vec<
string>(
"source");
663 cout <<
"Nsources = " << sourcenames.size() <<
"\n";
665 string query =
"SELECT fSourceName, fSourceKEY, fRightAscension, fDeclination FROM Source WHERE fSourceTypeKEY=1";
666 if (sourcenames.size()>0)
667 query +=
" AND fSourceName IN ('" + boost::algorithm::join(sourcenames,
"', '")+
"')";
669 const string sourcedb = conf.Get<
string>(
"source-database");
670 const mysqlpp::StoreQueryResult res =
671 Database(sourcedb).query(query).store();
675 vector<Source> sources;
676 for (
const auto &row: res)
678 const string name = string(row[0]);
682 src.equ.ra = double(row[2])*15;
683 src.equ.dec = double(row[3]);
685 src.maxzd =
MyDouble(conf,
"setup."+name+
".max-zd");
686 src.maxcurrent =
MyDouble(conf,
"setup."+name+
".max-current");
687 src.penalty = conf.Has(
"setup."+name+
".penalty") ?
688 conf.Get<
double>(
"setup."+name+
".penalty") : 1;
690 src.preobs = conf.Vec<
string>(
"preobs."+name);
693 cout <<
"[" << name <<
"]";
696 cout <<
" Zd<" << src.maxzd.val;
698 cout <<
" Penalty=" << src.penalty;
700 cout <<
" " << boost::algorithm::join(src.preobs,
"+") << endl;
711 sources.emplace_back(src);
719 const uint32_t n = nearbyint((sunrise-sunset)*24*60);
720 for (uint32_t
i=0;
i<n;
i++)
722 const double jd = sunset +
i/24./60.;
727 for (
auto& src: sources)
729 if (src.calcThreshold(so))
730 vis.emplace_back(src);
735 vis.emplace_back(src);
740 if (obs.size()>0 && obs.back().name==vis[0].name)
744 obs.emplace_back(vis[0]);
749 cout <<
"No source found." << endl;
755 for (
auto it=obs.begin(); it<obs.end()-1; it++)
757 obs.back().end = sunrise;
761 Print(obs, startup_offset);
776 Print(obs, startup_offset);
784 const string scheduledb = conf.Get<
string>(
"schedule-database");
789 db.query(
"LOCK TABLES Schedule WRITE");
791 const int rc =
FillSql(db, enter, obs, startup_offset);
794 db.query(
"UNLOCK TABLES");
bool RescheduleFirstSources(vector< Source > &obs)
void Print(const vector< Source > &obs, double startup_offset)
bool RescheduleIntermediateSources(vector< Source > &obs)
bool SortByThreshold(const Source &i, const Source &j)
Adds some functionality to boost::posix_time::ptime for our needs.
void CheckStartupAndShutdown(vector< Source > &obs)
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
void RemoveMiniSources(vector< Source > &obs)
Commandline parsing, resource file parsing and database access.
void SetFromStr(const std::string &str, const char *fmt="%Y-%m-%d %H:%M:%S")
int FillSql(Database &db, int enter, const vector< Source > &obs, double startup_offset)
RstTime GetSolarRst(double jd, const LnLatPosn &obs, double hrz=LN_SOLAR_STANDART_HORIZON)
static double max_current
void SetupConfiguration(Configuration &conf)
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
bool RescheduleLastSources(vector< Source > &obs)