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