Changeset 17170
- Timestamp:
- 09/17/13 18:41:04 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fscctrl.cc
r16961 r17170 11 11 #include "Console.h" 12 12 #include "Converter.h" 13 #include "../externals/Interpolator2D.h" 13 14 14 15 #include "tools.h" … … 34 35 ofstream fDumpStream; 35 36 37 36 38 protected: 39 vector<pair<double,double>> fPositionsSensors; 40 vector<pair<double,double>> fPositionsBias; 37 41 38 42 virtual void UpdateTemp(float, const vector<float> &) … … 626 630 fDump = b; 627 631 } 632 633 void SetPositionsSensors(const vector<pair<double,double>> &vec) 634 { 635 fPositionsSensors = vec; 636 } 637 638 void SetPositionsBias(const vector<pair<double,double>> &vec) 639 { 640 fPositionsBias = vec; 641 } 628 642 }; 629 643 … … 636 650 private: 637 651 652 vector<double> fLastRms; 653 638 654 DimDescribedService fDimTemp; 655 DimDescribedService fDimTemp2; 639 656 DimDescribedService fDimHum; 640 657 DimDescribedService fDimVolt; … … 650 667 { 651 668 Update(fDimTemp, temp, time); 669 670 vector<double> T; 671 vector<Interpolator2D::vec> xy; 672 673 T.reserve(31); 674 xy.reserve(31); 675 676 double avg = 0; 677 double rms = 0; 678 679 // Create a list of all valid sensors 680 for (int i=0; i<31; i++) 681 if (temp[i]!=0) 682 { 683 T.emplace_back(temp[i]); 684 xy.emplace_back(fPositionsSensors[i].first, fPositionsSensors[i].second); 685 686 avg += temp[i]; 687 rms += temp[i]*temp[i]; 688 } 689 690 if (T.size()==0) 691 { 692 Warn("No valid sensor temperatures."); 693 return; 694 } 695 696 avg /= T.size(); 697 rms /= T.size(); 698 rms -= avg*avg; 699 rms = rms<0 ? 0 : sqrt(rms - avg*avg); 700 701 // Clean broken reports 702 const double cut_val = 0.015; 703 const bool reject = rms>4 || (fabs(fLastRms[0]-fLastRms[1])<=cut_val && fabs(rms-fLastRms[0])>cut_val); 704 705 fLastRms[1] = fLastRms[0]; 706 fLastRms[0] = rms; 707 708 if (reject) 709 { 710 Warn("Suspicious temperature values rejecte for BIAS_TEMP."); 711 return; 712 } 713 714 // Create interpolator for the corresponding sensor positions 715 Interpolator2D inter(xy); 716 717 // Calculate weights for the output positions 718 if (!inter.SetOutputGrid(fPositionsBias)) 719 { 720 Warn("Temperature values rejecte for BIAS_TEMP (calculation of weights failed)."); 721 return; 722 } 723 724 // Interpolate the data 725 T = inter.Interpolate(T); 726 727 // Update the Dim service with the interpolated positions 728 Update(fDimTemp2, vector<float>(T.cbegin(), T.cend()), time); 652 729 } 653 730 … … 666 743 Update(fDimCurrent, curr, time); 667 744 } 668 669 670 745 671 746 public: 672 747 ConnectionDimFSC(ba::io_service& ioservice, MessageImp &imp) : 673 ConnectionFSC(ioservice, imp), 748 ConnectionFSC(ioservice, imp), fLastRms(2), 674 749 fDimTemp ("FSC_CONTROL/TEMPERATURE", "F:1;F:31;F:8;F:8;F:4;F:4;F:4", 675 750 "|t[s]:FSC uptime" … … 680 755 "|T_back[deg C]:FTM backpanel temperatures FTM (top/bottom), FSC (top/bottom)" 681 756 "|T_eth[deg C]:Ethernet switches temperatures top (front/back), bottom (f/b)"), 757 fDimTemp2 ("FSC_CONTROL/BIAS_TEMP", "F:1;F:320", 758 "|t[s]:FSC uptime" 759 "|T[deg C]:Interpolated temperatures at bias patch positions"), 682 760 fDimHum ("FSC_CONTROL/HUMIDITY", "F:1;F:4", 683 761 "|t[s]:FSC uptime" … … 709 787 "|FLP_I[A]:FLP - light pulser") 710 788 { 789 fLastRms[0] = 1.5; 711 790 } 712 791 … … 824 903 } 825 904 905 vector<pair<double,double>> ReadVector(const string &filename) const 906 { 907 vector<pair<double,double>> vec; 908 909 ifstream fin(filename); 910 while (1) 911 { 912 double x, y; 913 fin >> x; 914 fin >> y; 915 if (!fin) 916 break; 917 918 vec.emplace_back(x, y); 919 } 920 921 return vec; 922 } 923 826 924 int EvalOptions(Configuration &conf) 827 925 { 828 926 fFSC.SetVerbose(!conf.Get<bool>("quiet")); 927 928 const string fname1 = conf.Get<string>("sesnor-pos-file"); 929 const auto v1 = ReadVector(fname1); 930 if (v1.size() != 31) 931 { 932 Error("Reading sensor positions from "+fname1+"failed ("+to_string(v1.size())+")"); 933 return 1; 934 } 935 936 const string fname2 = conf.Get<string>("patch-pos-file"); 937 const auto v2 = ReadVector(fname2); 938 if (v2.size() != 320) 939 { 940 Error("Reading bias patch positions from "+fname2+"failed ("+to_string(v2.size())+")"); 941 return 1; 942 } 943 944 fFSC.SetPositionsSensors(v1); 945 fFSC.SetPositionsBias(v2); 829 946 830 947 SetEndpoint(conf.Get<string>("addr")); … … 850 967 ("no-dim", po_bool(), "Disable dim services") 851 968 ("addr,a", var<string>("localhost:5000"), "Network address of FSC") 969 ("sensor-pos-file", var<string>()->required(), "File with the positions of the 31 temperature sensors") 970 ("patch-pos-file", var<string>()->required(), "File with the positions of the 320 bias patches") 852 971 ("quiet,q", po_bool(true), "Disable printing contents of all received messages (except dynamic data) in clear text.") 853 972 ; … … 868 987 { 869 988 cout << 870 "The f tmctrl controls the FSC (FACT Slow Control) board.\n"989 "The fscctrl controls the FSC (FACT Slow Control) board.\n" 871 990 "\n" 872 991 "The default is that the program is started without user intercation. "
Note:
See TracChangeset
for help on using the changeset viewer.