GSI Object Oriented Online Offline (Go4)  GO4-6.3.0
TGo4ListCond.cxx
Go to the documentation of this file.
1 // $Id$
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4ListCond.h"
15 
16 #include <algorithm>
17 
20 {
21  SetDimension(1);
22 }
23 
24 TGo4ListCond::TGo4ListCond(const char *name, const char *title) :
25  TGo4Condition(name, title)
26 {
27  fxValues.clear();
28  SetDimension(1);
29 }
30 
31 TGo4ListCond::TGo4ListCond(const char *name, const char *title, const Int_t num, const Int_t * input) :
32  TGo4Condition(name, title)//, fiNum(num)
33 {
34  SetDimension(1);
35  SetValues(num,input);
36 }
37 
38 TGo4ListCond::TGo4ListCond(const char *name, const char *title, const Int_t start, const Int_t stop, const Int_t step) :
39  TGo4Condition(name, title)
40 {
41  SetDimension(1);
42  SetValues(start,stop,step);
43 
44 }
45 
46 void TGo4ListCond::SetValues(const Int_t num, const Int_t *values)
47 {
48  fxValues.clear();
49  for (int i = 0; i < num; ++i) {
50  fxValues.push_back(values[i]);
51  }
52 }
53 void TGo4ListCond::SetValues(const Int_t start, const Int_t stop, const Int_t step)
54 {
55  fxValues.clear();
56  Int_t num = (stop - start) / step;
57  if (num <= 0) {
58  num = 0;
59  }
60  num += 1;
61 
62  for (int i = 0; i < num; ++i) {
63  fxValues.push_back(start + i * step);
64  }
65 }
66 
68 
69 Bool_t TGo4ListCond::Test(Double_t dvalue)
70 {
71  Int_t value = dvalue; // need this to avoid framework ambiguity
72  IncCounts();
73  if (!IsEnabled()) {
74  if (FixedResult())
75  IncTrueCounts();
76  return FixedResult();
77  }
78 
79  for (size_t i = 0; i < fxValues.size(); ++i) {
80  if (value == fxValues[i]) {
81  // std::cout << i << " " << fxValues[i] << " " << value << std::endl;
82  IncTrueCounts();
83  return kTRUE;
84  }
85  }
86 
87  return kFALSE;
88 }
89 
91 {
93  PrintValues();
94 }
95 
97 {
98  size_t num = fxValues.size();
99  std::cout << "fxValues[" << num << "]: {";
100  if (num > 0) {
101  std::cout << fxValues[0];
102  for (size_t i = 1; i < num; ++i) {
103  std::cout << ", " << fxValues[i];
104  }
105  }
106  std::cout << "}" << std::endl;
107 }
108 
109 Bool_t TGo4ListCond::UpdateFrom(TGo4Condition *cond, Bool_t counts)
110 {
111  TGo4ListCond *from = dynamic_cast<TGo4ListCond *>(cond);
112  if (!from)
113  return kFALSE;
114  fxValues.clear();
115  for (size_t i = 0; i < from->GetNumValues(); ++i)
116  fxValues.push_back(from->GetValue(i));
117  return TGo4Condition::UpdateFrom(cond, counts);
118 }
119 
120 Double_t TGo4ListCond::GetXUp() const
121 {
122  return *std::max_element(fxValues.begin(), fxValues.end());
123 }
124 
125 Double_t TGo4ListCond::GetXLow() const
126 {
127  return *std::min_element(fxValues.begin(), fxValues.end());
128 }
129 
130 Double_t TGo4ListCond::GetYUp() const
131 {
132  return 0;
133 }
134 
135 Double_t TGo4ListCond::GetYLow() const
136 {
137  return 0;
138 }
virtual Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts)
Double_t GetYLow() const override
virtual ~TGo4ListCond()
virtual void PrintCondition(Bool_t full=kTRUE)
virtual void SetValues()
Definition: TGo4Condition.h:93
Double_t GetXLow() const override
Int_t GetValue(UInt_t ix) const
Definition: TGo4ListCond.h:48
Bool_t UpdateFrom(TGo4Condition *cond, Bool_t counts) override
Double_t GetXUp() const override
UInt_t GetNumValues() const
Definition: TGo4ListCond.h:46
virtual Bool_t Test()
std::vector< Int_t > fxValues
Definition: TGo4ListCond.h:82
Bool_t IsEnabled() const
Definition: TGo4Condition.h:82
Bool_t FixedResult() const
void PrintCondition(Bool_t full=kFALSE) override
void PrintValues()
void SetDimension(Int_t d)
Double_t GetYUp() const override