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