]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Preprocessor.cxx
AliEveEventManager
[u/mrichter/AliRoot.git] / T0 / AliT0Preprocessor.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 $Log: AliT0Preprocessor.cxx,v $
18 Revision 1.8  2007/12/07 15:22:51  alla
19 bug fixed by Alberto
20  
21 Revision 1.7  2007/12/06 16:35:24  alla
22 new bugs fixed by Tomek
23
24 Revision 1.5  2007/11/23 19:28:52  alla
25 bug fixed
26
27 Version 2.1  2007/11/21 
28 Preprocessor storing data to OCDB (T.Malkiewicz)
29
30 Version 1.1  2006/10   
31 Preliminary test version (T.Malkiewicz)
32 */   
33 // T0 preprocessor:
34 // 1) takes data from DCS and passes it to the class AliTOFDataDCS 
35 // for processing and writes the result to the Reference DB.
36 // 2) takes data form DAQ (both from Laser Calibration and Physics runs), 
37 // processes it, and stores either to OCDB or to Reference DB.
38
39
40 #include "AliT0Preprocessor.h"
41 #include "AliT0DataDCS.h"
42 #include "AliT0CalibWalk.h"
43 #include "AliT0CalibTimeEq.h"
44
45 #include "AliCDBMetaData.h"
46 #include "AliDCSValue.h"
47 #include "AliLog.h"
48
49 #include <TTimeStamp.h>
50 #include <TFile.h>
51 #include <TObjString.h>
52 #include <TNamed.h>
53 #include "AliT0Dqclass.h"
54
55
56 ClassImp(AliT0Preprocessor)
57
58 //____________________________________________________
59 AliT0Preprocessor::AliT0Preprocessor(AliShuttleInterface* shuttle) : 
60   AliPreprocessor("T00", shuttle), 
61   fData(0)
62 {
63   //constructor
64   AddRunType("PHYSICS");
65   AddRunType("STANDALONE");
66   AddRunType("LASER");
67 }
68 //____________________________________________________
69
70 AliT0Preprocessor::~AliT0Preprocessor()
71 {
72   //destructor
73   delete fData;
74   fData = 0;
75 }
76 //____________________________________________________
77
78 void AliT0Preprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
79 {
80   // Creates AliT0DataDCS object
81   AliPreprocessor::Initialize(run, startTime, endTime);
82   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, TTimeStamp(startTime).AsString(), TTimeStamp(endTime).AsString()));
83   fData = new AliT0DataDCS(fRun, fStartTime, fEndTime);
84 }
85 //____________________________________________________
86
87 Bool_t AliT0Preprocessor::ProcessDCS(){
88         // Check whether DCS should be processed or not...
89         TString runType = GetRunType();
90         Log(Form("ProcessDCS - RunType: %s",runType.Data()));
91
92         if((runType == "STANDALONE")||(runType == "PHYSICS")){
93           //            return kFALSE;
94                 return kTRUE;
95         }else{
96         return kFALSE;
97         }
98 }
99 //____________________________________________________
100
101 UInt_t AliT0Preprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap){
102         // Fills data into AliT0DataDCS object
103         Log("Processing DCS DP");
104         Bool_t resultDCSMap=kFALSE;
105         Bool_t resultDCSStore=kFALSE;
106
107         if(!dcsAliasMap)
108         {
109           Log("No DCS input data");
110           return 1;
111         }
112         else
113         {
114           resultDCSMap=fData->ProcessData(*dcsAliasMap);
115           if(!resultDCSMap)
116           {
117             Log("Error when processing DCS data");
118             return 2;// return error Code for processed DCS data not stored
119           }
120           else
121           {
122             AliCDBMetaData metaDataDCS;
123             metaDataDCS.SetBeamPeriod(0);
124             metaDataDCS.SetResponsible("Tomasz Malkiewicz");
125             metaDataDCS.SetComment("This preprocessor fills an AliTODataDCS object.");
126             AliInfo("Storing DCS Data");
127             resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
128             if (!resultDCSStore)
129             {
130               Log("Some problems occurred while storing DCS data results in ReferenceDB");
131               return 2;// return error Code for processed DCS data not stored
132             }
133           }
134         }
135         return 0;
136 }
137 //____________________________________________________
138
139 UInt_t AliT0Preprocessor::ProcessLaser(){
140         // Processing data from DAQ Standalone run
141         Log("Processing Laser calibration - Walk Correction");
142         
143         Bool_t resultLaser=kFALSE;
144         //processing DAQ
145         TList* list = GetFileSources(kDAQ, "LASER");
146         if (list)
147         {
148             TIter iter(list);
149             TObjString *source;
150             while ((source = dynamic_cast<TObjString *> (iter.Next())))
151             {
152               const char *laserFile = GetFile(kDAQ, "LASER", source->GetName());
153               if (laserFile)
154               {
155                 Log(Form("File with Id LASER found in source %s!", source->GetName()));
156                 AliT0CalibWalk *laser = new AliT0CalibWalk();
157                 laser->MakeWalkCorrGraph(laserFile);
158                 AliCDBMetaData metaData;
159                 metaData.SetBeamPeriod(0);
160                 metaData.SetResponsible("Tomek&Michal");
161                 metaData.SetComment("Walk correction from laser runs.");
162                 resultLaser=Store("Calib","Slewing_Walk", laser, &metaData, 0, 1);
163                 delete laser;
164                 Log(Form("resultLaser = %d",resultLaser));
165               }
166               else
167               {
168                 Log(Form("Could not find file with Id LASER in source %s!", source->GetName()));
169                 return 1;
170               }
171             }
172             if (!resultLaser)
173             {
174               Log("No Laser Data stored");
175               return 3;//return error code for failure in storing Laser Data
176             }
177           } else {
178                 Log("No sources found for id LASER!");
179                 return 1;
180           }
181         return 0;
182 }
183 //____________________________________________________
184
185 UInt_t AliT0Preprocessor::ProcessPhysics(){
186         //Processing data from DAQ Physics run
187         Log("Processing Physics");
188
189         Bool_t resultOnline=kFALSE; 
190         //processing DAQ
191         TList* listPhys = GetFileSources(kDAQ, "PHYSICS");
192         if (listPhys)
193           {
194             TIter iter(listPhys);
195             TObjString *sourcePhys;
196             while ((sourcePhys = dynamic_cast<TObjString *> (iter.Next())))
197             {
198               const char *filePhys = GetFile(kDAQ, "PHYSICS", sourcePhys->GetName());
199               if (filePhys)
200               {
201                 AliT0CalibTimeEq *online = new AliT0CalibTimeEq();
202                 online->Reset();
203                 online->ComputeOnlineParams(filePhys);
204                 AliCDBMetaData metaData;
205                 metaData.SetBeamPeriod(0);
206                 metaData.SetResponsible("Tomek&Michal");
207                 metaData.SetComment("Time equalizing result.");
208                 resultOnline = Store("Calib","TimeDelay", online, &metaData, 0, 1);
209                 Log(Form("resultOnline = %d",resultOnline));
210                 delete online;
211               }
212                 else
213               {
214                 Log(Form("Could not find file with Id PHYSICS in source %s!", sourcePhys->GetName()));
215                 return 1;
216               }
217               
218             }
219             if (!resultOnline)
220             {
221               Log("No Data stored");
222               return 4;//return error code for failure in storing OCDB Data
223             }
224           } else {
225                 Log("No sources found for id PHYSICS!");
226                 return 1;
227           }
228         return 0;
229 }
230 //____________________________________________________
231
232 UInt_t AliT0Preprocessor::ProcessCosmic(){
233         //Processing data from DAQ Physics run
234         Log("Processing Laser Physics");
235
236         Bool_t resultLaserOnline=kFALSE; 
237         //processing DAQ
238         TList* listLaser = GetFileSources(kDAQ, "COSMIC");
239         if (listLaser)
240           {
241             TIter iter(listLaser);
242             TObjString *sourceLaser;
243             while ((sourceLaser = dynamic_cast<TObjString *> (iter.Next())))
244             {
245               const char *fileLaser = GetFile(kDAQ, "COSMIC", sourceLaser->GetName());
246               if (fileLaser)
247               {
248                 AliT0CalibTimeEq *onlineLaser = new AliT0CalibTimeEq();
249                 onlineLaser->Reset();
250                 onlineLaser->ComputeOnlineParams(fileLaser);
251                 AliCDBMetaData metaData;
252                 metaData.SetBeamPeriod(0);
253                 metaData.SetResponsible("Tomek&Michal");
254                 metaData.SetComment("Time equalizing result.");
255                 resultLaserOnline = Store("Calib","LaserTimeDelay", onlineLaser, &metaData, 0, 1);
256                 Log(Form("resultLaserOnline = %d",resultLaserOnline));
257                 delete onlineLaser;
258               }
259                 else
260               {
261                 Log(Form("Could not find file with Id COSMIC in source %s!", sourceLaser->GetName()));
262                 return 0;
263               }
264               
265             }
266             if (!resultLaserOnline)
267             {
268               Log("No Laser Data stored");
269               return 0;//return error code for failure in storing OCDB Data
270             }
271           } else {
272                 Log("No sources found for id COSMIC!");
273                 return 0;
274           }
275         return 0;
276 }
277 //____________________________________________________
278
279 UInt_t AliT0Preprocessor::Process(TMap* dcsAliasMap )
280 {
281   // T0 preprocessor return codes:
282   // return=0 : all ok
283   // return=1 : no DCS input data 
284   // return=2 : failed to store DCS data
285   // return=3 : no Laser data (Walk correction)
286   // return=4 : failed to store OCDB time equalized data
287   // return=5 : no DAQ input for OCDB
288   // return=6 : failed to retrieve DAQ data from OCDB
289   // return=7 : failed to store T0 OCDB data
290         Bool_t dcsDP = ProcessDCS();
291         Log(Form("dcsDP = %d",dcsDP));  
292         TString runType = GetRunType();
293         Log(Form("RunType: %s",runType.Data()));
294         //processing
295         if(runType == "STANDALONE"){
296           if(dcsDP==1){
297             Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
298             return iresultDCS;
299           }
300         }
301         if(runType == "LASER"){
302           Int_t iresultLaser = ProcessLaser();
303           Log(Form("iresultLaser = %d",iresultLaser));
304           return iresultLaser;
305         }
306         else if(runType == "PHYSICS"){
307           Int_t iresultPhysics = ProcessPhysics();
308          //      Int_t iresultCosmic = ProcessCosmic();
309           if(dcsDP==1){
310             Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
311             return iresultDCS;
312           }
313           Log(Form("iresultPhysics = %d",iresultPhysics));
314           return iresultPhysics; 
315           //            Log(Form("iresultPhysics =iresultCosmic %d",iresultCosmic));
316           //    return iresultCosmic; 
317         }       
318         
319         return 0;
320 }