KaliVeda
Toolkit for HIC analysis
KVRunListLine.h
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 
27 
28 private:
35 
36  inline Int_t GetFieldIndex(const Char_t*) const;
37 
40  void SetFieldKeys()
41  {
42  calling_field_keys = false; // just to terminate recursion of parameter pack
43  }
44  void SetRunKeys()
45  {
46  calling_run_keys = false; // just to terminate recursion of parameter pack
47  }
48 
49 protected:
51 
52 public:
53  KVRunListLine();
54  virtual ~ KVRunListLine();
55 
56  virtual const Char_t* GetField(const Char_t*) const;
57  TObjString* GetFieldString(const Char_t*) const;
58  Int_t GetIntField(const Char_t*);
60 
61  virtual void SetFields();
62  Bool_t FieldsSet() const
63  {
64  return fFieldsSet;
65  };
66 
67  inline void SetLine(const Char_t*);
68  inline void SetLine(TString&);
69  inline void Clear();
70  Int_t BreakLineIntoFields(const char);
71  inline Bool_t HasFieldValue(const Char_t*) const;
72  inline Bool_t HasField(const Char_t*) const;
73  Bool_t FieldContains(const Char_t*, const Char_t*) const;
74  Bool_t IsFloat(const Char_t* name);
75 
76  virtual void Print() const;
77  inline void PrintFieldValue(const Char_t* name) const;
78  virtual Int_t GetTrigger(const Char_t* field_name =
79  "Trigger", const Char_t* fmt = "M>=%d");
80 
81  template<typename T, typename... Args>
82  void SetFieldKeys(T key0, Args... keys)
83  {
89 
90  if (!calling_field_keys) {
92  fFieldKeys.Clear();
93  calling_field_keys = true; // to avoid clearing in every recursion
94  }
95  fFieldKeys.Add(new TObjString(key0));
96  SetFieldKeys(keys...);
97  }
98  template<typename T, typename... Args>
99  void SetRunKeys(T key0, Args... keys)
100  {
103 
104  if (!calling_run_keys) {
106  fRunKeys.Clear();
107  calling_run_keys = true; // to avoid clearing in every recursion
108  }
109 
110  fRunKeys.Add(new TObjString(key0));
111  SetRunKeys(keys...);
112  }
113 
114  virtual Bool_t IsFieldHeader();
115  virtual Bool_t GoodRunLine();
116 
117  ClassDef(KVRunListLine, 0) //Base class for reading runlist files
118 };
119 
121 
122 inline Bool_t KVRunListLine::HasField(const Char_t* fname) const
123 {
126 
127  return (FieldsSet() ? fIndexList.HasParameter(fname) : kFALSE);
128 }
129 
131 
132 inline Bool_t KVRunListLine::HasFieldValue(const Char_t* fname) const
133 {
137  Int_t index = GetFieldIndex(fname);
138  if (!(index > -1 && index < fFields->GetEntries()))
139  return kFALSE;
140  KVString tmp(((TObjString*)(*fFields)[index])->String());
141  return !tmp.IsWhitespace();
142 }
143 
145 
146 inline Int_t KVRunListLine::GetFieldIndex(const Char_t* fname) const
147 {
153 
154  return fIndexList.GetIntValue(fname);
155 }
156 
158 
159 inline void KVRunListLine::SetLine(const Char_t* line)
160 {
162  fLine = line;
163 }
164 
166 
167 inline void KVRunListLine::SetLine(TString& line)
168 {
170  fLine = line;
171 }
172 
174 
175 inline void KVRunListLine::Clear()
176 {
177 
179  fFields->Clear();
180 }
181 
183 
184 inline void KVRunListLine::PrintFieldValue(const Char_t* name) const
185 {
191 
192  std::cout << name << " : ";
193  if (HasFieldValue(name))
194  std::cout << GetField(name) << std::endl;
195  else
196  std::cout << "[absent]" << std::endl;
197 }
198 
199 #endif
int Int_t
bool Bool_t
char Char_t
float Float_t
constexpr Bool_t kFALSE
#define ClassDef(name, id)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
char name[80]
Extended TList class which owns its objects by default.
Definition: KVList.h:28
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:26
Int_t BreakLineIntoFields(const char)
TString fLine
line to analyse
Definition: KVRunListLine.h:30
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:32
KVList fFieldKeys
key words used to recognise field headings
Definition: KVRunListLine.h:33
bool calling_field_keys
Definition: KVRunListLine.h:38
Float_t GetFloatField(const Char_t *)
Int_t GetFieldIndex(const Char_t *) const
bool calling_run_keys
Definition: KVRunListLine.h:39
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:99
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:44
TObjString * GetFieldString(const Char_t *) const
Bool_t fFieldsSet
flag set once fields have been set
Definition: KVRunListLine.h:31
void SetFieldKeys(T key0, Args... keys)
Definition: KVRunListLine.h:82
Bool_t FieldsSet() const
Definition: KVRunListLine.h:62
void SetFieldKeys()
Definition: KVRunListLine.h:40
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:34
void PrintFieldValue(const Char_t *name) const
Int_t fMaxNFields
maximum allowed number of fields i.e. size of TObjArray fFields
Definition: KVRunListLine.h:29
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:50
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:73
void Clear(Option_t *option="") override
Bool_t IsWhitespace() const
TLine * line
double T(double x)
const char * String