several bugfixes
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleLogbookEntry.cxx
CommitLineData
2bb7b766 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"
eba76848 24#include <TString.h>
25#include <TObjString.h>
26#include <TMap.h>
2bb7b766 27
28ClassImp(AliShuttleLogbookEntry)
29
30//______________________________________________________________________________________________
31AliShuttleLogbookEntry::AliShuttleLogbookEntry() :
32TObject(),
33fRun(-1),
eba76848 34fRunParameters(0)
2bb7b766 35{
9827400b 36 //
37 // default constructor
38 //
2bb7b766 39
eba76848 40 const UInt_t nDet = AliShuttleInterface::NDetectors();
2bb7b766 41 memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status));
eba76848 42 fRunParameters.SetOwner(1);
2bb7b766 43}
44
45//______________________________________________________________________________________________
eba76848 46AliShuttleLogbookEntry::AliShuttleLogbookEntry(Int_t run, Status* status) :
2bb7b766 47TObject(),
48fRun(run),
eba76848 49fRunParameters(0)
2bb7b766 50{
9827400b 51 //
52 // default constructor
53 //
2bb7b766 54
eba76848 55 const UInt_t nDet = AliShuttleInterface::NDetectors();
2bb7b766 56 memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status));
57 if(status) SetDetectorStatus(status);
eba76848 58 fRunParameters.SetOwner(1);
2bb7b766 59}
60
61//______________________________________________________________________________________________
62AliShuttleLogbookEntry::~AliShuttleLogbookEntry() {
9827400b 63 //
64 // destructor
65 //
2bb7b766 66
2bb7b766 67}
68
69//______________________________________________________________________________________________
70AliShuttleLogbookEntry::AliShuttleLogbookEntry(const AliShuttleLogbookEntry &c) :
71TObject(),
72fRun(c.fRun),
eba76848 73fRunParameters(0)
2bb7b766 74{
9827400b 75 //
76 // copy constructor
77 //
2bb7b766 78
eba76848 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 }
2bb7b766 88}
89
90//______________________________________________________________________________________________
91AliShuttleLogbookEntry &AliShuttleLogbookEntry::operator=(const AliShuttleLogbookEntry &c)
92{
9827400b 93 //
94 // assigment operator
95 //
2bb7b766 96
97 if (this != &c)
98 ((AliShuttleLogbookEntry &) c).Copy(*this);
99 return *this;
100}
101
102//______________________________________________________________________________________________
103void AliShuttleLogbookEntry::Copy(TObject& c) const
104{
9827400b 105 //
106 // copy function
107 //
2bb7b766 108
109 AliShuttleLogbookEntry& target = (AliShuttleLogbookEntry &) c;
110
111 target.fRun = fRun;
eba76848 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 }
2bb7b766 120
121 target.SetDetectorStatus(GetDetectorStatus());
2bb7b766 122}
123
124//______________________________________________________________________________________________
125AliShuttleLogbookEntry::Status AliShuttleLogbookEntry::GetDetectorStatus(Int_t detPos) const
126{
9827400b 127 //
128 // get detector status from detector code
129 //
2bb7b766 130
eba76848 131 if(detPos < 0 || detPos >= (Int_t) AliShuttleInterface::NDetectors()) {
2bb7b766 132 AliError(Form("Invalid parameter: %d", detPos));
133 return kUnprocessed;
134 }
135 return fDetectorStatus[detPos];
136}
137
138//______________________________________________________________________________________________
eba76848 139void AliShuttleLogbookEntry::SetDetectorStatus(const char* detName, Status status)
2bb7b766 140{
9827400b 141 //
142 // set detector status from detector code
143 //
2bb7b766 144
eba76848 145 Int_t detPos = AliShuttleInterface::GetDetPos(detName);
2bb7b766 146 if(detPos<0) return;
147 SetDetectorStatus(detPos, status);
148}
149
150//______________________________________________________________________________________________
eba76848 151void AliShuttleLogbookEntry::SetDetectorStatus(const char* detName, const char* statusName)
152{
9827400b 153 //
154 // set detector status from detector code
155 //
eba76848 156
157 Int_t detPos = AliShuttleInterface::GetDetPos(detName);
158 if(detPos<0) return;
159 SetDetectorStatus(detPos, statusName);
160}
161
162//______________________________________________________________________________________________
2bb7b766 163void AliShuttleLogbookEntry::SetDetectorStatus(Status* status)
164{
9827400b 165 //
166 // set detector status from detector code
167 //
2bb7b766 168
eba76848 169 for(UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++){
2bb7b766 170 fDetectorStatus[i] = status[i];
171 }
172}
173
174//______________________________________________________________________________________________
175void AliShuttleLogbookEntry::SetDetectorStatus(UInt_t detPos, Status status)
176{
9827400b 177 //
178 // set detector status from detector code
179 //
2bb7b766 180
eba76848 181 if(detPos >= AliShuttleInterface::NDetectors()) {
182 AliError(Form("Shuttle has only %d subdetectors!", AliShuttleInterface::NDetectors()));
2bb7b766 183 return;
184 }
185 fDetectorStatus[detPos] = status;
186}
187
188//______________________________________________________________________________________________
eba76848 189void AliShuttleLogbookEntry::SetDetectorStatus(UInt_t detPos, const char* statusName)
190{
9827400b 191 //
192 // set detector status from detector code
193 //
eba76848 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//______________________________________________________________________________________________
2bb7b766 214Bool_t AliShuttleLogbookEntry::IsDone() const{
9827400b 215 //
216 // return TRUE if all subdetectors are in status DONE, FAILED or INACTIVE
217 //
2bb7b766 218
eba76848 219 for(UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++){
2bb7b766 220 if(fDetectorStatus[i] == kUnprocessed) return kFALSE;
221 }
222 return kTRUE;
223}
224
225//______________________________________________________________________________________________
226const char* AliShuttleLogbookEntry::GetDetectorStatusName(Status status)
227{
9827400b 228 //
229 // returns a name (string) of the detector status
230 //
2bb7b766 231
eba76848 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
2bb7b766 240}
241
242//______________________________________________________________________________________________
eba76848 243void AliShuttleLogbookEntry::Print(Option_t* option) const
2bb7b766 244{
9827400b 245 //
246 // print current shuttle logbook entry
247 //
2bb7b766 248
249 TString message = "\n*** Run parameters ***\n";
eba76848 250 TTimeStamp startTimeStamp(GetStartTime());
251 TTimeStamp endTimeStamp(GetEndTime());
2bb7b766 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
441b0e9c 257 for (UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++)
258 {
9827400b 259 message += Form("\t%2d - %s: %s \n", i, AliShuttleInterface::GetDetName(i),
2bb7b766 260 GetDetectorStatusName(fDetectorStatus[i]));
441b0e9c 261 }
2bb7b766 262
eba76848 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 {
ea3b94b8 279 TString logStr(aValue->GetName(), 100);
280 message += Form("\tlog (first 100 chars) %s \n",logStr.Data());
2bb7b766 281 }
282 }
2bb7b766 283 }
284
eba76848 285 AliInfo(Form("%s",message.Data()));
2bb7b766 286}
2bb7b766 287//______________________________________________________________________________________________
eba76848 288void AliShuttleLogbookEntry::SetRunParameter(const char* key, const char* value){
9827400b 289 //
290 // set a run parameter (read from the DAQ logbook)
291 //
2bb7b766 292
eba76848 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);
2bb7b766 297
2bb7b766 298 }
eba76848 299 fRunParameters.Add(keyObj, new TObjString(value));
300 AliDebug(2, Form("Number of parameters: %d", fRunParameters.GetEntries()));
2bb7b766 301}
2bb7b766 302//______________________________________________________________________________________________
eba76848 303const char* AliShuttleLogbookEntry::GetRunParameter(const char* key) const{
9827400b 304 //
305 // get a run parameter
306 //
2bb7b766 307
eba76848 308 TObjString* value = dynamic_cast<TObjString*> (fRunParameters.GetValue(key));
309 if(!value) {
310 AliError(Form("No such parameter: %s", key));
311 return 0;
2bb7b766 312 }
eba76848 313 return value->GetName();
2bb7b766 314}