]> git.uio.no Git - u/mrichter/AliRoot.git/blob - T0/AliT0Preprocessor.cxx
Preprocessor with new DA
[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$
18 Version 2.1  2007/11/21 
19 Preprocessor storing data to OCDB (T.Malkiewicz)
20
21 Version 1.1  2006/10   
22 Preliminary test version (T.Malkiewicz)
23 */   
24
25 // T0 preprocessor:
26 // 1) takes data from DCS and passes it to the class AliTOFDataDCS for processing and writes the result to the Reference DB.
27 // 2) takes data form DAQ (both from Laser Calibration and Physics runs), processes it, and stores either to OCDB or to Reference DB.
28
29 #include "AliT0Preprocessor.h"
30 #include "AliT0DataDCS.h"
31 #include "AliT0CalibWalk.h"
32 #include "AliT0CalibTimeEq.h"
33
34 #include "AliCDBMetaData.h"
35 #include "AliDCSValue.h"
36 #include "AliLog.h"
37
38 #include <TTimeStamp.h>
39 #include <TFile.h>
40 #include <TObjString.h>
41 #include <TNamed.h>
42 #include "AliT0Dqclass.h"
43
44
45 ClassImp(AliT0Preprocessor)
46
47 //____________________________________________________
48 AliT0Preprocessor::AliT0Preprocessor(AliShuttleInterface* shuttle) : AliPreprocessor("T00", shuttle),
49 fData(0)
50 {
51   //constructor
52 }
53 //____________________________________________________
54
55 AliT0Preprocessor::~AliT0Preprocessor()
56 {
57   delete fData;
58   fData = 0;
59 }
60 //____________________________________________________
61
62 void AliT0Preprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
63 {
64   AliPreprocessor::Initialize(run, startTime, endTime);
65   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, TTimeStamp(startTime).AsString(), TTimeStamp(endTime).AsString()));
66   fData = new AliT0DataDCS(fRun, fStartTime, fEndTime);
67 }
68 //____________________________________________________
69
70 UInt_t AliT0Preprocessor::Process(TMap* dcsAliasMap )
71 {
72   // T0 preprocessor return codes:
73   // return=0 : all ok
74   // return=1 : no DCS input data 
75   // return=2 : failed to store DCS data
76   // return=3 : no Laser data (Walk correction)
77   // return=4 : failed to store OCDB time equalized data
78   // return=5 : no DAQ input for OCDB
79   // return=6 : failed to retrieve DAQ data from OCDB
80   // return=7 : failed to store T0 OCDB data
81
82         Bool_t resultDCSMap=kFALSE;
83         Bool_t resultDCSStore=kFALSE;
84         Bool_t resultLaser=kFALSE;
85         Bool_t resultOnline=kFALSE;  
86
87         // processing DCS
88         
89         if(!dcsAliasMap) 
90         {
91           Log("No DCS input data");     
92           return 1;
93         }
94         else
95         { 
96           resultDCSMap=fData->ProcessData(*dcsAliasMap);
97           if(!resultDCSMap)
98           {
99             Log("Error when processing DCS data");
100             return 2;// return error Code for processed DCS data not stored
101           }
102           else
103           {
104             AliCDBMetaData metaDataDCS;
105             metaDataDCS.SetBeamPeriod(0);
106             metaDataDCS.SetResponsible("Tomasz Malkiewicz");
107             metaDataDCS.SetComment("This preprocessor fills an AliTODataDCS object.");
108             AliInfo("Storing DCS Data");
109             resultDCSStore = Store("Calib","DCSData",fData, &metaDataDCS);
110             if (!resultDCSStore)
111             {
112               Log("Some problems occurred while storing DCS data results in ReferenceDB");
113               return 2;// return error Code for processed DCS data not stored
114             }
115  
116           }     
117         }
118
119         // processing DAQ
120
121         TString runType = GetRunType();
122
123         if(runType == "T0_STANDALONE_LASER") 
124         {
125           TList* list = GetFileSources(kDAQ, "LASER");
126           if (list)
127           {
128             TIter iter(list);
129             TObjString *source;
130             while ((source = dynamic_cast<TObjString *> (iter.Next())))
131             {
132               const char *laserFile = GetFile(kDAQ, "LASER", source->GetName());
133               if (laserFile)
134               {
135                 Log(Form("File with Id TIME found in source %s!", source->GetName()));
136                 AliT0CalibWalk *laser = new AliT0CalibWalk();
137                 // laser->Reset();
138                 laser->MakeWalkCorrGraph(laserFile);
139                 AliCDBMetaData metaData;
140                 metaData.SetBeamPeriod(0);
141                 metaData.SetResponsible("Tomek&Michal");
142                 metaData.SetComment("Walk correction from laser runs.");
143                 resultLaser = Store("Calib","Data", laser, &metaData);
144                 delete laser;
145               } 
146               else
147               {
148                 Log(Form("Could not find file with Id TIME in source %s!", source->GetName()));
149                 return 1;
150               }
151             }
152             if (!resultLaser)
153             {
154               Log("No Laser Data stored");
155               return 3;//return error code for failure in storing Laser Data
156             }
157           }     
158         } 
159         else if(runType == "PHYSICS") 
160         {
161             AliT0CalibTimeEq *online = new AliT0CalibTimeEq();
162             online->Reset();
163             online->ComputeOnlineParams("CFD13-CFD","", "c1", 20, 1.);
164             AliCDBMetaData metaData;
165             metaData.SetBeamPeriod(0);
166             metaData.SetResponsible("Tomek&Michal");
167             metaData.SetComment("Time equalizing result.");
168
169             resultOnline = Store("Calib","Data", online, &metaData);
170             delete online;
171             if (!resultOnline)
172             {
173               Log("No Laser Data stored");
174               return 4;//return error code for failure in storing OCDB Data
175             }
176         
177         }
178        
179
180 /* commented for testing, TM 22.11.2007
181           
182         while ((source = dynamic_cast<TObjString *> (iter.Next()))) 
183           {
184             const char* TimefileName = GetFile(kDAQ, "TIME", source->GetName());
185             if (TimefileName)
186             {
187               Log(Form("File with Id TIME found in source %s!", source->GetName()));
188               TFile *file = TFile::Open(TimefileName);
189               if(!file || !file->IsOpen()) 
190               {
191                 Log(Form("Error opening file with Id TIME from source %s!", source->GetName()));
192                 return 1;
193               } 
194               AliT0Dqclass *tempdata = dynamic_cast<AliT0Dqclass*> (file->Get("Time"));
195               if (!tempdata) 
196               {
197                 Log("Could not find key \"Time\" in DAQ file!");
198                 return 1;
199               }
200               for(Int_t i=0;i<24;i++)
201               {
202                 numbers[i] = tempdata->GetTime(i);
203                                         //      printf("\nnumbers: %f\n",numbers[i]);
204               }
205               file->Close();
206               delete tempdata;
207             } 
208             else 
209             {
210               Log(Form("Could not find file with Id TIME in source %s!", source->GetName()));
211               return 1;
212             }
213         //              calibdata->SetTime(numbers, hv);
214         //              calibdata->Print();
215         //              calibdata->FitGauss();
216           } 
217         } 
218         else 
219         {
220           Log("No sources for Id TIME found!");
221         }        
222
223 */
224
225   return 0;
226 }
227
228