/[PAMELA software]/yoda/event/EventCounter.cpp
ViewVC logotype

Diff of /yoda/event/EventCounter.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2.0 by kusanagi, Tue Sep 21 20:49:57 2004 UTC revision 2.3 by kusanagi, Thu Dec 9 08:47:42 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $   * $Source: /home/cvsmanager/yoda/event/EventCounter.cpp,v $
3   * $Id: EventCounter.cpp,v 1.7 2004/09/21 20:23:37 kusanagi Exp $   * $Id: EventCounter.cpp,v 2.2 2004/12/03 22:04:04 kusanagi Exp $
4   * $Author: kusanagi $   * $Author: kusanagi $
5   *   *
6   * Implementation of the EventCounter class.   * Implementation of the EventCounter class.
# Line 56  EventCounter::EventCounter(int run): Line 56  EventCounter::EventCounter(int run):
56    TrkInit(0),    TrkInit(0),
57    TofInit(0),    TofInit(0),
58    TrgInit(0),    TrgInit(0),
59      NdInit(0),
60      S4Init(0),
61    CalAlarm(0),    CalAlarm(0),
62    AcAlarm(0),    AcAlarm(0),
63    TrkAlarm(0),    TrkAlarm(0),
64    TrgAlarm(0),    TrgAlarm(0),
65    TofAlarm(0),    TofAlarm(0),
66      S4Alarm(0),
67    RunNumber(run) {    RunNumber(run) {
68      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));
69      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));
70      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse1));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1,  &CalibCalPulse1));
71      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse2));      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse2));
72      CMap.insert(CounterMap::value_type(PacketType::Physics,         &Physics));      CMap.insert(CounterMap::value_type(PacketType::Physics,         &Physics));
73      CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth,    &CalibTrkBoth));      CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth,    &CalibTrkBoth));
# Line 95  EventCounter::EventCounter(int run): Line 98  EventCounter::EventCounter(int run):
98      CMap.insert(CounterMap::value_type(PacketType::CalInit,         &CalInit));      CMap.insert(CounterMap::value_type(PacketType::CalInit,         &CalInit));
99      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));
100      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));
101      CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &TrgInit));      CMap.insert(CounterMap::value_type(PacketType::NdInit,          &NdInit));
102        CMap.insert(CounterMap::value_type(PacketType::S4Init,          &S4Init));
103      CMap.insert(CounterMap::value_type(PacketType::CalAlarm,        &CalAlarm));      CMap.insert(CounterMap::value_type(PacketType::CalAlarm,        &CalAlarm));
104      CMap.insert(CounterMap::value_type(PacketType::AcAlarm,         &AcAlarm));      CMap.insert(CounterMap::value_type(PacketType::AcAlarm,         &AcAlarm));
105      CMap.insert(CounterMap::value_type(PacketType::TrkAlarm,        &TrkAlarm));      CMap.insert(CounterMap::value_type(PacketType::TrkAlarm,        &TrkAlarm));
106      CMap.insert(CounterMap::value_type(PacketType::TrgAlarm,        &TrgAlarm));      CMap.insert(CounterMap::value_type(PacketType::TrgAlarm,        &TrgAlarm));
107      CMap.insert(CounterMap::value_type(PacketType::TofAlarm,        &TofAlarm));      CMap.insert(CounterMap::value_type(PacketType::TofAlarm,        &TofAlarm));
108        CMap.insert(CounterMap::value_type(PacketType::S4Alarm,         &S4Alarm));
109  }  }
110    
111  /**  /**
112   * Increment the event counter for a certain packet.   * Increment the event counter for a certain packet.
113   * @param type Event type to be incremented.   * @param type Event type to be incremented.
114   */   */
115  void EventCounter::Increment(PacketType const * type) {  void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
116    CounterMap::iterator p = CMap.find(type);    CounterMap::iterator p = CMap.find(type);
117    if (p != CMap.end()) {    if (p != CMap.end()) {
118      int *counter = p->second;      int *counter = p->second;
119      (*counter)++;      (*counter)++;
120      oss.flush();      oss.str("");
121      oss << " Counter." <<  type->GetName() << " = " <<  (*counter);      oss << " Counter." <<  type->GetName() << " = " <<  (*counter);
122      logger->debug(oss.str().c_str());      logger->debug(oss.str().c_str());
123    } else {    } else {
124      oss.flush();      throw NotExistingCounterException(type->GetName().c_str());
     oss <<  " No counter for packet type " <<  type->GetName();  
     logger->warn(oss.str().c_str());  
125    }    }
126  }  }
127    
# Line 130  void EventCounter::Increment(PacketType Line 133  void EventCounter::Increment(PacketType
133   * number of the last read event of that type.   * number of the last read event of that type.
134   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
135   */   */
136  int EventCounter::Get(PacketType const * type) const {  int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){
137    const CounterMap::const_iterator p = CMap.find(type);    const CounterMap::const_iterator p = CMap.find(type);
138    if (p != CMap.end()) {    if (p != CMap.end()) {
139      const int *counter = p->second;      const int *counter = p->second;
140      return *counter;      return *counter;
141    } else {    } else {
142      oss.flush();      throw NotExistingCounterException(type->GetName().c_str());
     oss <<  " No counter for packet type " <<  type->GetName();  
     logger->warn(oss.str().c_str());  
143      return -1;      return -1;
144    }    }
145  }  }
# Line 149  int EventCounter::Get(PacketType const * Line 150  int EventCounter::Get(PacketType const *
150   * @return The next counter of that packet type.   * @return The next counter of that packet type.
151   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
152   */   */
153  int EventCounter::Next(PacketType const * type) const {  int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){
154    const CounterMap::const_iterator p = CMap.find(type);    const CounterMap::const_iterator p = CMap.find(type);
155    if (p != CMap.end()) {    if (p != CMap.end()) {
156      const int *counter = p->second;      const int *counter = p->second;
157      return *counter + 1;      return *counter + 1;
158    } else {    } else {
159      oss.flush();      throw NotExistingCounterException(type->GetName().c_str());
     oss <<  " No counter for packet type " <<  type->GetName();  
     logger->warn(oss.str().c_str());  
160      return -1;      return -1;
161    }    }
162  }  }
# Line 168  int EventCounter::Next(PacketType const Line 167  int EventCounter::Next(PacketType const
167   */   */
168  void EventCounter::PrintCounters() const {  void EventCounter::PrintCounters() const {
169    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {    for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {
170    oss.flush();    oss.str("");
171    oss <<  " Counter." <<  (p->first)->GetName()  <<   " = " <<  (*p->second);    oss <<  " Counter." <<  (p->first)->GetName()  <<   " \t \t " <<  (*p->second);
172    logger->warn(oss.str().c_str());    logger->warn(oss.str().c_str());
   std::cout <<  " Counter." <<  (p->first)->GetName()  <<   "\t = \t" <<  (*p->second) << "\n";  
173    }    }
174  }  }

Legend:
Removed from v.2.0  
changed lines
  Added in v.2.3

  ViewVC Help
Powered by ViewVC 1.1.23