]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliTriggerScalersRecord.cxx
Fix for Coverity 14218
[u/mrichter/AliRoot.git] / STEER / AliTriggerScalersRecord.cxx
CommitLineData
d7dd8a54 1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id: AliTriggerScalersRecord.cxx 22322 2007-11-22 11:43:14Z cvetan $ */
17
18///////////////////////////////////////////////////////////////////////////////
19//
20// Class to define the ALICE Trigger Scalers Record
21//
22// Each record consists of 1 time stamp (4 words) (AliTimeStamp)
23// and an array with the scalers (AliTriggerScalers) for each trigger class
24// in partition
25//
26//////////////////////////////////////////////////////////////////////////////
27
28#include <Riostream.h>
6833469d 29#include <TObjArray.h>
d7dd8a54 30#include "AliLog.h"
31#include "AliTimeStamp.h"
32#include "AliTriggerScalers.h"
33#include "AliTriggerScalersRecord.h"
34
35ClassImp( AliTriggerScalersRecord )
36//_____________________________________________________________________________
37AliTriggerScalersRecord::AliTriggerScalersRecord():
38 fTimestamp(),
6833469d 39 fScalers()
d7dd8a54 40{
085f344f 41 //Default constructor
d7dd8a54 42}
43
44//_____________________________________________________________________________
45void AliTriggerScalersRecord::SetTimeStamp( UInt_t orbit, UInt_t period,
46 UInt_t seconds, UInt_t microsecs )
47{
48 fTimestamp.SetTimeStamp( orbit, period, seconds, microsecs );
49}
50
51//_____________________________________________________________________________
52void AliTriggerScalersRecord::AddTriggerScalers( AliTriggerScalers* scaler )
53{
54 fScalers.AddLast( scaler );
55 fScalers.Sort();
56}
57
58//_____________________________________________________________________________
59void AliTriggerScalersRecord::AddTriggerScalers( UChar_t classIndex, UInt_t LOCB, UInt_t LOCA,
60 UInt_t L1CB, UInt_t L1CA, UInt_t L2CB, UInt_t L2CA )
61{
62 AddTriggerScalers( new AliTriggerScalers( classIndex, LOCB, LOCA, L1CB, L1CA, L2CB, L2CA ) );
085f344f 63 fScalers.Sort();
d7dd8a54 64}
65
66//_____________________________________________________________________________
67Int_t AliTriggerScalersRecord::Compare( const TObject* obj ) const
68{
69 // Compare timestamps
70
71 return fTimestamp.Compare( &(((AliTriggerScalersRecord*)obj)->fTimestamp) );
72}
085f344f 73//_____________________________________________________________________________
74const AliTriggerScalers* AliTriggerScalersRecord::GetTriggerScalersForClass( const Int_t classindex ) const
75{
76 // Find Trigger scaler with class ID = classindex using a brutal force
77
78 Int_t position, last;
79 AliTriggerScalers *op2 = 0;
80 position = 0;
81 last = fScalers.GetEntriesFast();
82 while (position < last) {
83 op2 = (AliTriggerScalers *)fScalers.At(position);
84 if( op2 && (op2->GetClassIndex() == classindex )) break;
85 op2=0;
86 position++;
87 }
88 return op2;
89}
d7dd8a54 90
91//_____________________________________________________________________________
085f344f 92AliTriggerScalers* AliTriggerScalersRecord::GetTriggerScalersForClassBinary( const Int_t classindex )
d7dd8a54 93{
085f344f 94 // Find Trigger scaler with class ID = classindex using a binary search.
d7dd8a54 95
96 Int_t base, position, last, result = 0;
97 AliTriggerScalers *op2 = NULL;
98
085f344f 99 fScalers.Sort();
d7dd8a54 100
101 base = 0;
102 last = fScalers.GetEntriesFast();
103
104 while (last >= base) {
105 result = 0;
106 position = (base+last) / 2;
107 op2 = (AliTriggerScalers *)fScalers.At(position);
085f344f 108 if( op2 && op2->GetClassIndex() > classindex ) result = -1;
109 if( op2 && op2->GetClassIndex() < classindex ) result = 1;
d7dd8a54 110
111 if (op2 && result == 0)
112 return op2;
113 if (!op2 || result < 0)
114 last = position-1;
115 else
116 base = position+1;
117 op2 = NULL;
118 }
119 return op2;
120}
121
122//_____________________________________________________________________________
123void AliTriggerScalersRecord::Print( const Option_t* ) const
124{
125 // Print
126 cout << "Trigger Scalers Record: " << endl;
127 fTimestamp.Print();
128 for( Int_t i=0; i<fScalers.GetEntriesFast(); ++i )
129 ((AliTriggerScalers*)fScalers.At(i))->Print();
130}