KaliVeda  1.13/01
Heavy-Ion Analysis Toolkit
KVRunListLine.h
Go to the documentation of this file.
1 
3 #ifndef __KVRUNLISTLINE_H
4 #define __KVRUNLISTLINE_H
5 
6 #include "TObjString.h"
7 #include "TObjArray.h"
8 #include "Riostream.h"
9 #include "KVNameValueList.h"
10 #include "KVString.h"
11 #include "KVList.h"
12 
26 
27 private:
34 
35  inline Int_t GetFieldIndex(const Char_t*) const;
36 
39  void SetFieldKeys()
40  {
41  calling_field_keys = false; // just to terminate recursion of parameter pack
42  }
43  void SetRunKeys()
44  {
45  calling_run_keys = false; // just to terminate recursion of parameter pack
46  }
47 
48 protected:
50 
51 public:
52  KVRunListLine();
53  virtual ~ KVRunListLine();
54 
55  virtual const Char_t* GetField(const Char_t*) const;
56  TObjString* GetFieldString(const Char_t*) const;
57  Int_t GetIntField(const Char_t*);
59 
60  virtual void SetFields();
61  Bool_t FieldsSet() const
62  {
63  return fFieldsSet;
64  };
65 
66  inline void SetLine(const Char_t*);
67  inline void SetLine(TString&);
68  inline void Clear();
69  Int_t BreakLineIntoFields(const char);
70  inline Bool_t HasFieldValue(const Char_t*) const;
71  inline Bool_t HasField(const Char_t*) const;
72  Bool_t FieldContains(const Char_t*, const Char_t*) const;
73  Bool_t IsFloat(const Char_t* name);
74 
75  virtual void Print() const;
76  inline void PrintFieldValue(const Char_t* name) const;
77  virtual Int_t GetTrigger(const Char_t* field_name =
78  "Trigger", const Char_t* fmt = "M>=%d");
79 
80  template<typename T, typename... Args>
81  void SetFieldKeys(T key0, Args... keys)
82  {
88 
89  if (!calling_field_keys) {
91  fFieldKeys.Clear();
92  calling_field_keys = true; // to avoid clearing in every recursion
93  }
94  fFieldKeys.Add(new TObjString(key0));
95  SetFieldKeys(keys...);
96  }
97  template<typename T, typename... Args>
98  void SetRunKeys(T key0, Args... keys)
99  {
102 
103  if (!calling_run_keys) {
105  fRunKeys.Clear();
106  calling_run_keys = true; // to avoid clearing in every recursion
107  }
108 
109  fRunKeys.Add(new TObjString(key0));
110  SetRunKeys(keys...);
111  }
112 
113  virtual Bool_t IsFieldHeader();
114  virtual Bool_t GoodRunLine();
115 
116  ClassDef(KVRunListLine, 0) //Base class for reading runlist files
117 };
118 
120 
121 inline Bool_t KVRunListLine::HasField(const Char_t* fname) const
122 {
125 
126  return (FieldsSet() ? fIndexList.HasParameter(fname) : kFALSE);
127 }
128 
130 
131 inline Bool_t KVRunListLine::HasFieldValue(const Char_t* fname) const
132 {
136  Int_t index = GetFieldIndex(fname);
137  if (!(index > -1 && index < fFields->GetEntries()))
138  return kFALSE;
139  KVString tmp(((TObjString*)(*fFields)[index])->String());
140  return !tmp.IsWhitespace();
141 }
142 
144 
145 inline Int_t KVRunListLine::GetFieldIndex(const Char_t* fname) const
146 {
152 
153  return fIndexList.GetIntValue(fname);
154 }
155 
157 
158 inline void KVRunListLine::SetLine(const Char_t* line)
159 {
161  fLine = line;
162 }
163 
165 
166 inline void KVRunListLine::SetLine(TString& line)
167 {
169  fLine = line;
170 }
171 
173 
174 inline void KVRunListLine::Clear()
175 {
176 
178  fFields->Clear();
179 }
180 
182 
183 inline void KVRunListLine::PrintFieldValue(const Char_t* name) const
184 {
190 
191  std::cout << name << " : ";
192  if (HasFieldValue(name))
193  std::cout << GetField(name) << std::endl;
194  else
195  std::cout << "[absent]" << std::endl;
196 }
197 
198 #endif
int Int_t
char Char_t
const Bool_t kFALSE
bool Bool_t
float Float_t
#define ClassDef(name, id)
Extended TList class which owns its objects by default.
Definition: KVList.h:27
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
Int_t GetIntValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
Base class for reading runlists for experiments ,.
Definition: KVRunListLine.h:25
Int_t BreakLineIntoFields(const char)
TString fLine
line to analyse
Definition: KVRunListLine.h:29
Bool_t FieldContains(const Char_t *, const Char_t *) const
Returns true if "field" exists, has been filled, and contains "string" as part or all of its value.
virtual void SetFields()
Bool_t HasFieldValue(const Char_t *) const
TObjArray * fFields
array of all fields after break down of fLine
Definition: KVRunListLine.h:31
KVList fFieldKeys
key words used to recognise field headings
Definition: KVRunListLine.h:32
bool calling_field_keys
Definition: KVRunListLine.h:37
Float_t GetFloatField(const Char_t *)
Int_t GetFieldIndex(const Char_t *) const
bool calling_run_keys
Definition: KVRunListLine.h:38
virtual Bool_t IsFieldHeader()
Returns kTRUE if and only if current line contains ALL of the keywords defined by SetFieldKeys()
virtual void Print() const
void SetRunKeys(T key0, Args... keys)
Definition: KVRunListLine.h:98
Bool_t IsFloat(const Char_t *name)
virtual Bool_t GoodRunLine()
Returns kTRUE if and only if current line contains integer values for ALL the fields defined by SetRu...
void SetRunKeys()
Definition: KVRunListLine.h:43
TObjString * GetFieldString(const Char_t *) const
Bool_t fFieldsSet
flag set once fields have been set
Definition: KVRunListLine.h:30
void SetFieldKeys(T key0, Args... keys)
Definition: KVRunListLine.h:81
Bool_t FieldsSet() const
Definition: KVRunListLine.h:61
void SetFieldKeys()
Definition: KVRunListLine.h:39
Bool_t HasField(const Char_t *) const
INLINES_______________________________________________________________________________.
virtual Int_t GetTrigger(const Char_t *field_name="Trigger", const Char_t *fmt="M>=%d")
KVList fRunKeys
fields that must be present (have a value) for a line to be considered a "good run line"
Definition: KVRunListLine.h:33
void PrintFieldValue(const Char_t *name) const
Int_t fMaxNFields
maximum allowed number of fields i.e. size of TObjArray fFields
Definition: KVRunListLine.h:28
void SetLine(const Char_t *)
virtual ~ KVRunListLine()
Int_t GetIntField(const Char_t *)
virtual const Char_t * GetField(const Char_t *) const
KVNameValueList fIndexList
list of integer indexes corresponding to field names
Definition: KVRunListLine.h:49
virtual void Clear(Option_t *option="")
virtual void Add(TObject *obj)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
virtual void Clear(Option_t *option="")
Bool_t IsWhitespace() const
TLine * line
double T(double x)
const char * String