Function Bool_t GetHLTStatus added to preprocessor. It returns the status of HLT
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestPreprocessor.cxx
CommitLineData
5c6b40ae 1#include "AliTestPreprocessor.h"
2
3#include "AliCDBMetaData.h"
d461a8a7 4#include "AliCDBEntry.h"
5c6b40ae 5#include "AliDCSValue.h"
6#include "AliLog.h"
7#include "AliTestDataDCS.h"
8
9#include <TTimeStamp.h>
d461a8a7 10#include <TObjString.h>
9827400b 11#include <TList.h>
5c6b40ae 12
13//
14// This class is an example for a simple preprocessor.
15// It takes data from DCS and passes it to the class AliTestDataDCS, which
16// reformats its. This class is then written to the CDB.
17//
18
19ClassImp(AliTestPreprocessor)
20
36137ac1 21//______________________________________________________________________________________________
fc5a4708 22AliTestPreprocessor::AliTestPreprocessor(AliShuttleInterface* shuttle) :
23 AliPreprocessor("TPC", shuttle),
5c6b40ae 24 fData(0)
25{
26 // constructor
27}
28
36137ac1 29//______________________________________________________________________________________________
5c6b40ae 30AliTestPreprocessor::~AliTestPreprocessor()
31{
32 // destructor
33}
34
36137ac1 35//______________________________________________________________________________________________
5c6b40ae 36void AliTestPreprocessor::Initialize(Int_t run, UInt_t startTime,
37 UInt_t endTime)
38{
39 // Creates AliTestDataDCS object
40
41 AliPreprocessor::Initialize(run, startTime, endTime);
42
9827400b 43 Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
5c6b40ae 44 TTimeStamp(startTime).AsString(),
45 TTimeStamp(endTime).AsString()));
46
47 fData = new AliTestDataDCS(fRun, fStartTime, fEndTime);
48}
49
36137ac1 50//______________________________________________________________________________________________
9827400b 51Bool_t AliTestPreprocessor::ProcessDCS()
52{
53 //
54 // decide here if DCS data is to be processed
55 //
56
57 // TODO implement a decision, e.g. based on the run type
58 // In this example: Skip DCS if run type is CALIB
59 if (strcmp(GetRunType(), "CALIB") == 0)
60 return kFALSE;
61
62 return kTRUE;
63}
64
65//______________________________________________________________________________________________
36137ac1 66UInt_t AliTestPreprocessor::Process(TMap* dcsAliasMap)
5c6b40ae 67{
68 // Fills data into a AliTestDataDCS object
69
70 if (!dcsAliasMap)
886d60e6 71 {
72 Log("ERROR: No DCS map provided by SHUTTLE!");
73 return 1;
74 }
87968cd5 75
36137ac1 76 // The processing of the DCS input data is forwarded to AliTestDataDCS
441b0e9c 77 fData->ProcessData(*dcsAliasMap);
5c6b40ae 78
441b0e9c 79 // Example of how to retrieve the run type from the Shuttle, using GetRunType() function
80 // TODO Here the run type for the "DET" detector must be set manually with SetInputRunType function,
81 // in reality it will be read from the "run type" logbook!
82 TString runType = GetRunType();
9827400b 83 Log(Form("Run type for run %d: %s", fRun, runType.Data()));
441b0e9c 84
886d60e6 85 // Example of how to retrieve the list of sources that produced the file with id DRIFTVELOCITY
86 TList* sourceList = GetFileSources(kDAQ, "DRIFTVELOCITY");
87968cd5 87 sourceList = GetFileSources(kHLT, "HLTData");
886d60e6 88 if (!sourceList)
89 {
87968cd5 90 Log("Error retrieving list of sources from FXS!");
91 return 1;
886d60e6 92 }
87968cd5 93
94 if (sourceList->GetEntries() == 0)
95 {
96 Log("No sources found for id HLTData!");
97 // TODO What to do now depends on the expected behaviour of the
98 // online DA: if it expected to produce data for the FXS every run, then
99 // if no sources are found it means a problem happened and you should return error;
100 // if DA may or may not send files to FXS, then you shouldn't return error
101 // and go on with the analysis!
102 return 1;
103 }
104
105 // TODO We have the list of sources that produced the files with Id DRIFTVELOCITY.
886d60e6 106 // Now we will loop on the list and we'll query the files one by one.
107 Log("The following sources produced files with the id DRIFTVELOCITY");
108 sourceList->Print();
4a33bdd9 109
886d60e6 110 TIter iter(sourceList);
111 TObjString *source = 0;
112 while((source=dynamic_cast<TObjString*> (iter.Next()))){
113 TString fileName = GetFile(kDAQ, "DRIFTVELOCITY", source->GetName());
114 if (fileName.Length() > 0)
115 Log(Form("Got the file %s, now we can extract some values.", fileName.Data()));
116 }
36137ac1 117
886d60e6 118 delete sourceList;
119
87968cd5 120 // Example of retrieving files from HLT, including how to query HLT status
121
122 Bool_t hltStatus = GetHLTStatus(); // 1 = HLT ON (=> Query HLT), 0 = HLT OFF (=> skip HLT query)
123
124 if (hltStatus)
125 {
126 Log("HLT is ON, let's query our files");
127 sourceList = GetFileSources(kHLT, "HLTData");
128 if (!sourceList)
129 {
130 Log("Error retrieving list of sources from FXS!");
131 return 1;
132 }
133
134 if (sourceList->GetEntries() == 0)
135 {
136 Log("No sources found for id HLTData!");
137 // TODO What to do now depends on the expected behaviour of the
138 // online DA: if it expected to produce data for the FXS every run, then
139 // if no sources are found it means a problem happened and you should return error;
140 // if DA may or may not send files to FXS, then you shouldn't return error
141 // and go on with the analysis!
142 return 1;
143 }
144 Log("The following sources produced files with the id HLTData");
145
146 sourceList->Print();
147
148 TIter iter(sourceList);
149 TObjString *source = 0;
150 while((source=dynamic_cast<TObjString*> (iter.Next()))){
151 TString fileName = GetFile(kHLT, "HLTData", source->GetName());
152 if (fileName.Length() > 0)
153 Log(Form("Got the file %s from HLT, now we can extract some values.", fileName.Data()));
154 }
155
156 delete sourceList;
157
158 } else {
159 Log("HLT is OFF, skipping query...");
160 }
161
4a33bdd9 162 // Example of how to retrieve the list of sources that produced files
163 sourceList = GetFileSources(kDAQ);
164 if (!sourceList)
165 {
166 Log("Error: No sources found!");
167 return 1;
168 }
169
170 Log("The following sources produced files");
171 sourceList->Print();
172 delete sourceList;
173
174 // Example of how to retrieve the list of ids from a given source
175 TList* idList = GetFileIDs(kDAQ, "LDC0");
176 if (!idList)
177 {
178 Log("Error: No IDs found!");
179 return 1;
180 }
181
182 Log("The following ids are available");
183 idList->Print();
184 delete idList;
185
886d60e6 186 // Example to store a file directly to the reference storage
187 // Suppose we have queried the file from the FXS. Now the file is available locally and is called "file1.root".
188 const char* refFileName="file1.root";
189 if (!StoreReferenceFile(refFileName, "InputData.root"))
9827400b 190 return 1;
191
36137ac1 192
eba76848 193 // Example of how to retrieve a run parameter using GetRunParameter function
194 // TODO Here the parameter must be set manually with SetInputRunParameter function,
195 // in reality it will be read from the run logbook!
196
197 // note that the parameters are returned as character strings!
198 const char* nEvents = GetRunParameter("totalEvents");
199 if (nEvents) {
200 Log(Form("Number of events for run %d: %s",fRun, nEvents));
201 } else {
202 Log(Form("Number of events not put in logbook!"));
203 }
204
d461a8a7 205 // Example of how to retrieve a condition object from OCDB
206
207 AliCDBEntry *entry = GetFromOCDB("Calib", "Data");
208 if (!entry)
209 {
210 Log("No object found in OCDB!");
211 } else {
87968cd5 212 Log("Got TPC/Calib/Data object from OCDB. The object's metadata is: ");
213 entry->PrintMetaData();
d461a8a7 214 }
215
eba76848 216
36137ac1 217 //Now we have to store the final CDB file
5c6b40ae 218 AliCDBMetaData metaData;
219 metaData.SetBeamPeriod(0);
441b0e9c 220 metaData.SetResponsible("TPC expert");
5c6b40ae 221 metaData.SetComment("This preprocessor fills an AliTestDataDCS object.");
222
9827400b 223 Bool_t result = Store("Calib", "Data", fData, &metaData, 0, 0);
5c6b40ae 224 delete fData;
225 fData = 0;
226
9827400b 227 if (!result)
228 return 1;
229
230 return 0;
5c6b40ae 231}
232