Back to index

CErrorCollection.C

 
//----------------------------------------------------------------------------- 
//  $Header: /asis/offline/ceres/cool/project/RCS/CErrorCollection.C,v 1.3 1997/07/21 09:38:20 messer Exp $ 
// 
//  COOL Program Library   
//  Copyright (C) CERES collaboration, 1996 
// 
//  Implementation of class CErrorCollection. 
// 
//----------------------------------------------------------------------------- 
#include "CErrorCollection.h" 
#include <strstream.h> 
#include <fstream.h> 
#include <stdio.h> 
 
unsigned errorHashFunction(const CString& str) 
{ 
   return str.hash(); 
} 
 
CErrorCollection::CErrorCollection()  
{ 
   eventCounter      = 0; 
   eventDictionary   = new RWTValHashDictionary<CString, CBoolean>(errorHashFunction); 
   counterDictionary = new RWTValHashDictionary<CString, int>(errorHashFunction); 
} 
 
CErrorCollection::~CErrorCollection()  
{ 
   delete eventDictionary;  
   delete counterDictionary;  
} 
    
void CErrorCollection::remember(const CString& key)  
{ 
   eventDictionary->insertKeyAndValue(key, True); 
    
   int newValue = getCounter(key) + 1; 
   counterDictionary->insertKeyAndValue(key, newValue);  
} 
 
void CErrorCollection::remember(const CString& key, int receiver)  
{ 
   remember(key); 
 
   CString fullKey = getFullKey(key, receiver); 
    
   eventDictionary->insertKeyAndValue(fullKey, True); 
    
   int newValue = getCounter(fullKey) + 1; 
   counterDictionary->insertKeyAndValue(fullKey, newValue);  
} 
 
int CErrorCollection::getCounter(const CString& key) const 
{  
   int val = 0; 
   if (counterDictionary->findValue(key, val))  
      return val; 
   else 
      return 0; 
}   
 
int CErrorCollection::getCounter(const CString& key, int receiver) const 
{  
   int val = 0; 
   if (counterDictionary->findValue(getFullKey(key, receiver), val))  
      return val; 
   else 
      return 0; 
}   
 
CBoolean CErrorCollection::inLastEvent(const CString& key) const 
{ 
   CBoolean found; 
   if (eventDictionary->findValue(key, found)) 
      return found; 
   else 
      return False; 
} 
 
CBoolean CErrorCollection::inLastEvent(const CString& key, int receiver) const 
{ 
   CBoolean found; 
   if (eventDictionary->findValue(getFullKey(key, receiver), found)) 
      return found; 
   else 
      return False; 
} 
 
void CErrorCollection::newEvent() 
{ 
   eventCounter++; 
   reset(); 
} 
 
CString CErrorCollection::getFullKey(const CString& key, int receiver) const 
{ 
  char *buf = new char[10]; 
  sprintf(buf,"%3d\0",receiver); 
  CString fullKey = key + " receiver " + buf; 
  delete [] buf; 
  return fullKey; 
} 
 
size_t CErrorCollection::entries() const 
{ 
   return counterDictionary->entries(); 
} 
 
void CErrorCollection::reset() 
{ 
   eventDictionary->clear(); 
} 
 
void CErrorCollection::resetAll() 
{ 
   eventDictionary->clear(); 
   counterDictionary->clear(); 
} 
 
void CErrorCollection::printSummary() const 
{ 
   if (counterDictionary->isEmpty()) { 
      clog << "dictionary has no entries" << endl; 
      return; 
   } 
    
   RWTValHashDictionaryIterator<CString, int> iterator(*counterDictionary); 
   iterator.reset(*counterDictionary);                     // get valid starting point   
   // 
   //  Write all key/ value pairs in the dictionary 
   // 
 
   clog << "----------------------------------------------------------------------" << endl; 
   while (iterator())  
      clog << iterator.key() << ": " << iterator.value() << endl; 
   clog << "----------------------------------------------------------------------" << endl; 
 
} 
 
 
 
 
 
 
 
 
 
 
 

Back to index