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

Diff of /chewbacca/event/EventCounter.cpp

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

revision 1.1 by mocchiut, Tue Sep 23 07:19:51 2008 UTC revision 1.5 by mocchiut, Thu Feb 11 09:02:15 2010 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /repository/event/EventCounter.cpp,v $   * $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/event/EventCounter.cpp,v $
3   * $Id: EventCounter.cpp,v 1.2 2008-02-07 18:17:23 messineo Exp $   * $Id: EventCounter.cpp,v 1.4 2009/08/04 13:58:16 mocchiut Exp $
4   * $Author: messineo $   * $Author: mocchiut $
5   *   *
6   * Implementation of the EventCounter class.   * Implementation of the EventCounter class.
7   */   */
# Line 15  Line 15 
15  //marco  //marco
16  ////static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter"));  ////static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventCounter"));
17  static std::stringstream oss;  static std::stringstream oss;
18    
19  using namespace pamela;  using namespace pamela;
20    
21    
22    mapval::mapval(): count(0), name(""){ }
23    
24    mapval::mapval(TString n, Int_t *i): count(i), name(n){ }
25    
26    mappa::mappa(){  
27      val = 0;
28      this->Clear();
29    }
30    
31    void mappa::Clear(Option_t *t){
32      //    cout << " mappa clear" << endl;
33      t="";
34      if ( val ){
35        val->Delete();
36        val = 0;
37      };
38      fend = false;
39      entries = 0;
40    }
41    
42    void mappa::Set(){
43      //  cout << " in mappa set" << endl;
44      if (val) delete val;
45      val = new TClonesArray("pamela::mapval",47);
46      //  cout << " out mappa set" << endl;
47    }
48    
49    void mappa::Delete(Option_t *t){
50      //  cout << " mappa del" << endl;
51      if ( val ){
52        val->Delete();
53        val = 0;
54        //          delete val;
55      };
56      delete this;
57    }
58    
59    void mappa::Insert(TString nme, Int_t *valu){
60      //  cout << " mappa insert " << nme.Data() << " valu " << *valu << endl;
61      if ( !val ) this->Set();
62      TClonesArray &t = *val;
63      new(t[entries]) mapval(nme,valu);
64      entries++;
65    }
66    
67    mapval::mapval(const mapval &t){
68      name = t.name;
69      count = t.count;
70    }
71    
72    mapval* mappa::Find(TString n){
73      Bool_t fo = false;
74      fend = false;
75      mapval *c = NULL;
76      for (Int_t i=0; i < entries; i++){
77        c = (mapval*)val->At(i);
78        if ( c && !strcmp(c->name.Data(),n.Data()) ){
79          fo = true;
80          break;
81        };
82      };
83      if ( !fo ) fend = true;
84      return c;
85    }
86    
87  /**  /**
88   * Create a new event counter for a certain run.   * Create a new event counter for a certain run.
89   * @param run Run number.   * @param run Run number.
90   */   */
91  EventCounter::EventCounter(int run):  EventCounter::EventCounter(int run):
92          // New Packets.          // New Packets.
93      RunNumber(run),
94    Pscu(0),    Pscu(0),
95    PhysEndRun(0),    PhysEndRun(0),
96    CalibCalPulse1(0),    CalibCalPulse1(0),
# Line 31  EventCounter::EventCounter(int run): Line 99  EventCounter::EventCounter(int run):
99    CalibTrkBoth(0),    CalibTrkBoth(0),
100    CalibTrk1(0),    CalibTrk1(0),
101    CalibTrk2(0),    CalibTrk2(0),
102      CalibCal(0),
103    CalibTof(0),    CalibTof(0),
104    CalibS4(0),    CalibS4(0),
105    CalibCalPed(0),    CalibCalPed(0),
106    Calib1_Ac1(0),    Calib1_Ac1(0),
   Calib2_Ac1(0),  
107    Calib1_Ac2(0),    Calib1_Ac2(0),
108      Calib2_Ac1(0),
109    Calib2_Ac2(0),    Calib2_Ac2(0),
   CalibCal(0),  
110    RunHeader(0),    RunHeader(0),
111    RunTrailer(0),    RunTrailer(0),
112    CalibHeader(0),    CalibHeader(0),
# Line 69  EventCounter::EventCounter(int run): Line 137  EventCounter::EventCounter(int run):
137    S4Alarm(0),    S4Alarm(0),
138    Ac2Alarm(0),    Ac2Alarm(0),
139    TsbT(0),    TsbT(0),
140    TsbB(0),    TsbB(0) {
141    RunNumber(run) {      CMap.Set();
142      CMap.insert(CounterMap::value_type(PacketType::Pscu,            &Pscu));      CMap.Insert(PacketType::Physics->GetName(),         &Physics);
143      CMap.insert(CounterMap::value_type(PacketType::PhysEndRun,      &PhysEndRun));      CMap.Insert(PacketType::Pscu->GetName(),            &Pscu);
144      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse1,  &CalibCalPulse1));      CMap.Insert(PacketType::RunHeader->GetName(),       &RunHeader);
145      CMap.insert(CounterMap::value_type(PacketType::CalibCalPulse2,  &CalibCalPulse2));      CMap.Insert(PacketType::RunTrailer->GetName(),      &RunTrailer);
146      CMap.insert(CounterMap::value_type(PacketType::Physics,         &Physics));      CMap.Insert(PacketType::PhysEndRun->GetName(),      &PhysEndRun);
147      CMap.insert(CounterMap::value_type(PacketType::CalibTrkBoth,    &CalibTrkBoth));      CMap.Insert(PacketType::InitHeader->GetName(),      &InitHeader);
148      CMap.insert(CounterMap::value_type(PacketType::CalibTrk1,       &CalibTrk1));      CMap.Insert(PacketType::InitTrailer->GetName(),     &InitTrailer);  
149      CMap.insert(CounterMap::value_type(PacketType::CalibTrk2,       &CalibTrk2));      CMap.Insert(PacketType::Log->GetName(),             &Log);
150      CMap.insert(CounterMap::value_type(PacketType::CalibTof,        &CalibTof));      CMap.Insert(PacketType::VarDump->GetName(),         &VarDump);
151      CMap.insert(CounterMap::value_type(PacketType::CalibS4,         &CalibS4));      CMap.Insert(PacketType::ArrDump->GetName(),         &ArrDump);
152      CMap.insert(CounterMap::value_type(PacketType::CalibCalPed,     &CalibCalPed));      CMap.Insert(PacketType::TabDump->GetName(),         &TabDump);
153      CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac1,      &Calib1_Ac1));      CMap.Insert(PacketType::Tmtc->GetName(),            &Tmtc);
154      CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac1,      &Calib2_Ac1));      CMap.Insert(PacketType::Mcmd->GetName(),            &Mcmd);
155      CMap.insert(CounterMap::value_type(PacketType::Calib1_Ac2,      &Calib1_Ac2));      CMap.Insert(PacketType::TsbT->GetName(),            &TsbT);
156      CMap.insert(CounterMap::value_type(PacketType::Calib2_Ac2,      &Calib2_Ac2));      CMap.Insert(PacketType::TsbB->GetName(),            &TsbB);
157      CMap.insert(CounterMap::value_type(PacketType::CalibCal,        &CalibCal));      CMap.Insert(PacketType::CalibHeader->GetName(),     &CalibHeader);
158      CMap.insert(CounterMap::value_type(PacketType::RunHeader,       &RunHeader));      CMap.Insert(PacketType::CalibTrailer->GetName(),    &CalibTrailer);  
159      CMap.insert(CounterMap::value_type(PacketType::RunTrailer,      &RunTrailer));      CMap.Insert(PacketType::CalibCalPulse1->GetName(),  &CalibCalPulse1);
160      CMap.insert(CounterMap::value_type(PacketType::CalibHeader,     &CalibHeader));      CMap.Insert(PacketType::CalibCalPulse2->GetName(),  &CalibCalPulse2);
161      CMap.insert(CounterMap::value_type(PacketType::CalibTrailer,    &CalibTrailer));        CMap.Insert(PacketType::CalibTrkBoth->GetName(),    &CalibTrkBoth);
162      CMap.insert(CounterMap::value_type(PacketType::InitHeader,      &InitHeader));      CMap.Insert(PacketType::CalibTrk1->GetName(),       &CalibTrk1);
163      CMap.insert(CounterMap::value_type(PacketType::InitTrailer,     &InitTrailer));        CMap.Insert(PacketType::CalibTrk2->GetName(),       &CalibTrk2);
164      CMap.insert(CounterMap::value_type(PacketType::EventTrk,        &EventTrk));        CMap.Insert(PacketType::CalibS4->GetName(),         &CalibS4);
165      CMap.insert(CounterMap::value_type(PacketType::Log,             &Log));      CMap.Insert(PacketType::CalibCalPed->GetName(),     &CalibCalPed);
166      CMap.insert(CounterMap::value_type(PacketType::VarDump,         &VarDump));      CMap.Insert(PacketType::Calib1_Ac1->GetName(),      &Calib1_Ac1);
167      CMap.insert(CounterMap::value_type(PacketType::ArrDump,         &ArrDump));      CMap.Insert(PacketType::Calib2_Ac1->GetName(),      &Calib2_Ac1);
168      CMap.insert(CounterMap::value_type(PacketType::TabDump,         &TabDump));      CMap.Insert(PacketType::Calib1_Ac2->GetName(),      &Calib1_Ac2);
169      CMap.insert(CounterMap::value_type(PacketType::Tmtc,            &Tmtc));      CMap.Insert(PacketType::Calib2_Ac2->GetName(),      &Calib2_Ac2);
170      CMap.insert(CounterMap::value_type(PacketType::Mcmd,            &Mcmd));      CMap.Insert(PacketType::CalibCal->GetName(),        &CalibCal);
171      CMap.insert(CounterMap::value_type(PacketType::ForcedFECmd,     &ForcedFECmd));      CMap.Insert(PacketType::EventTrk->GetName(),        &EventTrk);  
172      CMap.insert(CounterMap::value_type(PacketType::Ac1Init,         &Ac1Init));      CMap.Insert(PacketType::Ac1Init->GetName(),         &Ac1Init);
173      CMap.insert(CounterMap::value_type(PacketType::CalInit,         &CalInit));      CMap.Insert(PacketType::CalInit->GetName(),         &CalInit);
174      CMap.insert(CounterMap::value_type(PacketType::TrkInit,         &TrkInit));      CMap.Insert(PacketType::TrkInit->GetName(),         &TrkInit);
175      CMap.insert(CounterMap::value_type(PacketType::TofInit,         &TofInit));      CMap.Insert(PacketType::TofInit->GetName(),         &TofInit);
176      CMap.insert(CounterMap::value_type(PacketType::TrgInit,         &TrgInit));      CMap.Insert(PacketType::TrgInit->GetName(),         &TrgInit);
177      CMap.insert(CounterMap::value_type(PacketType::NdInit,          &NdInit));      CMap.Insert(PacketType::NdInit->GetName(),          &NdInit);
178      CMap.insert(CounterMap::value_type(PacketType::S4Init,          &S4Init));      CMap.Insert(PacketType::S4Init->GetName(),          &S4Init);
179      CMap.insert(CounterMap::value_type(PacketType::Ac2Init,         &Ac2Init));      CMap.Insert(PacketType::Ac2Init->GetName(),         &Ac2Init);
180      CMap.insert(CounterMap::value_type(PacketType::CalAlarm,        &CalAlarm));      CMap.Insert(PacketType::CalAlarm->GetName(),        &CalAlarm);
181      CMap.insert(CounterMap::value_type(PacketType::Ac1Alarm,        &Ac1Alarm));      CMap.Insert(PacketType::Ac1Alarm->GetName(),        &Ac1Alarm);
182      CMap.insert(CounterMap::value_type(PacketType::TrkAlarm,        &TrkAlarm));      CMap.Insert(PacketType::TrkAlarm->GetName(),        &TrkAlarm);
183      CMap.insert(CounterMap::value_type(PacketType::TrgAlarm,        &TrgAlarm));      CMap.Insert(PacketType::TrgAlarm->GetName(),        &TrgAlarm);
184      CMap.insert(CounterMap::value_type(PacketType::TofAlarm,        &TofAlarm));      CMap.Insert(PacketType::TofAlarm->GetName(),        &TofAlarm);
185      CMap.insert(CounterMap::value_type(PacketType::S4Alarm,         &S4Alarm));      CMap.Insert(PacketType::S4Alarm->GetName(),         &S4Alarm);
186      CMap.insert(CounterMap::value_type(PacketType::Ac2Alarm,        &Ac2Alarm));      CMap.Insert(PacketType::Ac2Alarm->GetName(),        &Ac2Alarm);
187      CMap.insert(CounterMap::value_type(PacketType::TsbT,            &TsbT));      CMap.Insert(PacketType::ForcedFECmd->GetName(),     &ForcedFECmd);
188      CMap.insert(CounterMap::value_type(PacketType::TsbB,            &TsbB));      CMap.Insert(PacketType::CalibTof->GetName(),        &CalibTof);
189      
190  }  }
191    
192  /**  /**
# Line 126  EventCounter::EventCounter(int run): Line 194  EventCounter::EventCounter(int run):
194   * @param type Event type to be incremented.   * @param type Event type to be incremented.
195   */   */
196  void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){  void EventCounter::Increment(PacketType const * type) throw (NotExistingCounterException){
197          CounterMap::iterator p = CMap.find(type);    //  cout << " increment "<< endl;
198    if (p != CMap.end()) {    mapval *p = CMap.Find(type->GetName());
199      if ( !CMap.end()) {    
200            int *counter = p->second;      //    cout << " A Counter." <<  type->GetName() << " = " <<  (*(&p->count)) << endl;
201      (*counter)++;      (*(p->count))++;
202        //(*(&p->count))++;
203        //    cout << " B Counter." <<  type->GetName() << " = " <<  (*(&p->count)) << endl;
204      } else {    
205      oss.str("");      oss.str("");
206      oss << " Counter." <<  type->GetName() << " = " <<  (*counter);      oss << "\n No counter of type  " << type->GetName();
    //marco  
     //std::cout<<oss.str()<<std::endl; //marco  
     //// logger->info(oss.str().c_str());  
   } else {  
   
     oss.str("");  
     oss << "\n No counter of type  " << type->GetName().c_str();  
     //std::cout<<oss.str()<<std::endl; //marco  
   
207      throw NotExistingCounterException(oss.str().c_str());      throw NotExistingCounterException(oss.str().c_str());
208    }    }
209  }  }
# Line 154  void EventCounter::Increment(PacketType Line 216  void EventCounter::Increment(PacketType
216   * number of the last read event of that type.   * number of the last read event of that type.
217   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
218   */   */
219  int EventCounter::Get(PacketType const * type) const throw (NotExistingCounterException){  int EventCounter::Get(PacketType const * type) throw (NotExistingCounterException){
220    const CounterMap::const_iterator p = CMap.find(type);    //  cout << " get "<< endl;
221    if (p != CMap.end()) {    mapval *p = CMap.Find(type->GetName());
222      const int *counter = p->second;    if ( !CMap.end()) {
223      return *counter;      //    cout << " C Counter." <<  type->GetName() << " = " <<  (*(p->count)) << endl;
224        return ((*(p->count)));
225        //    return ((*(&p->count)));
226    } else {    } else {
227      throw NotExistingCounterException(type->GetName().c_str());      throw NotExistingCounterException(type->GetName());
228      return -1;      return -1;
229    }    }
230  }  }
# Line 171  int EventCounter::Get(PacketType const * Line 235  int EventCounter::Get(PacketType const *
235   * @return The next counter of that packet type.   * @return The next counter of that packet type.
236   * @retval -1 if there was no event of this type.   * @retval -1 if there was no event of this type.
237   */   */
238  int EventCounter::Next(PacketType const * type) const throw (NotExistingCounterException){  int EventCounter::Next(PacketType const * type) throw (NotExistingCounterException){
239    const CounterMap::const_iterator p = CMap.find(type);    //  cout << " next "<< endl;
240    if (p != CMap.end()) {    mapval *p = CMap.Find(type->GetName());
241      const int *counter = p->second;    if ( !CMap.end()) {
242      return *counter + 1;      //    cout << " NEXT Counter." <<  type->GetName() << " = " <<  (*(p->count))+1 << endl;
243        return ((*(p->count)) + 1);
244        //    return ((*(&p->count)) + 1);
245        //    return ((&(p->count)) + 1);
246    } else {    } else {
247      throw NotExistingCounterException(type->GetName().c_str());      throw NotExistingCounterException(type->GetName());
248      return -1;      return -1;
249    }    }
250  }  }
# Line 186  int EventCounter::Next(PacketType const Line 253  int EventCounter::Next(PacketType const
253   * Get the all the counters   * Get the all the counters
254    * @retval 0 if there was no event of this type.    * @retval 0 if there was no event of this type.
255   */   */
256  void EventCounter::PrintCounters() const {  void EventCounter::PrintCounters(){
257          std::cout<<"PrintCounters:"<<std::endl;    std::cout<<"PrintCounters:"<<std::endl;
258      //
259          for(CounterMap::const_iterator p = CMap.begin(); p != CMap.end(); p++) {    for (Int_t i=0; i < CMap.GetEntries(); i++){
260    oss.str("");      mapval *p = CMap.Get(i);
261    oss <<  " Counter." <<  (p->first)->GetName()  <<   " \t \t " <<  (*p->second);      oss.str("");
262    std::cout<<oss.str()<<std::endl;      oss <<  " Counter." <<  (p->name).Data()  <<   " \t \t " <<  (*(p->count));
263    //marco      //    oss <<  " Counter." <<  (p->name).Data()  <<   " \t \t " <<  (*(&p->count));
264    //logger->info(oss.str().c_str());      //    oss <<  " Counter." <<  (p->name).Data()  <<   " \t \t " <<  (&(p->count));
265    }      std::cout<<oss.str()<<std::endl;
266      };
267  }  }
268            
269    ClassImp(mapval)
270    ClassImp(mappa)
271    ClassImp(EventCounter)  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.5

  ViewVC Help
Powered by ViewVC 1.1.23