KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVINDRARunListReader.cpp
1/*
2$Id: KVINDRARunListReader.cpp,v 1.8 2007/04/26 16:38:57 franklan Exp $
3*/
4
5#include <KVINDRARunListReader.h>
6#include <TClass.h>
7#include <TError.h>
8#include <KVRunListLine.h>
9
10
11using namespace std;
12
14
15
16
19
21{
22 //Default ctor.
23 //We set default values for recognising comment lines ('#') and the separator character ('|')
24
25 fLineReader = new KVRunListLine;
26 fComment = '#';
27 fSeparator = '|';
28 fTrigger = -1;
29 fNewRunList = kFALSE;
30 fVersion = 0;
31}
32
33
34
38
40{
41 //Dtor.
42 //Delete KVRunListLine object if one exists; close runlist file if open
44 if (fLineReader) {
45 delete fLineReader;
46 fLineReader = 0;
47 }
48}
49
50
51
56
58{
59 //Open file 'filename' for reading.
60 //Returns kTRUE if file can be opened (info message), kFALSE if not (error message)
61 //Reset fTrigger to -1 (in case we already read a different file)
62
64 if (fRunsStream.is_open()) {
66 Info(Form("%s::OpenRLFile", IsA()->GetName()),
67 "Opened file %s for reading", filename);
68 fTrigger = -1;
69 return kTRUE;
70 }
71 Error(Form("%s::OpenRLFile", IsA()->GetName()),
72 "Cannot open file %s for reading", filename);
73 //reset ifstream ready to try opening another file
74 fRunsStream.close();
75 fRunsStream.clear();
76 return kFALSE;
77}
78
79
80
84
86{
87 //Close current runlist file. Another file can be opened after this.
88 //If no file is open, do nothing.
89 if (fRunsStream.is_open()) {
90 fRunsStream.close();
91 fRunsStream.clear();
92 fRunsFile = "";
93 }
94}
95
96
97
104
106{
107 //Read a line from current runlist file. If not a comment line (i.e. does not begin with 'fComment' character)
108 //then analyse it with fLineReader object.
109 //Returns kFALSE if no file is open or if file is not good for i/o
110 //Returns kFALSE if fLineReader has not been initialised
111 //Returns kFALSE if line cannot be read / end of file is reached
112 if (!fRunsStream.is_open()) {
113 Error(Form("%s::ReadRLLine", IsA()->GetName()),
114 "No file open for reading");
115 return kFALSE;
116 }
117 if (!fRunsStream.good()) {
118 Error(Form("%s::ReadRLLine", IsA()->GetName()),
119 "File %s is not good for reading", fRunsFile.Data());
120 return kFALSE;
121 }
123
124 if (!fRunsStream.good())
125 return kFALSE;
126
127 if (fLine.BeginsWith("Version")) {
128 //read version number in file
129 if (sscanf(fLine.Data(), "Version=%d", &fVersion) == 1) {
130 //set flag to force reading runlist with new method
132 return kFALSE;
133 }
134 }
135 else if (!fLine.BeginsWith(fComment)) {
138 }
139 else {
140 //comment line - reset line reader
142 }
143 return kTRUE;
144}
145
146
147
155
157{
158 //This method will open the runlist file 't' and read its entire contents, calling user-overridable method "GoodRunLine(KVRunListLine*)"
159 //every time a line defining a new run is read from the file.
160 //If 't' is not given, we assume that the name of the run list file was passed to the constructor, and so the file should
161 //already be open in this case.
162 //Before calling this method, you should call SetRunListLineType() to define the class used to read each line, and
163 //SetRLCommentChar()/SetRLSeparatorChar() if you want to override the default comment/separator characters.
164
165 if (!strcmp(t, "")) {
166 //no filename given - file should have been opened by OpenRLFile - check !
167 if (!fRunsStream.is_open()) {
168 Error(Form("%s::ReadRunList", IsA()->GetName()),
169 "No runlist file open for reading");
170 return;
171 }
172 }
173 else {
174 //open new file - check OK
175 //close any previously opened file
176 CloseRLFile();
177 if (!OpenRLFile(t))
178 return; //error message will be given by OpenRLFile
179 }
180 //reset last trigger read
181 fTrigger = -1;
182 fCurrentLine = 1;
183 while (ReadRLLine()) { // read lines in file while we can
184
185 if (fLineReader->GoodRunLine()) {
186 //call user's function
187 GoodRunLine();
188 }
189 //reset line reader
191 fCurrentLine++;
192 }
193
194 //close run file
195 CloseRLFile();
196}
197
198
199
204
206{
207 //This method should be overridden in derived class by the user.
208 //It is called every time that the fLineReader finds a line which is a "good run line" (see KVRunListLine::GoodRunLine()).
209 //The default behaviour is just to print the breakdown of the line in question on the screen.
210
212}
213
214
215
223
225 const Char_t* fmt)
226{
227 //Get trigger multiplicity for current line.
228 //Give field name which contains trigger information and format string 'fmt' containing e.g. "M>=%d"
229 //if trigger field info is written in form "M>=4" etc. etc.
230 //The last value read is kept (fTrigger), so that, if no trigger value is given for the current line,
231 //but one was given on a previous line, we assume that the previous value is valid until a new one is given.
232 //A value "-1" means no trigger has been set for any line in the file so far.
233
234 Int_t trig = fLineReader->GetTrigger(field, fmt);
235 if (trig < 0 && fLineReader->HasFieldValue(field))
236 cout << "...apparently on line " << GetRLLineNumber() << endl;
237 return (trig < 0 ? fTrigger : fTrigger = trig);
238}
239
240
int Int_t
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
constexpr Bool_t kTRUE
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
TClass * IsA() const override
char * Form(const char *fmt,...)
Utitlity base class for reading INDRA runlist files.
std::ifstream fRunsStream
input file stream
Bool_t fNewRunList
flag set when reading new ("Version=10") runlist
Int_t fCurrentLine
number of line in runlist file we are currently analysing
Bool_t OpenRLFile(const Char_t *)
TString fRunsFile
name of file to read
void ReadRunList(const Char_t *name="")
Char_t fComment
character placed at beginning of comment lines
Int_t GetRunListTrigger(const Char_t *field, const Char_t *fmt)
Int_t fTrigger
last multiplicity trigger read from file
KVRunListLine * fLineReader
object used to analyse lines in file
Char_t fSeparator
character used to separate fields on each line of file
Int_t fVersion
version number of new runlist
TString fLine
last line read from file
Base class for reading runlists for experiments ,.
Int_t BreakLineIntoFields(const char)
virtual void Print() const
virtual Bool_t GoodRunLine()
Returns kTRUE if and only if current line contains integer values for ALL the fields defined by SetRu...
virtual Int_t GetTrigger(const Char_t *field_name="Trigger", const Char_t *fmt="M>=%d")
void SetLine(const Char_t *)
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
std::istream & ReadLine(std::istream &str, Bool_t skipWhite=kTRUE)
void Error(const char *location, const char *fmt,...)
void Info(const char *location, const char *fmt,...)
ClassImp(TPyArg)