Hi,
I'm having a problem with values read in from a file and assigned to a vector using push_back are not updating. After the values have been assigned, the vector returns zero for all of its values for a fixed time after assignment. The behavior is consistent, and I do not understand why it is happening.
Here are the primary methods involved:
Code:
process(Event &event)
{
Module& md = *(_decoder->module(event.id()));
if (_doonce) {
std::cout << "Calling initPedestals for module: " << event.id()
<< " on event: " << event.event() << std::endl;
initPedestals(md);
}
std::vector<double>& pedestals = (md.pedestals());
// now we find the max channel
ChannelList& channels = event.channels();
ChannelList::iterator it = channels.begin();
int channel;
double max;
for (;it!=channels.end();++it) {
double signal = (*it)->signal() - pedestals.at((*it)->channel());
std::cout << "Event: " << event.event()
<< " Channel: " << (*it)->channel()
<< " Signal: " << (*it)->signal()
<< " Pedestal: " << pedestals.at((*it)->channel())
<< " S - P: " << signal << std::endl;
if (signal>max) {
max = signal;
channel = (*it)->channel();
}
}
std::stringstream ss;
ss << event.date() << ' ' << event.id() << ' ' << event.event() << ' '
<< channel << ' ' << max << '\n';
_fman.file(_fname).write(ss.str().c_str(),ss.str().size());
// _fman.file(_fname) << ss.str();
_doonce = false;
}
initPedestals(Module &md)
{
_pflist.insert(PFEntry(256,"pedestals.txt"));
PFList::iterator it = _pflist.find(md.id());
if (it!=_pflist.end()) {
std::string name = it->second;
FileManager fman;
fman.open(name,FileManager::Old);
std::fstream& file = fman.file(name);
while (file.good()) {
double val;
file >> val;
if (!file.good()) break;
std::cout << "ped = " << val;
md.pedestals().push_back(val);
file >> val;
if (!file.good()) break;
std::cout << " noise = " << val << std::endl;
md.noise().push_back(val);
}
for (int i=0;i<(int)md.pedestals().size();i++) {
std::cout << "pedestal = " << md.pedestals()[i];
std::cout << " noise = " << md.noise()[i] << std::endl;
}
}
else
for (int i=0;i<md.ntot();i++) {
md.pedestals().push_back(0);
md.noise().push_back(0);
}
}
Sorry if the code is a bit ugly, I have been throwing print statements in everywhere to try and debug.
All of the print statements indicate that the value of all of the pedestal entries are 0 for about the first 75000 calls, at which point they begin to reflect the values read in from the file. However, the print statements also verify that the values are being read in at the beginning of the first call. I can't explain the delay between assignment of values using "push_back" in initPedestals and the return of the values using "at" in process. (or the direct access operator in the print statement in initPedestals either!)
If anyone can see what the problem is, or give me an idea of what might be causing this so I can track it down in the rest of my code, it would be much appreciated!