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