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