Index: trunk/Poubelle/archTOI.old/toiproducer.cc
===================================================================
--- trunk/Poubelle/archTOI.old/toiproducer.cc	(revision 534)
+++ trunk/Poubelle/archTOI.old/toiproducer.cc	(revision 555)
@@ -57,5 +57,5 @@
   // should be nothing left
   if (!extraopts.empty()) return false;
-  
+
   return true;
 }
@@ -129,6 +129,7 @@
 
 class comp2nd { public:bool operator()(pair<long, double> const& a, long b) {return a.first<b;}};
-
-deque<pair<long, double> >::const_iterator TOIProducer::findHist(TOI const& toi,long sampleNum) {
+class comp2ndI { public:bool operator()(long a, pair<long, double> const& b) {return a<b.first;}};
+
+deque<pair<long, double> >::const_iterator TOIProducer::findHistL(TOI const& toi,long sampleNum) {
   CHKPROD
   deque<pair<long, double> >& h = history[toi.ref];
@@ -136,7 +137,18 @@
 }
 
-deque<pair<long, double> >::const_iterator TOIProducer::findHist(deque<pair<long, double> >& h,long sampleNum) {
+deque<pair<long, double> >::const_iterator TOIProducer::findHistL(deque<pair<long, double> >& h,long sampleNum) {
   return lower_bound(h.begin(), h.end(), sampleNum, comp2nd());
 }
+
+deque<pair<long, double> >::const_iterator TOIProducer::findHistH(TOI const& toi,long sampleNum) {
+  CHKPROD
+  deque<pair<long, double> >& h = history[toi.ref];
+  return upper_bound(h.begin(), h.end(), sampleNum, comp2ndI());
+}
+
+deque<pair<long, double> >::const_iterator TOIProducer::findHistH(deque<pair<long, double> >& h,long sampleNum) {
+  return upper_bound(h.begin(), h.end(), sampleNum, comp2ndI());
+}
+
 
 bool TOIProducer::canGetValue(long sampleNum, TOI const& toi) {
@@ -145,5 +157,5 @@
   if (h.empty()) return false;
   if (sampleNum < h.front().first || sampleNum > h.back().first) return false;
-  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  deque<pair<long, double> >::const_iterator i = findHistL(h, sampleNum);
   if (i == h.end()) return false;
   return ((*i).first == sampleNum);
@@ -163,5 +175,5 @@
   deque<pair<long, double> >& h = history[toi.ref];
   if (h.empty()) return false;
-  return (sampleNum > h.back().first && sampleNum <= h.front().first);
+  return (sampleNum > h.front().first && sampleNum <= h.back().first);
    // Must be inside, otherwise we don't know if it is prev or simply past
 }
@@ -171,5 +183,5 @@
   deque<pair<long, double> >& h = history[toi.ref];
   if (h.empty()) return false;
-  return (sampleNum >= h.back().first && sampleNum < h.front().first);
+  return (sampleNum >= h.front().first && sampleNum < h.back().first);
 }
 
@@ -179,5 +191,5 @@
 //       << h.front().first 
 //       << " " << h.back().first << endl;
-  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  deque<pair<long, double> >::const_iterator i = findHistL(h, sampleNum);
   if (i == h.end()) return -999999;
 //  cout << "found " << (*i).first << endl;
@@ -189,10 +201,12 @@
 double TOIProducer::getPrevValue(long& sampleNum, TOI const& toi) {
   deque<pair<long, double> >& h = history[toi.ref];
-  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  deque<pair<long, double> >::const_iterator i = findHistH(h, sampleNum);
   if (i == h.end()) return -999999;
-  if ((*i).first == sampleNum) {
+  pair<long, double> tstpair = *i;
+  while ((*i).first >= sampleNum) {
     if (i == history[toi.ref].begin()) {sampleNum = -99999 ;return -9999;}
     i--;
   }
+  tstpair = *i;
   sampleNum = (*i).first;
   return (*i).second;
@@ -201,10 +215,12 @@
 double TOIProducer::getNextValue(long& sampleNum, TOI const& toi) {
   deque<pair<long, double> >& h = history[toi.ref];
-  deque<pair<long, double> >::const_iterator i = findHist(h, sampleNum);
+  deque<pair<long, double> >::const_iterator i = findHistL(h, sampleNum);
   if (i == h.end()) return -999999;
-  if ((*i).first == sampleNum) {
+  pair<long, double> tstpair = *i;
+  while ((*i).first <= sampleNum) {
     if (i == history[toi.ref].end()) {sampleNum = -99999 ;return -9999;}
     i++;
   }
+  tstpair=*i;
   sampleNum = (*i).first;
   return (*i).second;
@@ -212,11 +228,11 @@
 
 void TOIProducer::computedValue(TOI const& toi, long sampleNum, double value) {
-  map<int, deque<pair<long, double> > >::iterator i = history.find(toi.ref);
-  if (i == history.end()) throw ArchExc("computedValue : bad TOI " + toi.name);
-  deque<pair<long, double> >& h = (*i).second;
+  //map<int, deque<pair<long, double> > >::iterator i = history.find(toi.ref);
+  //if (i == history.end()) throw ArchExc("computedValue : bad TOI " + toi.name);
+  //deque<pair<long, double> >& h = (*i).second;
+  deque<pair<long, double> >& h = history[toi.ref];
   if (!h.empty() && sampleNum <= h.back().first)
     throw ArchExc("computedValue : sampleNum not in sequence for " + toi.name);
   h.push_back(pair<long,double>(sampleNum,value));
-  
   for (map<TOIAbsorber*, set<TOI> >::iterator j = clients.begin(); j != clients.end(); j++) {
     set<TOI>& tois = (*j).second;
