fix for bug #66294
[u/mrichter/AliRoot.git] / SHUTTLE / test / TestHMPIDPreprocessor.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 // Prototype of HMPID Preprocessor
18 //
19
20 #include "TestHMPIDPreprocessor.h"
21
22 #include "AliCDBMetaData.h"
23 #include "AliDCSValue.h"
24 #include "AliLog.h"
25 #include "AliShuttleInterface.h"
26
27 #include <TTimeStamp.h>
28 #include <TObjString.h>
29 #include <TSystem.h>
30 #include <TList.h>
31
32 ClassImp(TestHMPIDPreprocessor)
33
34 //________________________________________________________________________________________
35 TestHMPIDPreprocessor::TestHMPIDPreprocessor():
36         AliPreprocessor("HMP",0)
37 {
38 // default constructor - Don't use this!
39
40 }
41
42 //________________________________________________________________________________________
43 TestHMPIDPreprocessor::TestHMPIDPreprocessor(AliShuttleInterface* shuttle):
44         AliPreprocessor("HMP", shuttle)
45 {
46 // constructor - shuttle must be instantiated!
47
48 }
49
50 //________________________________________________________________________________________
51 void TestHMPIDPreprocessor::Initialize(Int_t run, UInt_t startTime,
52         UInt_t endTime) 
53 {
54 // Initialize preprocessor
55
56         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
57                 TTimeStamp(startTime).AsString(),
58                 TTimeStamp(endTime).AsString()));
59
60         fRun = run;
61         fStartTime = startTime;
62         fEndTime = endTime;
63 }
64
65 //________________________________________________________________________________________
66 Bool_t TestHMPIDPreprocessor::ProcessDCS() 
67 {
68 // Initialize preprocessor
69
70         TString runType = GetRunType();
71         if(runType == "LED") return kFALSE;
72         return kTRUE;
73 }
74
75
76 //________________________________________________________________________________________
77 UInt_t TestHMPIDPreprocessor::Process(TMap* /*valueMap*/)
78 {
79 // process data retrieved by the Shuttle
80
81         Bool_t result = kFALSE;
82
83         // Get run type and start the processing algorithm accordingly
84         TString runType = GetRunType();
85         if (runType.Length()==0)
86         {
87                 Log("Undefined run type!");
88                 return 1;
89         }
90
91         Log(Form("Run type: %s", runType.Data()));
92
93         if (runType == "PHYSICS")
94         {
95                 // DAQ
96                 TList* filesources = GetFileSources(AliShuttleInterface::kDAQ, "DAQFile");
97
98                 if(!filesources) {
99                         AliError(Form("No sources found for thresholds.txt for run %d !", fRun));
100                         return 2;
101                 }
102
103                 AliInfo("Here's the list of sources for thresholds.txt");
104                 filesources->Print();
105
106                 TIter iter(filesources);
107                 TObjString* source;
108                 int i=0;
109                 while((source=dynamic_cast<TObjString*> (iter.Next()))){
110                         printf("\n\n Getting file #%d\n",++i);
111                         //if(i==1) continue;
112                         //TString filename = GetFile(AliShuttleInterface::kDAQ, "DAQFile", source->GetName());
113                         TString filename = "DAQfile.txt";
114                         if(!filename.Length()) {
115                                 AliError(Form("Error: retrieval of file from source %s failed!", source->GetName()));
116                                 delete filesources;
117                                 return 3;
118                         }
119                         TString command = Form("more %s",filename.Data());
120                         gSystem->Exec(command.Data());
121
122                         // STORAGE! The First file name will be stored into CDB, the second into reference storage
123                         TObjString filenameObj(filename);
124                         AliCDBMetaData metaData;
125                         if(i==1) result = Store("Calib", "DAQData", &filenameObj, &metaData);
126                         if(i==2) result = StoreReferenceData("Calib", "RefData", &filenameObj, &metaData);
127
128                 }
129                 delete filesources;
130
131         } else if (runType == "PEDESTALS")
132         {
133
134                 // DCS
135                 TString filename = GetFile(AliShuttleInterface::kDCS, "DCSFile", 0);
136                 if(!filename.Length()) {
137                         AliError(Form("Error: retrieval of file from DCS failed!"));
138                         return 4;
139                 }
140                 TString command = Form("more %s", filename.Data());
141                 gSystem->Exec(command.Data());
142
143                 // STORAGE! The First file name will be stored into CDB, the second into reference storage
144                 TObjString filenameObj(filename);
145                 AliCDBMetaData metaData;
146                 result = Store("Calib", "DCSData", &filenameObj, &metaData);
147
148         } else if (runType == "LED")
149         {
150
151                 // HLT
152                 TList* filesources = GetFileSources(AliShuttleInterface::kHLT, "HLTFile");
153
154                 if(!filesources) {
155                         Log(Form("No sources found for HLTFile for run %d !", fRun));
156                         return 5;
157                 }
158
159                 AliInfo("Here's the list of sources for HLTFile");
160                 filesources->Print();
161
162                 TIter iter(filesources);
163                 int i = 0;
164                 TObjString* source;
165                 while((source=dynamic_cast<TObjString*> (iter.Next()))){
166                         printf("\n\n Getting file #%d\n",++i);
167                         //if(i==1) continue;
168                         //TString filename = GetFile(AliShuttleInterface::kHLT, "HLTFile", source->GetName());
169                         TString filename="HLTfile.txt";
170                         if(!filename.Length()) {
171                                 AliError(Form("Error: retrieval of file from source %s failed!", source->GetName()));
172                                 delete filesources;
173                                 return 6;
174                         }
175                         TString command = Form("more %s",filename.Data());
176                         gSystem->Exec(command.Data());
177
178                         // STORAGE! The First file name will be stored into CDB, the second into reference storage
179                         TObjString filenameObj(filename);
180                         AliCDBMetaData metaData;
181                         if(i==1) result = Store("Calib", "HLTData", &filenameObj, &metaData);
182                         if(i==2) result = StoreReferenceData("Calib", "RefHLTData", &filenameObj, &metaData);
183
184                 }
185                 delete filesources;
186         } else {
187                 Log(Form("Unknown run type: %s", runType.Data()));
188         }
189         
190         if(!result) 
191         {
192                 Log("Storage error!");
193                 return 100;
194         }
195         
196         return 0;
197 }
198