/** @file * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $ * $Id: EventCounter.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $ * $Author: kusanagi $ * * Implementation of the EventCounter class. */ #include #include "EventCounter.h" #include "PscuHeader.h" static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.raw.EventCounter"); using namespace pamela; /** * Create a new event counter for a certain run. * @param run Run number. */ EventCounter::EventCounter(int run): // New Packets. Pscu(-1), Physics(-1), Forced_Pkt(-1), Calib_Trk1(-1), Calib_Trk2(-1), Calib_Cal(-1), Calib_Trd(-1), Calib_Tof(-1), Calib_S4(-1), Run_Header(-1), Run_Trailer(-1), Alarm(-1), Khb(-1), Log(-1), VarDump(-1), ArrDump(-1), TabDump(-1), Tmtc(-1), Mcmd(-1), HA_Header_E5(-1), RunNumber(run) { CMap.insert(CounterMap::value_type(PacketType::Pscu, &Pscu)); CMap.insert(CounterMap::value_type(PacketType::Physics, &Physics)); CMap.insert(CounterMap::value_type(PacketType::ForcedPkt, &Forced_Pkt)); CMap.insert(CounterMap::value_type(PacketType::CalibTrk1, &Calib_Trk1)); CMap.insert(CounterMap::value_type(PacketType::CalibTrk2, &Calib_Trk2)); CMap.insert(CounterMap::value_type(PacketType::CalibCal, &Calib_Cal)); CMap.insert(CounterMap::value_type(PacketType::CalibTrd, &Calib_Trd)); CMap.insert(CounterMap::value_type(PacketType::CalibTof, &Calib_Tof)); CMap.insert(CounterMap::value_type(PacketType::CalibS4, &Calib_S4)); CMap.insert(CounterMap::value_type(PacketType::RunHeader, &Run_Header)); CMap.insert(CounterMap::value_type(PacketType::RunTrailer, &Run_Trailer)); CMap.insert(CounterMap::value_type(PacketType::Alarm, &Alarm)); CMap.insert(CounterMap::value_type(PacketType::Khb, &Khb)); CMap.insert(CounterMap::value_type(PacketType::Log, &Log)); CMap.insert(CounterMap::value_type(PacketType::VarDump, &VarDump)); CMap.insert(CounterMap::value_type(PacketType::ArrDump, &ArrDump)); CMap.insert(CounterMap::value_type(PacketType::TabDump, &TabDump)); CMap.insert(CounterMap::value_type(PacketType::Tmtc, &Tmtc)); CMap.insert(CounterMap::value_type(PacketType::Mcmd, &Mcmd)); CMap.insert(CounterMap::value_type(PacketType::HA_Header_E5, &HA_Header_E5)); } /** * Increment the event counter for a certain packet. * @param type Event type to be incremented. */ void EventCounter::Increment(PacketType const * type) { CounterMap::iterator p = CMap.find(type); if (p != CMap.end()) { int *counter = p->second; (*counter)++; cat << log4cpp::Priority::INFO << " Counter." << type->GetName() << " = " << (*counter) << "\n " << log4cpp::CategoryStream::ENDLINE; } else { cat << log4cpp::Priority::INFO << " No counter for packet type " << type->GetName() << "\n " << log4cpp::CategoryStream::ENDLINE; } } /** * Get the counter corresponding to a certain packet type. * @param type Event type to be incremented. * @return The counter of that packet type. For the current event type, * this is the actual event number. For all other types, this is the event * number of the last read event of that type. * @retval -1 if there was no event of this type. */ int EventCounter::Get(PacketType const * type) const { const CounterMap::const_iterator p = CMap.find(type); if (p != CMap.end()) { const int *counter = p->second; return *counter; } else { cat << log4cpp::Priority::INFO << " No counter for packet type " << type->GetName() << "\n " << log4cpp::CategoryStream::ENDLINE; return -1; } } /** * Get the counter of the next event corresponding to a certain packet type. * @param type Event type to be incremented. * @return The next counter of that packet type. * @retval -1 if there was no event of this type. */ int EventCounter::Next(PacketType const * type) const { const CounterMap::const_iterator p = CMap.find(type); if (p != CMap.end()) { const int *counter = p->second; return *counter + 1; } else { cat << log4cpp::Priority::WARN << " No counter for packet type " << type->GetName() << "\n " << log4cpp::CategoryStream::ENDLINE; return -1; } } /** * Get the all the counters * @retval -1 if there was no event of this type. */ void EventCounter::PrintCounters() const { for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) { cat << log4cpp::Priority::INFO << " Counter." << (p->first)->GetName() << " = " << (*p->second) << "\n " << log4cpp::CategoryStream::ENDLINE; } }