Changeset 19516 for trunk/FACT++
- Timestamp:
- 05/26/19 12:02:46 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/scheduler.cc
r19508 r19516 426 426 uint16_t fKeepAliveInterval; 427 427 428 int16_t GetSourceKey(const string &name, const double &ra, const double &dec) 428 struct Source 429 { 430 int16_t key { -1 }; 431 bool isToO { false }; 432 }; 433 434 Source GetSourceKey(const string &name, const double &ra, const double &dec) 429 435 { 430 436 const double min_dist = 0.1; 431 437 const double check_dist = 2.0; 432 438 433 434 int32_t source_key = -1; 439 // ----------------------- Check if source with same name exists ----------------------- 440 441 const string query2 = 442 "SELECT fSourceKey, fIsToO FROM Source WHERE fSourceName='"+name+"'"; 443 444 const mysqlpp::StoreQueryResult res2 = fConnection.query(query2).store(); 445 446 if (res2.num_rows()) 447 { 448 Source source; 449 source.key = res2[0]["fSourceKey"]; 450 source.isToO = res2[0]["fIsToO"]; 451 452 Info("A source with the same name (key="+to_string(source.key)+") was found in the Source table."); 453 454 return source; 455 } 456 457 // ----------------- Check if source with similar coordinates exists ------------------- 435 458 436 459 const string query1 = 437 "SELECT fSourceKey, fSourceName, ADIST(fDeclination, fRightAscension*15, "+to_string(dec)+", "+to_string(ra)+") AS Dist\n" 460 "SELECT\n" 461 " fSourceKey,\n" 462 " fSourceName,\n" 463 " ADIST(fDeclination, fRightAscension*15, "+to_string(dec)+", "+to_string(ra)+") AS Dist,\n" 464 " fIsToO\n" 438 465 " FROM Source\n" 439 466 " WHERE fSourceTypeKEY=1\n" … … 445 472 if (res1.num_rows()) 446 473 { 447 Info("Found "+to_string(res1.num_rows())+" sources with a distance less than "+ to_string(check_dist)+"\u00b0");474 Info("Found "+to_string(res1.num_rows())+" sources with a distance less than "+Tools::Form("%.2f", check_dist)+"\u00b0"); 448 475 449 476 for (size_t i=0; i<res1.num_rows(); i++) 450 477 { 451 478 const mysqlpp::Row &row = res1[i]; 452 Info(" "+string(row["fSourceName"])+" ["+string(row["fSourceKey"])+"]: D="+ string(row["Dist"])+"\u00b0");479 Info(" "+string(row["fSourceName"])+" ["+string(row["fSourceKey"])+"]: D="+Tools::Form("%.2f", double(row["Dist"]))+"\u00b0"); 453 480 } 454 481 … … 456 483 if (double(row["Dist"])<min_dist) 457 484 { 458 Warn("Sources closer than "+to_string(check_dist)+"\u00b0 detected."); 459 Warn("Overwriting source key with: "+string(row["fSourceName"])+" ["+string(row["fSourceKey"])+"]: D="+string(row["Dist"])+"\u00b0"); 460 source_key = res1[0]["fSourceKey"]; 485 Source source; 486 source.key = res1[0]["fSourceKey"]; 487 source.isToO = res1[0]["fIsToO"]; 488 489 Warn("Sources closer than "+Tools::Form("%.2f", check_dist)+"\u00b0 detected."); 490 Warn("Overwriting source key with: "+string(row["fSourceName"])+" ["+to_string(source.key)+"]: D="+Tools::Form("%.2f", double(row["Dist"]))+"\u00b0"); 491 492 return source; 461 493 } 462 494 } 463 495 464 //Out() << Time()-stopwatch << endl; 465 466 const string query2 = 467 "SELECT fSourceKey FROM Source WHERE fSourceName='"+name+"'"; 468 469 const mysqlpp::StoreQueryResult res2 = fConnection.query(query2).store(); 470 471 if (res2.num_rows()) 472 { 473 source_key = res2[0]["fSourceKey"]; 474 Info("A source with the same name (key="+to_string(source_key)+") was found in the Source table."); 475 } 476 477 return source_key; 496 return Source(); 478 497 } 479 498 … … 575 594 576 595 577 bool ScheduleImp(const string &name, const double &ra, const double &dec, const bool &known_only)596 bool ScheduleImp(const string &name, const double &ra, const double &dec, const CheckVisibility &check, const bool &is_pointing) 578 597 { 579 598 const bool fDryRun = GetCurrentState()!=ToO::State::kArmed; … … 608 627 */ 609 628 610 int32_t source_key= GetSourceKey(name, ra, dec);629 Source source = GetSourceKey(name, ra, dec); 611 630 612 631 Out() << Time()-stopwatch << endl; 613 632 614 if ( known_only && source_key<0)633 if (is_pointing && source.key<0) // Not a known source 615 634 { 616 635 Warn("Observation of only known sources requested but no known source found."); 617 636 return false; 637 } 638 639 if (source.key>=0) 640 { 641 if (source.isToO) 642 { 643 Warn("Known source with ToO flag... skipping."); 644 return false; 645 } 646 647 const set<uint16_t> prioritized_sources = { 1, 2, 7 }; 648 649 const bool prio = prioritized_sources.find(source.key)!=prioritized_sources.end(); 650 651 if ((check.threshold>3 && !prio) || check.threshold>10) 652 { 653 Warn("Relative threshold too high... skipping."); 654 return false; 655 } 618 656 } 619 657 … … 690 728 int32_t reschedule = -1; 691 729 int32_t following = -1; 730 int32_t last_resch = -1; 692 731 for (size_t i=0; i<resS.num_rows(); i++) 693 732 { … … 715 754 reschedule = i; 716 755 756 if (bool(row["Reschedule"]) && !row["Delete"]) 757 last_resch = i; 758 717 759 if (following==-1 && bool(row["Following"])) 718 760 following = i; … … 799 841 // ==================================================================== 800 842 801 // FIXME: Check if source is not already scheduled anyways 802 803 Info("Source will be scheduled."); 804 805 if (source_key<0) 843 if (source.key<0) 806 844 { 807 845 const double wobble_angle = GetWobbleAngle(ra, dec); … … 818 856 auto q = fConnection.query(query); 819 857 q.execute(); 820 Info(q.info()); 821 822 source_key = q.insert_id(); 823 824 Info(string(fDryRun?"[dry-run] ":"")+"The new source got the key "+to_string(source_key)); 858 if (!q.info().empty()) 859 Info(q.info()); 860 861 source.key = q.insert_id(); 862 863 Info(string(fDryRun?"[dry-run] ":"")+"The new source got the key "+to_string(source.key)); 825 864 } 826 865 else 827 866 Out() << query << endl; 828 829 867 } 830 868 … … 833 871 // ==================================================================== 834 872 873 Info("Source will be scheduled."); 874 875 Out() << "New entries:\n"; 876 835 877 vector<string> insert; 836 878 837 Out() << "New entries:\n"; 838 Out() << " | auto | " << schedtime.GetAsStr() << " | < start > | 0 | ToO | nodrs,grb | " << setw(4) << source_key << " | 4\n"; 839 840 insert.emplace_back("('"+schedtime.GetAsStr()+"',0,'ToO','nodrs:true,grb:true',"+to_string(source_key)+",4)"); 879 const bool ongoing = last_resch>=0 && source.key==uint16_t(resS[last_resch]["fSourceKey"]); 880 881 if (ongoing) 882 Out() << " | | | < ongoing > | 0 | | | " << setw(4) << source.key << " | 4\n"; 883 else 884 { 885 Out() << " | auto | " << schedtime.GetAsStr() << " | < start > | 0 | ToO | " << (is_pointing?" nodrs ":"nodrs,grb") << " | " << setw(4) << source.key << " | 4\n"; 886 insert.emplace_back("('"+schedtime.GetAsStr()+"',0,'ToO','"+(is_pointing?"nodrs:true":"nodrs:true,grb:true")+"',"+to_string(source.key)+",4)"); 887 } 841 888 842 889 // -------------------------------------------------------------------- … … 878 925 // Empty interrupt to stop data taking as early as possible 879 926 // Triggers also RELOAD_SOURCES 880 Dim::SendCommandNB("DIM_CONTROL/INTERRUPT", "prepare"); 927 if (!ongoing) 928 Dim::SendCommandNB("DIM_CONTROL/INTERRUPT", "prepare"); 881 929 882 930 // --------------------------------------------------------- … … 897 945 auto q = fConnection.query(queryI); 898 946 q.execute(); 899 Info(q.info()); 947 if (!q.info().empty()) 948 Info(q.info()); 900 949 } 901 950 // --------------------------------------------------------- … … 905 954 // --------------------------------------------------------- 906 955 907 Dim::SendCommand("DIM_CONTROL/INTERRUPT", "reschedule"); 956 if (!ongoing) 957 Dim::SendCommand("DIM_CONTROL/INTERRUPT", "reschedule"); 908 958 909 959 ostringstream out; … … 914 964 } 915 965 916 bool Schedule(const string &name, const double &ra, const double &dec, const bool &known_only)966 bool Schedule(const string &name, const double &ra, const double &dec, const CheckVisibility &check, const bool &is_pointing) 917 967 { 918 968 try 919 969 { 920 return ScheduleImp(name, ra, dec, known_only);970 return ScheduleImp(name, ra, dec, check, is_pointing); 921 971 } 922 972 catch (const exception &e) … … 1018 1068 1019 1069 Info(string("Sun altitude: ")+(check.valid_sun ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.solarobj.fSunHrz.alt)+"\u00b0]"); 1020 Info(string("Moon distance: ")+(check.valid_moon ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.moon_dist)+"\u00b0]"); 1021 Info(string("Zenith angle: ")+(check.valid_zd ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.position.zd)+"\u00b0]"); 1022 Info(string("Current: ")+(check.valid_current ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.current)+" \u00b5A]"); 1023 Info(string("Rel. threshold: ")+(check.valid_threshold?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.threshold)+"]"); 1070 if (check.valid_sun) 1071 { 1072 Info(string("Moon distance: ")+(check.valid_moon ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.moon_dist)+"\u00b0]"); 1073 Info(string("Zenith angle: ")+(check.valid_zd ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.position.zd)+"\u00b0]"); 1074 Info(string("Current: ")+(check.valid_current ?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.current)+" \u00b5A]"); 1075 Info(string("Rel. threshold: ")+(check.valid_threshold?"OK ":"failed")+" ["+Tools::Form("%5.1f", check.threshold)+"]"); 1076 } 1024 1077 1025 1078 if (!check.visible) … … 1094 1147 */ 1095 1148 1096 const bool known_only= grb.type==51 || grb.type==83;1097 1098 Schedule(name, grb.ra, grb.dec, known_only);1149 const bool is_pointing = grb.type==51 || grb.type==83; 1150 1151 Schedule(name, grb.ra, grb.dec, check, is_pointing); 1099 1152 1100 1153 return fConnection.connected() ? GetCurrentState() : ToO::State::kDisconnected;
Note:
See TracChangeset
for help on using the changeset viewer.