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