sum of vector elements

Hi,

i m reading 2 measurements from oscilloscope for eash diver setting( 15) i am geeting the desired out put 2 measurements for each setting, now i want to add these vector element. i want the sum value for each setting, but my vector size is one and i cannot get the sum values, can anyone have a look

m_step[1] = 1;
Last edited on
void TDctrlMeasurement::ReadMem(TAlpide *chip, int ARegion, int AOffset, int &AValue,
bool &exception)
{
if ((ARegion > 31) || (AOffset > 127)) {
std::cout << "ReadMem: invalid parameters" << std::endl;
return;
}
uint16_t LowAdd = Alpide::REG_RRU_MEB_LSB_BASE | (ARegion << 11) | AOffset;
uint16_t HighAdd = Alpide::REG_RRU_MEB_MSB_BASE | (ARegion << 11) | AOffset;

uint16_t LowVal, HighVal;
int err;

try {
err = chip->ReadRegister(LowAdd, LowVal);
}
catch (std::exception &e) {
exception = true;
// std::cout << "Exception " << e.what() << " when reading low value" << std::endl;
return;
}
exception = false;
if (err >= 0) {
try {
err = chip->ReadRegister(HighAdd, HighVal);
}
catch (std::exception &e) {
// std::cout << "Exception " << e.what() << " when reading high value" << std::endl;
exception = true;
return;
}
}

if (err < 0) {
std::cout << "Cannot read chip register." << std::endl;
throw runtime_error("Cannot read chip register.");
}

// Note to self: if you want to shorten the following lines,
// remember that HighVal is 16 bit and (HighVal << 16) will yield 0
// :-)
AValue = (HighVal & 0xff);
AValue <<= 16;
AValue |= LowVal;
}


/// Old test measurement from FIFO scan, adapt if necessary
bool TDctrlMeasurement::TestPattern(int pattern, bool &exception)
{
int readBack;
WriteMem(m_testChip, m_region, m_offset, pattern);
ReadMem(m_testChip, m_region, m_offset, readBack, exception);
if (exception) return false;
if (readBack != pattern) return false;
return true;
}

void TDctrlMeasurement::LoopEnd(int loopIndex)
{
if (loopIndex == 2) {
while (!(m_mutex->try_lock()))
;
m_histoQue->push_back(*m_histo);
m_mutex->unlock();
m_histo->Clear();
}
}


// Execute does the actual measurement
// this method has to implement the amplitude measurement for one single chip,
// for one driver setting
// results are saved into m_histo as described below
void TDctrlMeasurement::Execute()
{
bool exception;
common::TChipIndex idx;
idx.boardIndex = m_boardIndex;
idx.chipId = m_testChip->GetConfig()->GetChipId();
idx.dataReceiver = m_testChip->GetConfig()->GetParamValue("RECEIVER");

// skip disabled chips and OB slaves


for (int i=0; i<2; i++){


float peak_p;

if ((m_testChip->GetConfig()->IsEnabled()) &&
(m_testChip->GetConfig()->GetParamValue("LINKSPEED") != -1)) {

scope.single_capture(); // Stop on first trigger
TestPattern(0xFFFFFF, exception); // Generate data on bus
/*if (exception) { // Should these be ignored?
std::cout << "Fifo scan failed" << std::endl;
throw runtime_erro("Fifo scan failed");
}*/

scope.wait_for_trigger(10); // Check and wait until triggered


// Do the measurement here, value has to be saved in the histogram
// with THisto::Set, idx indicates the chip, e.g.
// m_histo->Set(idx, m_value[1], measured amplitude)
// to enter the measured amplitude for the current chip and the current
// driver setting
if ((m_testChip->GetConfig()->GetCtrInt() == 0) && (FindBoardIndex(m_testChip) == 0)) {
// Retrieve measuremts

scope.en_measure_ch(3); // Set measurement to read from scope channel 3
scope.get_meas();
peak_p=scope.ch3.peak;
//std::cout<<"peak_p"<<peak_p<<"the single measurement "<<scope.ch3.peak<<std::endl;


usleep(5000);

}
std::vector<float> myvector;
myvector.push_back(peak_p);
vector<float>::iterator it;

//printing all elements
cout << "myvector elements are: ";

for (it = myvector.begin(); it != myvector.end(); it++)

cout << *it << " ";
cout << endl;
//std::cout<<"peak_p"<<peak_p<<"the single measurement "<<scope.ch3.peak<<std::endl;

int a=2;
float averagepeak_p=0;
float standardDeviationnom = 0;
float sumofpeaks=0;


for (unsigned int i=0; i<myvector.size(); i++){
sumofpeaks+=myvector[i];

//std::cout<<"sumofpeaks"<<sumofpeaks<<std::endl;

averagepeak_p=sumofpeaks/a;

//std::cout<<"averagepeak_p"<<averagepeak_p<<"the single measurement "<<scope.ch3.peak<<std::endl;

/// averagepeak_p=peak_p/a;

standardDeviationnom += (pow(myvector[i] - averagepeak_p, 2));
}


float standarddeviation=sqrt(standardDeviationnom/2);
//std::cout<<"Standard Deviation "<<standarddeviation<<"and the last masurement peak_p is "<<scope.ch3.peak<<std::endl;
//std::cout<<"peak_p is "<<peak_p<<"the single measurement "<<scope.ch3.peak<<std::endl;
//m_histo->Set(idx, m_value[i], peak_p, scope.ch3.peak); // Update plots
//std::cout<<"amp_p is "<<peak_p<<"the single measurement "<<scope.ch3.amp<<std::endl;
m_histo->Set(idx,m_value[0], peak_p, standarddeviation);
m_histo->Set(idx, m_value[0], amp_p, scope.ch3.amp);
m_histo->Set(idx, m_value[0], rtim_p, scope.ch3.rtim);
m_histo->Set(idx, m_value[0], ftim_p, scope.ch3.ftim);
scope.en_measure_ch(4);
scope.get_meas();
//std::cout<<"peak_n is "<<peak_n<<"the single measurement "<<scope.ch4.peak<<std::endl;
m_histo->Set(idx, m_value[0], peak_n, scope.ch4.peak);
//std::cout<<"amp_n is "<<amp_p<<"the single measurement "<<scope.ch4.amp<<std::endl;
m_histo->Set(idx, m_value[0], amp_n, scope.ch4.amp);
m_histo->Set(idx, m_value[0], rtim_n, scope.ch4.rtim);
m_histo->Set(idx, m_value[0], ftim_n, scope.ch4.ftim);


}
else {
scope.en_measure_ch(1);
scope.get_meas();
//std::cout<<"reading the scope peak_p in else"<<scope.ch1.peak<<std::endl;
m_histo->Set(idx, m_value[0], peak_p, scope.ch1.peak);
m_histo->Set(idx, m_value[0], amp_p, scope.ch1.amp);
m_histo->Set(idx, m_value[0], rtim_p, scope.ch1.rtim);
m_histo->Set(idx, m_value[0], ftim_p, scope.ch1.ftim);
scope.en_measure_ch(2);
scope.get_meas();
//std::cout<<"reading the scope peak_n in else"<<scope.ch2.peak<<std::endl;
m_histo->Set(idx, m_value[0], peak_n, scope.ch2.peak);
m_histo->Set(idx, m_value[0], amp_n, scope.ch2.amp);
m_histo->Set(idx, m_value[0], rtim_n, scope.ch2.rtim);
m_histo->Set(idx, m_value[0], ftim_n, scope.ch2.ftim);
}
}

// here only to avoid error "idx set but not used"
// remove in implementation
} // m_histo->Set(idx, m_value[1], 0);



void TDctrlMeasurement::Terminate()
{
if (m_disableManchesterEncoding == 1) {
for (unsigned int i = 0; i < m_chips.size(); i++) {
if (!m_chips.at(i)->GetConfig()->IsEnabled()) continue;
m_chips.at(i)->GetConfig()->SetDisableManchester(true);
AlpideConfig::ConfigureCMU(m_chips.at(i));
}
}

TScan::Terminate();
scope.close();

m_running = false;
}
now i want to add these vector element
What vector? Where do you add elements to the vector?
First of all, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

We can see:
1
2
3
4
5
6
float peak_p;
peak_p = scope.ch3.peak;

std::vector<float> myvector;
myvector.push_back( peak_p );
// assert: myvector has exactly one float in it 
Topic archived. No new replies allowed.