]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/AliT0Preprocessor.cxx
protection from old OCDB object
[u/mrichter/AliRoot.git] / T0 / AliT0Preprocessor.cxx
CommitLineData
bc943889 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/*
50e28e1c 17$Log: AliT0Preprocessor.cxx,v $
18Revision 1.8 2007/12/07 15:22:51 alla
19bug fixed by Alberto
271b5bd3 20
67b67126 21Revision 1.7 2007/12/06 16:35:24 alla
22new bugs fixed by Tomek
23
02cf5377 24Revision 1.5 2007/11/23 19:28:52 alla
25bug fixed
26
bc943889 27Version 2.1 2007/11/21
28Preprocessor storing data to OCDB (T.Malkiewicz)
29
30Version 1.1 2006/10
31Preliminary test version (T.Malkiewicz)
32*/
387638f7 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
bc943889 39
dc7ca31d 40#include "AliT0Preprocessor.h"
bc943889 41#include "AliT0DataDCS.h"
42#include "AliT0CalibWalk.h"
43#include "AliT0CalibTimeEq.h"
dc7ca31d 44
45#include "AliCDBMetaData.h"
46#include "AliDCSValue.h"
8f1790c4 47#include "AliCDBEntry.h"
dc7ca31d 48#include "AliLog.h"
dc7ca31d 49
50#include <TTimeStamp.h>
51#include <TFile.h>
5221c818 52#include <TObjString.h>
dc7ca31d 53#include <TNamed.h>
54#include "AliT0Dqclass.h"
6a9d154f 55#include "TClass.h"
dc7ca31d 56
43c247cf 57#include "iostream"
8f1790c4 58
bc943889 59
dc7ca31d 60ClassImp(AliT0Preprocessor)
61
62//____________________________________________________
387638f7 63AliT0Preprocessor::AliT0Preprocessor(AliShuttleInterface* shuttle) :
64 AliPreprocessor("T00", shuttle),
65 fData(0)
dc7ca31d 66{
bc943889 67 //constructor
2a8e3409 68 AddRunType("PHYSICS");
69 AddRunType("STANDALONE");
79e2e9c6 70 AddRunType("LASER");
dc7ca31d 71}
bc943889 72//____________________________________________________
dc7ca31d 73
74AliT0Preprocessor::~AliT0Preprocessor()
75{
50e28e1c 76 //destructor
bc943889 77 delete fData;
78 fData = 0;
79}
80//____________________________________________________
dc7ca31d 81
bc943889 82void AliT0Preprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
83{
50e28e1c 84 // Creates AliT0DataDCS object
bc943889 85 AliPreprocessor::Initialize(run, startTime, endTime);
86 AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run, TTimeStamp(startTime).AsString(), TTimeStamp(endTime).AsString()));
8eb4ac75 87 fData = new AliT0DataDCS(fRun, fStartTime, fEndTime, GetStartTimeDCSQuery(), GetEndTimeDCSQuery());
dc7ca31d 88}
bc943889 89//____________________________________________________
dc7ca31d 90
49ab1618 91Bool_t AliT0Preprocessor::ProcessDCS(){
92 // Check whether DCS should be processed or not...
93 TString runType = GetRunType();
94 Log(Form("ProcessDCS - RunType: %s",runType.Data()));
95
4b5d6a0a 96 if((runType == "STANDALONE")||
97 (runType == "PHYSICS")||
98 (runType == "LASER")){
8f1790c4 99 return kFALSE;
100 // return kTRUE;
49ab1618 101 }else{
102 return kFALSE;
103 }
104}
105//____________________________________________________
bc943889 106
49ab1618 107UInt_t AliT0Preprocessor::ProcessDCSDataPoints(TMap* dcsAliasMap){
108 // Fills data into AliT0DataDCS object
109 Log("Processing DCS DP");
bc943889 110 Bool_t resultDCSMap=kFALSE;
111 Bool_t resultDCSStore=kFALSE;
49ab1618 112
8bfd9a3e 113 if(!dcsAliasMap)
114 {
115 Log("No DCS input data");
49ab1618 116 return 1;
8bfd9a3e 117 }
118 else
119 {
120 resultDCSMap=fData->ProcessData(*dcsAliasMap);
121 if(!resultDCSMap)
122 {
123 Log("Error when processing DCS data");
bc943889 124 return 2;// return error Code for processed DCS data not stored
125 }
126 else
127 {
128 AliCDBMetaData metaDataDCS;
129 metaDataDCS.SetBeamPeriod(0);
130 metaDataDCS.SetResponsible("Tomasz Malkiewicz");
131 metaDataDCS.SetComment("This preprocessor fills an AliTODataDCS object.");
132 AliInfo("Storing DCS Data");
fe3c9b71 133 resultDCSStore = StoreReferenceData("Calib","DCSData",fData, &metaDataDCS);
bc943889 134 if (!resultDCSStore)
8bfd9a3e 135 {
bc943889 136 Log("Some problems occurred while storing DCS data results in ReferenceDB");
387638f7 137 return 2;// return error Code for processed DCS data not stored
bc943889 138 }
8bfd9a3e 139 }
140 }
49ab1618 141 return 0;
142}
143//____________________________________________________
8bfd9a3e 144
49ab1618 145UInt_t AliT0Preprocessor::ProcessLaser(){
146 // Processing data from DAQ Standalone run
8f1790c4 147 Log("Processing Laser calibration - Walk Correction");
148
149 //Retrieve the last T0 calibration object
150
151 Float_t parqtcold[24][2], parledold[24][2],parqtcnew[24][2], parlednew[24][2] , goodled[24][2], goodqtc[24][2];
152
6a9d154f 153 // std::cout<<"sizeof "<<sizeof(parqtcold)<<std::endl;
154 memset(parqtcold, 0, sizeof(parqtcold));
155 memset(parqtcnew, 0, sizeof(parqtcnew));
156 memset(parledold, 0, sizeof(parledold));
157 memset(parlednew, 0, sizeof(parlednew));
158 Int_t iStore=0;
159 Bool_t clbold = true;
8f1790c4 160
161 AliT0CalibWalk* clb=0;
162 AliCDBEntry* entryCalib = GetFromOCDB("Calib", "Slewing_Walk");
163 if(!entryCalib)
164 Log(Form("Cannot find any AliCDBEntry for [Calib, SlewingWalk]!"));
165 else {
6a9d154f 166 clb =dynamic_cast<AliT0CalibWalk*>(entryCalib->GetObject());
167 if(entryCalib->GetObject()->Class()->GetClassVersion() >3)
8f1790c4 168 {
6a9d154f 169 // std::cout<<" clb->Class()->GetClassVersion() < 4 "<<entryCalib->GetObject()->Class()->GetClassVersion()<<std::endl;
170 clbold=false;
171 for(Int_t i=0; i<24; i++)
8f1790c4 172 {
6a9d154f 173 for(Int_t ipar=0; ipar<2; ipar++)
174 {
175 // std::cout<<"parqtcold "<<parqtcold[i][ipar]<<std::endl;
176 parqtcold[i][ipar] = clb->GetQTCpar(i,ipar);
177 parledold[i][ipar] = clb->GetLEDpar(i, ipar);
178 goodqtc[i][ipar] = 999;
179 goodled[i][ipar] = 999;
180 // cout<<" old "<<i<<" "<<ipar<<" qtc "<< parqtcold[i][ipar]<<" led "<<parledold[i][ipar]<<endl;
181 }
8f1790c4 182 }
183 }
6a9d154f 184 } // object in existing OCDB
185
186 Bool_t resultLaser=kFALSE;
187 //processing DAQ
188 TList* list = GetFileSources(kDAQ, "LASER");
189 if (list)
190 {
191 TIter iter(list);
192 TObjString *source;
193 while ((source = dynamic_cast<TObjString *> (iter.Next())))
194 {
195 const char *laserFile = GetFile(kDAQ, "LASER", source->GetName());
196 if (laserFile)
bc943889 197 {
02cf5377 198 Log(Form("File with Id LASER found in source %s!", source->GetName()));
8bfd9a3e 199 AliT0CalibWalk *laser = new AliT0CalibWalk();
8bfd9a3e 200 laser->MakeWalkCorrGraph(laserFile);
8f1790c4 201 //check difference with what was before
6a9d154f 202 if(laser && clb && !clbold){
203 iStore = 1;
8f1790c4 204 for(Int_t i=0; i<24; i++)
205 {
206 for(Int_t ifit=0; ifit<2; ifit++)
207 {
208 parqtcnew[i][ifit] = laser->GetQTCpar(i,ifit);
209 if( parqtcold[i][ifit] != 0 && parqtcnew[i][ifit] !=0)
210 {
211 goodqtc[i][ifit] =
212 (parqtcnew[i][ifit] - parqtcold[i][ifit])/parqtcold[i][ifit];
213 // cout<<"qtc "<<i<<" "<<ifit<<" "<< goodqtc[i][ifit]<<endl;
214 }
215 parlednew[i][ifit] = laser->GetLEDpar(i,ifit);
6a9d154f 216 if(parledold[i][ifit] != 0 && parlednew[i][ifit]!= 0 )
8f1790c4 217 {
218 goodled[i][ifit]=
219 (parlednew[i][ifit] - parledold[i][ifit])/parledold[i][ifit];
220 // cout<<"led "<<i<<" "<<ifit<<" "<< goodled[i][ifit]<<endl;
221 }
222 if(TMath::Abs(goodqtc[i][ifit])>0.1 ||
223 TMath::Abs(goodled[i][ifit])>0.1)
224 iStore = 0;
225 }
226 }
227 }
6a9d154f 228
8f1790c4 229 AliCDBMetaData metaData;
230 metaData.SetBeamPeriod(0);
bc943889 231 metaData.SetResponsible("Tomek&Michal");
232 metaData.SetComment("Walk correction from laser runs.");
8f1790c4 233 if( iStore>0)
234 resultLaser=Store("Calib","Slewing_Walk", laser, &metaData, 0, 1);
bc943889 235 delete laser;
271b5bd3 236 Log(Form("resultLaser = %d",resultLaser));
8bfd9a3e 237 }
bc943889 238 else
239 {
8bfd9a3e 240 Log(Form("Could not find file with Id LASER in source %s!", source->GetName()));
bc943889 241 return 1;
242 }
243 }
244 if (!resultLaser)
8bfd9a3e 245 {
bc943889 246 Log("No Laser Data stored");
247 return 3;//return error code for failure in storing Laser Data
248 }
67b67126 249 } else {
250 Log("No sources found for id LASER!");
251 return 1;
252 }
49ab1618 253 return 0;
254}
255//____________________________________________________
256
257UInt_t AliT0Preprocessor::ProcessPhysics(){
258 //Processing data from DAQ Physics run
259 Log("Processing Physics");
260
271b5bd3 261 Bool_t resultOnline=kFALSE;
49ab1618 262 //processing DAQ
263 TList* listPhys = GetFileSources(kDAQ, "PHYSICS");
264 if (listPhys)
8bfd9a3e 265 {
266 TIter iter(listPhys);
267 TObjString *sourcePhys;
268 while ((sourcePhys = dynamic_cast<TObjString *> (iter.Next())))
269 {
270 const char *filePhys = GetFile(kDAQ, "PHYSICS", sourcePhys->GetName());
271 if (filePhys)
272 {
273 AliT0CalibTimeEq *online = new AliT0CalibTimeEq();
274 online->Reset();
387638f7 275 online->ComputeOnlineParams(filePhys);
8bfd9a3e 276 AliCDBMetaData metaData;
277 metaData.SetBeamPeriod(0);
278 metaData.SetResponsible("Tomek&Michal");
279 metaData.SetComment("Time equalizing result.");
02cf5377 280 resultOnline = Store("Calib","TimeDelay", online, &metaData, 0, 1);
271b5bd3 281 Log(Form("resultOnline = %d",resultOnline));
8bfd9a3e 282 delete online;
283 }
271b5bd3 284 else
8bfd9a3e 285 {
286 Log(Form("Could not find file with Id PHYSICS in source %s!", sourcePhys->GetName()));
287 return 1;
288 }
271b5bd3 289
8bfd9a3e 290 }
291 if (!resultOnline)
bc943889 292 {
271b5bd3 293 Log("No Data stored");
bc943889 294 return 4;//return error code for failure in storing OCDB Data
295 }
67b67126 296 } else {
297 Log("No sources found for id PHYSICS!");
298 return 1;
299 }
49ab1618 300 return 0;
301}
302//____________________________________________________
303
271b5bd3 304UInt_t AliT0Preprocessor::ProcessCosmic(){
305 //Processing data from DAQ Physics run
306 Log("Processing Laser Physics");
307
308 Bool_t resultLaserOnline=kFALSE;
309 //processing DAQ
310 TList* listLaser = GetFileSources(kDAQ, "COSMIC");
311 if (listLaser)
312 {
313 TIter iter(listLaser);
314 TObjString *sourceLaser;
315 while ((sourceLaser = dynamic_cast<TObjString *> (iter.Next())))
316 {
317 const char *fileLaser = GetFile(kDAQ, "COSMIC", sourceLaser->GetName());
318 if (fileLaser)
319 {
320 AliT0CalibTimeEq *onlineLaser = new AliT0CalibTimeEq();
321 onlineLaser->Reset();
322 onlineLaser->ComputeOnlineParams(fileLaser);
323 AliCDBMetaData metaData;
324 metaData.SetBeamPeriod(0);
325 metaData.SetResponsible("Tomek&Michal");
326 metaData.SetComment("Time equalizing result.");
327 resultLaserOnline = Store("Calib","LaserTimeDelay", onlineLaser, &metaData, 0, 1);
328 Log(Form("resultLaserOnline = %d",resultLaserOnline));
329 delete onlineLaser;
330 }
331 else
332 {
333 Log(Form("Could not find file with Id COSMIC in source %s!", sourceLaser->GetName()));
334 return 0;
335 }
336
337 }
338 if (!resultLaserOnline)
339 {
340 Log("No Laser Data stored");
341 return 0;//return error code for failure in storing OCDB Data
342 }
343 } else {
344 Log("No sources found for id COSMIC!");
345 return 0;
346 }
347 return 0;
348}
349//____________________________________________________
350
49ab1618 351UInt_t AliT0Preprocessor::Process(TMap* dcsAliasMap )
352{
353 // T0 preprocessor return codes:
354 // return=0 : all ok
355 // return=1 : no DCS input data
356 // return=2 : failed to store DCS data
357 // return=3 : no Laser data (Walk correction)
358 // return=4 : failed to store OCDB time equalized data
359 // return=5 : no DAQ input for OCDB
360 // return=6 : failed to retrieve DAQ data from OCDB
361 // return=7 : failed to store T0 OCDB data
362 Bool_t dcsDP = ProcessDCS();
363 Log(Form("dcsDP = %d",dcsDP));
364 TString runType = GetRunType();
365 Log(Form("RunType: %s",runType.Data()));
366 //processing
367 if(runType == "STANDALONE"){
79e2e9c6 368 if(dcsDP==1){
369 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
370 return iresultDCS;
371 }
372 }
373 if(runType == "LASER"){
374 Int_t iresultLaser = ProcessLaser();
4b5d6a0a 375 if(dcsDP==1){
376 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
377 return iresultDCS;
378 }
79e2e9c6 379 Log(Form("iresultLaser = %d",iresultLaser));
380 return iresultLaser;
49ab1618 381 }
79e2e9c6 382 else if(runType == "PHYSICS"){
383 Int_t iresultPhysics = ProcessPhysics();
6318dd46 384 // Int_t iresultCosmic = ProcessCosmic();
79e2e9c6 385 if(dcsDP==1){
386 Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
387 return iresultDCS;
388 }
389 Log(Form("iresultPhysics = %d",iresultPhysics));
390 return iresultPhysics;
391 // Log(Form("iresultPhysics =iresultCosmic %d",iresultCosmic));
392 // return iresultCosmic;
393 }
394
395 return 0;
dc7ca31d 396}