3 /************************************************************************
6 ** This file is property of and copyright by the Department of Physics
7 ** Institute for Physic and Technology, University of Bergen,
8 ** Bergen, Norway, 2006
9 ** This file has been written by Sebastian Bablok,
10 ** sebastian.bablok@ift.uib.no
12 ** Important: This file is provided without any warranty, including
13 ** fitness for any particular purpose.
16 *************************************************************************/
18 // @file AliHLTPendolinoListReader.cxx
19 // @author Sepastian Bablok
21 // @brief Helper class for pendolino list handling
22 // @note maintained by matthias.richter@cern.ch
29 #include <TObjString.h>
32 #include "AliHLTPendolinoListReader.h"
34 ClassImp(AliHLTPendolinoListReader)
37 //using namespace alice::hlt::pendolino;
39 //typedef pair<string, TMap> Key_Val_Pair;
40 //typedef TMap<TString, TMap> AliasMap;
43 int AliHLTPendolinoListReader::kMAX_LINE_LENGTH = 256;
46 AliHLTPendolinoListReader::AliHLTPendolinoListReader()
51 // see header file for class documentation
53 // refer to README to build package
55 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59 AliHLTPendolinoListReader::AliHLTPendolinoListReader(const char* filename)
64 // see header file for class documentation
65 if (ReadListFromFile(filename)) {
68 // log that filename does ot matches a file
73 AliHLTPendolinoListReader::~AliHLTPendolinoListReader()
75 // see header file for class documentation
77 fCalibObjList.Delete();
82 bool AliHLTPendolinoListReader::ReadListFromFile(const std::string filename)
84 // see header file for class documentation
85 return ReadListFromFile(filename.c_str());
89 bool AliHLTPendolinoListReader::ReadListFromFile(const char* filename)
91 // see header file for class documentation
93 unsigned int count = 0;
96 if (!filename || filename[0]==0) {
97 cout << "Filename for calibration object list is empty" << endl;
98 // ProxyLogger::getLogger()->createLogMessage(MSG_ERROR, LOG_SOURCE_PROXY,
99 // "PropertyReader received empty filename to read properties.");
103 pfile.open(filename, ios_base::in);
105 cout << "Error while opening list file or file does not exist."
107 // ProxyLogger::getLogger()->createLogMessage(MSG_ERROR, LOG_SOURCE_PROXY,
108 // "PropertyReader is unable to open property file '" +
109 // ProxyLogger::catos(filename) + "'.");
112 // ProxyLogger::getLogger()->createLogMessage(MSG_INFO, LOG_SOURCE_PROXY,
113 // "PropertyReader uses property file '" + ProxyLogger::catos(filename)
116 while ((!pfile.eof()) && (!pfile.bad())) {
117 char line[kMAX_LINE_LENGTH];
120 pfile.getline(line, kMAX_LINE_LENGTH);
123 if (strlen(line) == 0) {
126 // skip comment lines (beginning with '#') and lines with blank chars
128 if ((line[0] == '#') || (line[0] == ' ')) {
132 // cut off comments at end
133 ptrDelimiter = strstr(line, "#");
134 if (ptrDelimiter != 0) {
135 *ptrDelimiter = '\0';
137 // cut off end of line
138 ptrDelimiter = strstr(line, " ");
139 if (ptrDelimiter != 0) {
140 *ptrDelimiter = '\0';
143 // seperate alias names by detectors
144 ptrDelimiter = strstr(line, "=");
145 if (ptrDelimiter != 0) {
146 *ptrDelimiter = '\0'; // replace '=' with '\0'
147 ptrDelimiter++; // points to values (Aliasname)
148 if ((ptrDelimiter != 0) && (ptrDelimiter[0] != ' ') && (line[0] != ' ')) {
149 // cout <<"getting detector"<< endl;
150 // TString detector = new TString(line);
151 // string value(ptrDelimiter);
152 TList* pos = (TList*) fCalibObjList.GetValue(line);
155 // cout<<"inserting"<<endl;
156 TList *aliasList = new TList();
157 aliasList->Add(new TObjString(ptrDelimiter));
158 // cout<<"including"<<endl;
159 fCalibObjList.Add(new TObjString(line), (TObject*) aliasList);
160 // new TMap(new TObjString(ptrDelimiter), 0));
161 // cout << "inserted: " << line << " with " << ptrDelimiter << endl;
163 if (pos->FindObject(ptrDelimiter) == 0) {
164 // cout<<"adding"<<endl;
165 // mProperties.insert(String_Pair(name, value));
166 pos->Add(new TObjString(ptrDelimiter));
167 // use value [Alias name] as key for map
168 // cout << "added " << ptrDelimiter << " for " << line << endl;
170 cout << " ~~~ ommiting duplicated Alias names (" <<
171 ptrDelimiter << ")." << endl;
177 // ProxyLogger::getLogger()->createLogMessage(MSG_WARNING,
179 // "PropertyReader encountered empty property for '" +
180 // ProxyLogger::catos(line) + "'.");
181 cout << "Missing property value for " << line << endl;
186 // file calibration object name in local vector
188 fCalibObjList.push_back(name);
192 // ProxyLogger::getLogger()->createLogMessage(MSG_DEBUG, LOG_SOURCE_PROXY,
193 // "PropertyReader has read " + ProxyLogger::itos(count) +
194 // " properties from file '" + ProxyLogger::catos(filename) + "'.");
196 // maybe check also for .bad() for returning a false
202 void AliHLTPendolinoListReader::Print() const {
203 TIter iter(&fCalibObjList);
206 cout << "List Print:" << endl;
207 while ((detect = (TObjString*) (iter.Next()))) {
208 cout << " " << detect->String() << ":" << endl;
209 TMap* value = (TMap*) fCalibObjList.GetValue(detect->String().Data());
212 while ((alias = (TObjString*) (valIt.Next()))) {
213 cout << " " << alias->String() << endl;
217 cout << "---" << endl;
220 int AliHLTPendolinoListReader::RetrieveLastRunNumber(char* path) {
221 string strPath = path;
222 return AliHLTPendolinoListReader::RetrieveLastRunNumber(strPath);
225 int AliHLTPendolinoListReader::RetrieveLastRunNumber(string path) {
231 filename = path + "/lastRunNumber";
232 cout << " --- PATH to lastRunNumber is " << filename << endl;
234 pfile.open(filename.c_str(), ios_base::in);
236 cout << "Error while opening last RunNumber file or file does not exist."
240 if ((!pfile.eof()) && (!pfile.bad())) {
241 pfile.getline(line, 25);
242 runNumber = atoi(line);