Changeset 11860 for trunk/FACT++/src


Ignore:
Timestamp:
08/09/11 14:49:58 (14 years ago)
Author:
tbretz
Message:
Implemented reading referencevoltages from file -- preliminary.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/biasctrl.cc

    r11858 r11860  
    425425    }
    426426
     427    bool SetReferenceVoltage(const vector<float> &volt)
     428    {
     429        if (volt.size()!=kNumChannels)
     430        {
     431            ostringstream out;
     432            out << "SetReferenceVoltage - Given vector has " << volt.size() << " elements - expected " << kNumChannels << endl;
     433            Error(out);
     434            return false;
     435        }
     436
     437        for (size_t i=0; i<volt.size(); i++)
     438            fRefVolt[i] = volt[i]*4096/90;
     439
     440        return true;
     441    }
     442
     443    void ApplyReferenceVoltage()
     444    {
     445        for (size_t i=0; i<fRefVolt.size(); i++)
     446            SetVoltage(i, fRefVolt[i]);
     447    }
     448
    427449    void SetVerbose(bool b)
    428450    {
     
    696718            ("");
    697719
     720        AddEvent("APPLY_REFERENCE_VOLTAGE", kStateConnected)
     721            (Wrapper(bind(&ConnectionBias::ApplyReferenceVoltage, &fBias)))
     722            ("");
     723
    698724        AddEvent("ADAPT_VOLTAGES", kStateConnected)
    699725            (Wrapper(bind(&ConnectionBias::AdaptVoltages, &fBias)))
     
    711737        fBias.SetEndpoint(conf.Get<string>("dev"));
    712738        T::Message("Setting device to "+fBias.URL());
     739
     740        // --------------------------------------------------------------------------
     741
     742        ifstream fin("FACTmapV5.txt");
     743
     744        int l = 0;
     745
     746        vector<float> vec(ConnectionBias::kNumChannels);
     747
     748        string buf;
     749        while (getline(fin, buf, '\n'))
     750        {
     751            if (l>1439)
     752                break;
     753
     754            buf = Tools::Trim(buf);
     755            if (buf[0]=='#')
     756                continue;
     757
     758            stringstream str(buf);
     759
     760            int   idummy, board, channel;
     761            float fdummy, volt;
     762
     763            str >> idummy >> idummy >> idummy >> idummy >> idummy;
     764            str >> volt;
     765            str >> board;
     766            str >> channel;
     767            str >> fdummy >> fdummy >> fdummy;
     768
     769            if (channel+32*board>=ConnectionBias::kNumChannels)
     770            {
     771                T::Error("Invalid board/channel read from FACTmapV5.txt.");
     772                return 1;
     773            }
     774
     775            vec[channel+32*board] = volt;
     776            l++;
     777        }
     778
     779        if (l!=1440)
     780        {
     781            T::Error("Reading reference voltages from FACTmapV5.txt failed.");
     782            return 2;
     783        }
     784
     785        if (!fBias.SetReferenceVoltage(vec))
     786        {
     787            T::Error("Setting reference voltages failed.");
     788            return 3;
     789        }
     790
     791        // --------------------------------------------------------------------------
    713792
    714793        fBias.Connect();
Note: See TracChangeset for help on using the changeset viewer.