Run type field added in SHUTTLE framework. Run type is read from "run type" logbook...
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttleLogbookEntry.cxx
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         for (UInt_t i=0;i<nDet;i++)
41         {
42                 fRunType[i]="";
43         }
44         fRunParameters.SetOwner(1);
45 }
46
47 //______________________________________________________________________________________________
48 AliShuttleLogbookEntry::AliShuttleLogbookEntry(Int_t run, Status* status) :
49 TObject(),
50 fRun(run),
51 fRunParameters(0)
52 {
53 // default constructor
54
55         const UInt_t nDet = AliShuttleInterface::NDetectors();
56         memset(fDetectorStatus, kUnprocessed, nDet*sizeof(Status));
57         if(status) SetDetectorStatus(status);
58         for (UInt_t i=0;i<nDet;i++)
59         {
60                 fRunType[i]="";
61         }
62         fRunParameters.SetOwner(1);
63 }
64
65 //______________________________________________________________________________________________
66 AliShuttleLogbookEntry::~AliShuttleLogbookEntry() {
67 // destructor
68
69 }
70
71 //______________________________________________________________________________________________
72 AliShuttleLogbookEntry::AliShuttleLogbookEntry(const AliShuttleLogbookEntry &c) :
73 TObject(),
74 fRun(c.fRun),
75 fRunParameters(0)
76 {
77   // copy constructor
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         for (UInt_t i=0;i<AliShuttleInterface::NDetectors();i++)
90         {
91                 fRunType[i]=c.GetRunType(i);
92         }
93 }
94
95 //______________________________________________________________________________________________
96 AliShuttleLogbookEntry &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 //______________________________________________________________________________________________
106 void AliShuttleLogbookEntry::Copy(TObject& c) const
107 {
108   // copy function
109
110         AliShuttleLogbookEntry& target = (AliShuttleLogbookEntry &) c;
111
112         target.fRun = fRun;
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         }
121
122         target.SetDetectorStatus(GetDetectorStatus());
123         for (UInt_t i=0;i<AliShuttleInterface::NDetectors();i++)
124         {
125                 target.SetRunType(i, fRunType[i]);
126         }
127 }
128
129 //______________________________________________________________________________________________
130 AliShuttleLogbookEntry::Status AliShuttleLogbookEntry::GetDetectorStatus(Int_t detPos) const
131 {
132 // get detector status from detector code
133
134         if(detPos < 0 || detPos >= (Int_t) AliShuttleInterface::NDetectors()) {
135                 AliError(Form("Invalid parameter: %d", detPos));
136                 return kUnprocessed;
137         }
138         return fDetectorStatus[detPos];
139 }
140
141 //______________________________________________________________________________________________
142 void AliShuttleLogbookEntry::SetDetectorStatus(const char* detName, Status status)
143 {
144 // set detector status from detector code
145
146         Int_t detPos = AliShuttleInterface::GetDetPos(detName);
147         if(detPos<0) return;
148         SetDetectorStatus(detPos, status);
149 }
150
151 //______________________________________________________________________________________________
152 void 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
161 //______________________________________________________________________________________________
162 void AliShuttleLogbookEntry::SetDetectorStatus(Status* status)
163 {
164 // set detector status from detector code
165
166         for(UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++){
167                 fDetectorStatus[i] = status[i];
168         }
169 }
170
171 //______________________________________________________________________________________________
172 void AliShuttleLogbookEntry::SetDetectorStatus(UInt_t detPos, Status status)
173 {
174 // set detector status from detector code
175
176         if(detPos >= AliShuttleInterface::NDetectors()) {
177                 AliError(Form("Shuttle has only %d subdetectors!", AliShuttleInterface::NDetectors()));
178                 return;
179         }
180         fDetectorStatus[detPos] = status;
181 }
182
183 //______________________________________________________________________________________________
184 void 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
206
207
208 //______________________________________________________________________________________________
209 const 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 //______________________________________________________________________________________________
221 void 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 //______________________________________________________________________________________________
231 void 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 //______________________________________________________________________________________________
241 void 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
252 //______________________________________________________________________________________________
253 Bool_t AliShuttleLogbookEntry::IsDone() const{
254 // return TRUE if all subdetectors are in status DONE, FAILED or INACTIVE
255
256         for(UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++){
257                 if(fDetectorStatus[i] == kUnprocessed) return kFALSE;
258         }
259         return kTRUE;
260 }
261
262 //______________________________________________________________________________________________
263 const char* AliShuttleLogbookEntry::GetDetectorStatusName(Status status)
264 {
265   // returns a name (string) of the detector status
266
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
275 }
276
277 //______________________________________________________________________________________________
278 void AliShuttleLogbookEntry::Print(Option_t* option) const
279 {
280   // print current shuttle logbook entry
281
282         TString message = "\n*** Run parameters ***\n";
283         TTimeStamp startTimeStamp(GetStartTime());
284         TTimeStamp endTimeStamp(GetEndTime());
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
290         for (UInt_t i=0; i < AliShuttleInterface::NDetectors(); i++)
291         {
292                 message += Form("\t%2d - %s: %s ", i, AliShuttleInterface::GetDetName(i),
293                                         GetDetectorStatusName(fDetectorStatus[i]));
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         }
301
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";
319                         }
320                 }
321         }
322
323         AliInfo(Form("%s",message.Data()));
324 }
325 //______________________________________________________________________________________________
326 void AliShuttleLogbookEntry::SetRunParameter(const char* key, const char* value){
327 // set a run parameter (read from the DAQ logbook)
328
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);
333
334         }
335         fRunParameters.Add(keyObj, new TObjString(value));
336         AliDebug(2, Form("Number of parameters: %d", fRunParameters.GetEntries()));
337 }
338 //______________________________________________________________________________________________
339 const char* AliShuttleLogbookEntry::GetRunParameter(const char* key) const{
340 // get a run parameter
341
342         TObjString* value = dynamic_cast<TObjString*> (fRunParameters.GetValue(key));
343         if(!value) {
344                 AliError(Form("No such parameter: %s", key));
345                 return 0;
346         }
347         return value->GetName();
348 }