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