]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSt1IniReader.cxx
fixed bug with trigger digits in new segmentation (thanks to Christian)
[u/mrichter/AliRoot.git] / MUON / AliMUONSt1IniReader.cxx
CommitLineData
ba030c0e 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
88cb7938 16/* $Id$ */
ba030c0e 17
18// Authors: David Guez, Ivana Hrivnacova, Marion MacCormick; IPN Orsay
19//
20// Class AliMUONIniReader
21// ----------------------
22// General class to read data in ASCII file format,
23// similar to the Windows ".ini" files (a set of sections tagged by a
24// [ sectionName ]
25// and values defined in the way:
26// parameterName = value
27//
28// comment lines can be introduced if the first non-blank character
29// is either ';' or '#'
5f1df83a 30// Included in AliRoot 2003/01/28
ba030c0e 31
5f91c9e8 32#if !defined(__HP_aCC) && !defined(__alpha)
33 #include <sstream>
34#endif
ba030c0e 35
5f91c9e8 36#include <Riostream.h>
37#include <Rstrstream.h>
ba030c0e 38
5f91c9e8 39#include "AliMUONSt1IniReader.h"
ba030c0e 40
41//______________________________________________________________________
42AliMUONSt1IniReader::AliMUONSt1IniReader()
43 :fFile(),fCurrentType(kUndef),fEndOfFile(true)
44{
45// default constructor
46// ---
47}
48
49//______________________________________________________________________
50AliMUONSt1IniReader::AliMUONSt1IniReader(string fileName)
51{
52// normal constructor
53// ---
54
55 fFile.open(fileName.c_str());
56 if (!fFile) {cerr<<"Unable to open file "<<fileName<<endl;}
57 fEndOfFile = !fFile.good();
58 fCurrentType=kUndef;
59}
60
61//______________________________________________________________________
62AliMUONSt1IniReader::~AliMUONSt1IniReader()
63{
64 //destructor
65 fFile.close();
66}
67
68//______________________________________________________________________
69void AliMUONSt1IniReader::Reset()
70{
71// Reset the input stream. The file can be re-read after calling this function
72// ---
73
74 fFile.clear();
75 fFile.seekg(0,ios::beg);
76 fCurrentType=kUndef;
77 fEndOfFile=!fFile.good();
78}
79
80//______________________________________________________________________
81bool AliMUONSt1IniReader::ReadNextLine()
82{
83// The main function of this class.
84// Read next line in the file and set CurrentType(), CurrentName() and
85// CurrentValue() with the line's content
86// ---
87
88 if ( (!fFile) || (fFile.eof()) || (!fFile.good()) )
89 {fEndOfFile=true; fCurrentType=kUndef; return false;}
90
91 string line;
92 getline(fFile,line);
93 if ( line.empty()) { // this is a blank line
94 return ReadNextLine();
95 }
5f91c9e8 96#if defined (__HP_aCC) || (__alpha)
97 strstream l;
98 l << line;
99#else
ba030c0e 100 istringstream l(line);
5f91c9e8 101#endif
ba030c0e 102
103 char c;
104
105 l>>c;
106 if ( (c==';') || (c=='#') ) { // this is a comment
107 return ReadNextLine();
108 }
109
110 if (c=='[') { // this is a chapter name
111 getline(l,fCurrentName,']');
3c25381f 112 fCurrentName=Trail(fCurrentName);
ba030c0e 113 fCurrentType=kChapter;
114 return true;
115 } else {
116 if (line.find_first_of("=") != string::npos ) {
117 l.putback(c);
118 getline(l,fCurrentName,'=');
3c25381f 119 fCurrentName = Trail(fCurrentName);
ba030c0e 120
121 getline(l,fCurrentValue);
3c25381f 122 fCurrentValue = Trail(fCurrentValue);
ba030c0e 123 fCurrentType=kValue;
124 return true;
125 } else {
126 cerr<<"Warning, badly formated line..."<<line<<endl;
127 fCurrentType=kUndef;
128 return false;
129 }
130 }
5f91c9e8 131 // fCurrentType=kUndef;
132 // return false;
133 // unreachable
ba030c0e 134}
135
136//______________________________________________________________________
40c8ec24 137AliMUONSt1IniReader::ValueList AliMUONSt1IniReader::MakeCurrentValueList()
ba030c0e 138{
139// Read the next lines in the file
140// until eof() or a new section is found.
141// Return the list of (name,value) pairs read.
142// ---
143
40c8ec24 144 ValueList ans;
ba030c0e 145 while (true){
146 if (fCurrentType==kValue){
40c8ec24 147 ans.push_back( ValuePair(fCurrentName,fCurrentValue));
ba030c0e 148 } else break;
149 ReadNextLine();
150 }
151 return ans;
152}
153
154//______________________________________________________________________
40c8ec24 155AliMUONSt1IniReader::Chapter AliMUONSt1IniReader::MakeCurrentChapter()
ba030c0e 156{
157// Searches in the rest file for a new section
158// and return it's name and the list of (name,value) pairs in it
159// ---
160
161 while ((!Eof()) && (fCurrentType != kChapter)) ReadNextLine();
40c8ec24 162 if (Eof()) return Chapter();
ba030c0e 163 string name = fCurrentName;
164 ReadNextLine();
40c8ec24 165 return Chapter(name,MakeCurrentValueList());
ba030c0e 166}
167
168//______________________________________________________________________
40c8ec24 169AliMUONSt1IniReader::ChapterList AliMUONSt1IniReader::MakeChapterList()
ba030c0e 170{
171// Read the rest of the file and return all the chapter names and
172// (name,value) pair lists found after the current position
173// ---
174
40c8ec24 175 ChapterList ans;
ba030c0e 176 while (true) {
177 if (fCurrentType==kChapter) {
178 string s= fCurrentName;
179 ReadNextLine();
40c8ec24 180 //ans.insert(Chapter(s,MakeCurrentValueList()));
5f91c9e8 181 // does not compile on SunOS
40c8ec24 182 ans.insert(ChapterList::value_type(s,MakeCurrentValueList()));
ba030c0e 183 } else ReadNextLine();
184 if (fEndOfFile) break;
185 }
186 return ans;
187}
188
189//______________________________________________________________________
3c25381f 190string AliMUONSt1IniReader::Trail(const string& s) const
ba030c0e 191{
192// Utility function: clear the blanks before and after the string <s>
193// ---
194
195 string::size_type p1=s.find_first_not_of(" ");
196 if (p1==string::npos) return "";
197 string::size_type p2=s.find_last_not_of(" ");
198 return s.substr(p1,p2-p1+1);
199}