]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | // | |
17 | // This class is a container for the data queried from DAQ's logbook and logbook_shuttle tables. | |
18 | // It holds the run number, the start time and end time of the run, | |
19 | // and the array of the detectors' status (Unprocessed, Inactive, Failed, Done) | |
20 | ||
21 | #include "AliShuttleLogbookEntry.h" | |
22 | #include "AliLog.h" | |
23 | #include "TTimeStamp.h" | |
24 | #include <TString.h> | |
25 | #include <TObjString.h> | |
26 | #include <TMap.h> | |
27 | ||
28 | ClassImp(AliShuttleLogbookEntry) | |
29 | ||
30 | //______________________________________________________________________________________________ | |
31 | AliShuttleLogbookEntry::AliShuttleLogbookEntry() : | |
32 | TObject(), | |
33 | fRun(-1), | |
34 | fRunParameters(0) | |
35 | { | |
36 | // | |
37 | // default constructor | |
38 | // | |
39 | ||
40 | const UInt_t nDet = AliShuttleInterface::NDetectors(); | |
41 | memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status)); | |
42 | fRunParameters.SetOwner(1); | |
43 | } | |
44 | ||
45 | //______________________________________________________________________________________________ | |
46 | AliShuttleLogbookEntry::AliShuttleLogbookEntry(Int_t run, Status* status) : | |
47 | TObject(), | |
48 | fRun(run), | |
49 | fRunParameters(0) | |
50 | { | |
51 | // | |
52 | // default constructor | |
53 | // | |
54 | ||
55 | const UInt_t nDet = AliShuttleInterface::NDetectors(); | |
56 | memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status)); | |
57 | if(status) SetDetectorStatus(status); | |
58 | fRunParameters.SetOwner(1); | |
59 | } | |
60 | ||
61 | //______________________________________________________________________________________________ | |
62 | AliShuttleLogbookEntry::~AliShuttleLogbookEntry() { | |
63 | // | |
64 | // destructor | |
65 | // | |
66 | fRunParameters.DeleteAll(); | |
67 | } | |
68 | ||
69 | //______________________________________________________________________________________________ | |
70 | AliShuttleLogbookEntry::AliShuttleLogbookEntry(const AliShuttleLogbookEntry &c) : | |
71 | TObject(), | |
72 | fRun(c.fRun), | |
73 | fRunParameters(0) | |
74 | { | |
75 | // | |
76 | // copy constructor | |
77 | // | |
78 | ||
79 | SetDetectorStatus(c.GetDetectorStatus()); | |
80 | fRunParameters.SetOwner(1); | |
81 | TIter iter(c.fRunParameters.GetTable()); | |
82 | TPair* aPair = 0; | |
83 | while((aPair = dynamic_cast<TPair*>(iter.Next()))){ | |
84 | TObjString* aKey= dynamic_cast<TObjString*>(aPair->Key()); | |
85 | TObjString* aValue= dynamic_cast<TObjString*>(aPair->Value()); | |
86 | fRunParameters.Add(aKey->Clone(), aValue->Clone()); | |
87 | } | |
88 | } | |
89 | ||
90 | //______________________________________________________________________________________________ | |
91 | AliShuttleLogbookEntry &AliShuttleLogbookEntry::operator=(const AliShuttleLogbookEntry &c) | |
92 | { | |
93 | // | |
94 | // assigment operator | |
95 | // | |
96 | ||
97 | if (this != &c) | |
98 | ((AliShuttleLogbookEntry &) c).Copy(*this); | |
99 | return *this; | |
100 | } | |
101 | ||
102 | //______________________________________________________________________________________________ | |
103 | void AliShuttleLogbookEntry::Copy(TObject& c) const | |
104 | { | |
105 | // | |
106 | // copy function | |
107 | // | |
108 | ||
109 | AliShuttleLogbookEntry& target = (AliShuttleLogbookEntry &) c; | |
110 | ||
111 | target.fRun = fRun; | |
112 | target.fRunParameters.SetOwner(1); | |
113 | TIter iter(fRunParameters.GetTable()); | |
114 | TPair* aPair = 0; | |
115 | while((aPair = dynamic_cast<TPair*>(iter.Next()))){ | |
116 | TObjString* aKey= dynamic_cast<TObjString*>(aPair->Key()); | |
117 | TObjString* aValue= dynamic_cast<TObjString*>(aPair->Value()); | |
118 | target.fRunParameters.Add(aKey->Clone(), aValue->Clone()); | |
119 | } | |
120 | ||
121 | target.SetDetectorStatus(GetDetectorStatus()); | |
122 | } | |
123 | ||
124 | //______________________________________________________________________________________________ | |
125 | AliShuttleLogbookEntry::Status AliShuttleLogbookEntry::GetDetectorStatus(Int_t detPos) const | |
126 | { | |
127 | // | |
128 | // get detector status from detector code | |
129 | // | |
130 | ||
131 | if(detPos < 0 || detPos >= (Int_t) AliShuttleInterface::NDetectors()) { | |
132 | AliError(Form("Invalid parameter: %d", detPos)); | |
133 | return kUnprocessed; | |
134 | } | |
135 | return fDetectorStatus[detPos]; | |
136 | } | |
137 | ||
138 | //______________________________________________________________________________________________ | |
139 | void AliShuttleLogbookEntry::SetDetectorStatus(const char* detName, Status status) | |
140 | { | |
141 | // | |
142 | // set detector status from detector code | |
143 | // | |
144 | ||
145 | Int_t detPos = AliShuttleInterface::GetDetPos(detName); | |
146 | if(detPos<0) return; | |
147 | SetDetectorStatus(detPos, status); | |
148 | } | |
149 | ||
150 | //______________________________________________________________________________________________ | |
151 | void AliShuttleLogbookEntry::SetDetectorStatus(const char* detName, const char* statusName) | |
152 | { | |
153 | // | |
154 | // set detector status from detector code | |
155 | // | |
156 | ||
157 | Int_t detPos = AliShuttleInterface::GetDetPos(detName); | |
158 | if(detPos<0) return; | |
159 | SetDetectorStatus(detPos, statusName); | |
160 | } | |
161 | ||
162 | //______________________________________________________________________________________________ | |
163 | void AliShuttleLogbookEntry::SetDetectorStatus(Status* status) | |
164 | { | |
165 | // | |
166 | // set detector status from detector code | |
167 | // | |
168 | ||
169 | for(UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++){ | |
170 | fDetectorStatus[i] = status[i]; | |
171 | } | |
172 | } | |
173 | ||
174 | //______________________________________________________________________________________________ | |
175 | void AliShuttleLogbookEntry::SetDetectorStatus(UInt_t detPos, Status status) | |
176 | { | |
177 | // | |
178 | // set detector status from detector code | |
179 | // | |
180 | ||
181 | if(detPos >= AliShuttleInterface::NDetectors()) { | |
182 | AliError(Form("Shuttle has only %d subdetectors!", AliShuttleInterface::NDetectors())); | |
183 | return; | |
184 | } | |
185 | fDetectorStatus[detPos] = status; | |
186 | } | |
187 | ||
188 | //______________________________________________________________________________________________ | |
189 | void AliShuttleLogbookEntry::SetDetectorStatus(UInt_t detPos, const char* statusName) | |
190 | { | |
191 | // | |
192 | // set detector status from detector code | |
193 | // | |
194 | ||
195 | if(detPos >= AliShuttleInterface::NDetectors()) { | |
196 | AliError(Form("Shuttle has only %d subdetectors!", AliShuttleInterface::NDetectors())); | |
197 | return; | |
198 | } | |
199 | TString statusString(statusName); | |
200 | if(statusString.Contains("UNPROCESSED", TString::kIgnoreCase)){ | |
201 | SetDetectorStatus(detPos, kUnprocessed); | |
202 | } else if (statusString.Contains("INACTIVE", TString::kIgnoreCase)) { | |
203 | SetDetectorStatus(detPos, kInactive); | |
204 | } else if (statusString.Contains("FAILED", TString::kIgnoreCase)) { | |
205 | SetDetectorStatus(detPos, kFailed); | |
206 | } else if (statusString.Contains("DONE", TString::kIgnoreCase)) { | |
207 | SetDetectorStatus(detPos, kDone); | |
208 | } else { | |
209 | AliError(Form("Invalid status name: %s", statusName)); | |
210 | } | |
211 | } | |
212 | ||
213 | //______________________________________________________________________________________________ | |
214 | Bool_t AliShuttleLogbookEntry::IsDone() const{ | |
215 | // | |
216 | // return TRUE if all subdetectors are in status DONE, FAILED or INACTIVE | |
217 | // | |
218 | ||
219 | for(UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++){ | |
220 | if(fDetectorStatus[i] == kUnprocessed) return kFALSE; | |
221 | } | |
222 | return kTRUE; | |
223 | } | |
224 | ||
225 | //______________________________________________________________________________________________ | |
226 | const char* AliShuttleLogbookEntry::GetDetectorStatusName(Status status) | |
227 | { | |
228 | // | |
229 | // returns a name (string) of the detector status | |
230 | // | |
231 | ||
232 | switch (status){ | |
233 | case kUnprocessed: return "UNPROCESSED"; | |
234 | case kInactive: return "INACTIVE"; | |
235 | case kFailed: return "FAILED"; | |
236 | case kDone: return "DONE"; | |
237 | } | |
238 | return 0; | |
239 | ||
240 | } | |
241 | ||
242 | //______________________________________________________________________________________________ | |
243 | void AliShuttleLogbookEntry::Print(Option_t* option) const | |
244 | { | |
245 | // | |
246 | // print current shuttle logbook entry | |
247 | // | |
248 | ||
249 | TString message = "\n*** Run parameters ***\n"; | |
250 | TTimeStamp startTimeStamp(GetStartTime()); | |
251 | TTimeStamp endTimeStamp(GetEndTime()); | |
252 | message += Form("\tRun \t\t%d\n", fRun); | |
253 | message += Form("\tStarted \t%s\n", startTimeStamp.AsString("s")); | |
254 | message += Form("\tFinished \t%s\n", endTimeStamp.AsString("s")); | |
255 | message += "\n*** Detector status ***\n"; | |
256 | ||
257 | for (UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++) | |
258 | { | |
259 | message += Form("\t%2d - %s: %s \n", i, AliShuttleInterface::GetDetName(i), | |
260 | GetDetectorStatusName(fDetectorStatus[i])); | |
261 | } | |
262 | ||
263 | AliInfo(Form("option: %s",option)); | |
264 | TString optionStr(option); | |
265 | if(optionStr=="all"){ | |
266 | message += "\nPrinting full list of run parameters\n"; | |
267 | message += "\tParameter Value\n"; | |
268 | TIter iter(fRunParameters.GetTable()); | |
269 | TPair* aPair = 0; | |
270 | while((aPair = dynamic_cast<TPair*>(iter.Next()))){ | |
271 | TObjString* aKey= dynamic_cast<TObjString*>(aPair->Key()); | |
272 | TObjString* aValue= dynamic_cast<TObjString*>(aPair->Value()); | |
273 | TString keyStr=aKey->GetName(); | |
274 | if(keyStr != "log"){ | |
275 | message += Form("\t%s ", aKey->GetName()); | |
276 | if(keyStr.Length()<30) message.Append(' ', 30-keyStr.Length()); | |
277 | message += Form("%s\n", aValue->GetName()); | |
278 | } else { | |
279 | TString logStr(aValue->GetName(), 100); | |
280 | message += Form("\tlog (first 100 chars) %s \n",logStr.Data()); | |
281 | } | |
282 | } | |
283 | } | |
284 | ||
285 | AliInfo(Form("%s",message.Data())); | |
286 | } | |
287 | //______________________________________________________________________________________________ | |
288 | void AliShuttleLogbookEntry::SetRunParameter(const char* key, const char* value){ | |
289 | // | |
290 | // set a run parameter (read from the DAQ logbook) | |
291 | // | |
292 | ||
293 | TObjString* keyObj = new TObjString(key); | |
294 | if (fRunParameters.Contains(key)) { | |
295 | AliWarning(Form("Parameter %s already existing and it will be replaced.", key)); | |
296 | delete fRunParameters.Remove(keyObj); | |
297 | ||
298 | } | |
299 | fRunParameters.Add(keyObj, new TObjString(value)); | |
300 | AliDebug(2, Form("Number of parameters: %d", fRunParameters.GetEntries())); | |
301 | } | |
302 | //______________________________________________________________________________________________ | |
303 | const char* AliShuttleLogbookEntry::GetRunParameter(const char* key) const{ | |
304 | // | |
305 | // get a run parameter | |
306 | // | |
307 | ||
308 | TObjString* value = dynamic_cast<TObjString*> (fRunParameters.GetValue(key)); | |
309 | if(!value) { | |
310 | AliError(Form("No such parameter: %s", key)); | |
311 | return 0; | |
312 | } | |
313 | return value->GetName(); | |
314 | } |