]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/AliTOFPreprocessorFDR.cxx
Log used, fData member removed
[u/mrichter/AliRoot.git] / TOF / AliTOFPreprocessorFDR.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 Revision 1.1  2007/11/24 18:36:27  zampolli
19 TOF Preprocessor for FDR
20
21 */
22
23 #include <Riostream.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26
27 #include <TFile.h>
28 #include <TH1.h>
29 #include <TMath.h>
30 #include <TObjArray.h>
31 #include <TObjString.h>
32 #include <TTimeStamp.h>
33
34 #include "AliCDBMetaData.h"
35 #include "AliLog.h"
36 #include "AliTOFDataDCS.h"
37 #include "AliTOFGeometry.h"
38 #include "AliTOFPreprocessorFDR.h"
39 #include "AliTOFFormatDCS.h"
40 #include "AliDCSValue.h"
41
42 // TOF preprocessor class.
43 // It takes data from DCS and passes them to the class AliTOFDataDCS, which
44 // processes them. The result is then written to the CDB.
45 // analogously, it takes data form DAQ (both at Run level and inclusive - 
46 // of all the runs - level, processes them, and stores both Reference Data
47 // and Online Calibration files in the CDB. 
48
49
50 ClassImp(AliTOFPreprocessorFDR)
51
52 //_____________________________________________________________________________
53
54 AliTOFPreprocessorFDR::AliTOFPreprocessorFDR(AliShuttleInterface* shuttle) :
55   AliPreprocessor("TOF", shuttle),
56   fStoreRefData(kTRUE)
57 {
58   // constructor
59
60 }
61
62 //_____________________________________________________________________________
63
64 AliTOFPreprocessorFDR::~AliTOFPreprocessorFDR()
65 {
66   // destructor
67 }
68
69 //______________________________________________________________________________
70 void AliTOFPreprocessorFDR::Initialize(Int_t run, UInt_t startTime,
71         UInt_t endTime)
72 {
73   // Creates AliTOFDataDCS object
74
75   AliPreprocessor::Initialize(run, startTime, endTime);
76
77         Log(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
78                 TTimeStamp(startTime).AsString(),
79                 TTimeStamp(endTime).AsString()));
80
81 }
82
83 //_____________________________________________________________________________
84
85 UInt_t AliTOFPreprocessorFDR::ProcessDCSDataPoints(TMap* aliasMap)
86 {
87   // Fills data into a AliTOFDataDCS object
88   // return codes:
89   // return=0 : all ok
90   // return=1 : no DCS input data Map
91   // return=2 : no DCS processed data was stored in Ref Data
92   // return=3 : no DCS processed data was stored in OCDB
93
94   if (!aliasMap){
95     Log("No DCS map found: TOF exiting from Shuttle");
96     return 1;// return error Code for DCS input data not found 
97   }
98
99   else {
100
101     AliDCSValue* aValue;
102     AliDCSValue* aValue1;
103     Float_t timeMin = (Float_t)fStartTime;
104     Float_t timeMax = (Float_t)fEndTime;
105     Float_t val=0;
106     Float_t val1=0;
107     Float_t time=0; 
108     Float_t delta[2];
109     Float_t timedelta[2];
110
111     TH1::AddDirectory(0);
112     
113     Bool_t resultDCSMap=kFALSE;
114     Bool_t resultDCSStore=kFALSE;
115     
116     TString aliasDP[4]={"tof_lv_i48_02","tof_lv_v48_02","tof_lv_i33_02","tof_lv_v33_02"};
117     
118     TObjArray *array = new TObjArray(4);
119     array->SetOwner();
120
121     AliTOFFormatDCS *lv_i48_02 = new AliTOFFormatDCS();
122     AliTOFFormatDCS *lv_v48_02 = new AliTOFFormatDCS();
123     AliTOFFormatDCS *lv_i33_02 = new AliTOFFormatDCS();
124     AliTOFFormatDCS *lv_v33_02 = new AliTOFFormatDCS();
125     
126     array->AddAt(lv_i48_02,0);
127     array->AddAt(lv_v48_02,1);
128     array->AddAt(lv_i33_02,2);
129     array->AddAt(lv_v33_02,3);
130
131     // processing DCS
132     
133     for (Int_t i=0;i<4;i++){
134       TObjArray *aliasArr = (TObjArray*) aliasMap->GetValue(aliasDP[i].Data());
135       
136       if(!aliasArr){
137         Log(Form("Alias %s not found!", aliasDP[i].Data()));
138         return kFALSE;
139       }
140       
141       if(aliasArr->GetEntries()<3){
142         Log(Form("Alias %s has just %d entries!",
143                       aliasDP[i].Data(),aliasArr->GetEntries()));
144         continue;
145       }
146       
147       TIter iterarray(aliasArr);
148       
149       Int_t nentries = aliasArr->GetEntries();
150       Int_t deltaTimeStamp = (Int_t) nentries/3;
151       Int_t deltaTimeStamp1 = (Int_t) nentries/2;
152       
153       // filling aliases with 10 floats+1 Usign
154       Int_t index = 0;
155       for (Int_t k=0;k<3;k++){
156         index = deltaTimeStamp*k;
157         if (k==0) {
158           index=0;
159         }
160         else if (k==1) {
161           index=deltaTimeStamp1;
162         } 
163         else if (k==2) {
164           index=nentries-1; 
165         }
166         aValue = (AliDCSValue*) aliasArr->At(index);
167         val = aValue->GetFloat();
168         time = (Float_t) (aValue->GetTimeStamp());
169         if (i==0){
170           AliDebug(1,Form("tof_lv_i48: setting value %i to %f at %f",k,val,time));
171           lv_i48_02->SetFloat(k,val);
172           lv_i48_02->SetTimeStampFloat(k,time);
173         }
174         else if (i==1){
175           AliDebug(1,Form("tof_lv_v48: setting value %i to %f at %f",k,val,time));
176           lv_v48_02->SetFloat(k,val);
177           lv_v48_02->SetTimeStampFloat(k,time);
178         }
179         else if (i==2){
180           AliDebug(1,Form("tof_lv_i33: setting value %i to %f at %f",k,val,time));
181           lv_i33_02->SetFloat(k,val);
182           lv_i33_02->SetTimeStampFloat(k,time);
183         }
184         else if (i==3){
185           AliDebug(1,Form("tof_lv_v33: setting value %i to %f at %f",k,val,time));
186           lv_v33_02->SetFloat(k,val);
187           lv_v33_02->SetTimeStampFloat(k,time);
188         }
189       }
190   
191       // computing the most significant variations
192       
193       Int_t deltamin = (Int_t)(60/(timeMax-timeMin)*nentries);
194       Int_t klast = nentries-deltamin;
195       
196       for (Int_t k=0;k<klast;k++){
197         aValue = (AliDCSValue*) aliasArr->At(k);
198         aValue1 = (AliDCSValue*) aliasArr->At(k+deltamin);
199         val = aValue->GetFloat();
200         val1 = aValue1->GetFloat();
201         if (delta[0]<=TMath::Abs(val1-val)) {
202           delta[0]=TMath::Abs(val1-val);
203           timedelta[0] = (Float_t)k;
204         }
205         if (delta[1]<=delta[0]) {
206           Float_t temp = delta[1];
207           Float_t timetemp = timedelta[1];
208           delta[1]=delta[0];
209           delta[0]=temp;
210           timedelta[1]=timedelta[0];
211           timedelta[0]=timetemp;
212         }
213       }
214       
215       for (Int_t kk=0;kk<2;kk++){
216         if (i==0){
217           AliDebug(1,Form("tof_lv_i48: setting variation %i to %f at %f",kk,delta[kk],timedelta[kk]));
218           lv_i48_02->SetDelta(kk,delta[kk]);
219           lv_i48_02->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
220         }
221         else if (i==1){
222           AliDebug(1,Form("tof_lv_v48: setting variation %i to %f at %f",kk,delta[kk],timedelta[kk]));
223           lv_v48_02->SetDelta(kk,delta[kk]);
224           lv_v48_02->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
225         }
226         else if (i==2){
227           AliDebug(1,Form("tof_lv_i33: setting variation %i to %f at %f",kk,delta[kk],timedelta[kk]));
228           lv_i33_02->SetDelta(kk,delta[kk]);
229           lv_i33_02->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
230         }
231         else if (i==3){
232           AliDebug(1,Form("tof_lv_v33: setting variation %i to %f at %f",kk,delta[kk],timedelta[kk]));
233           lv_v33_02->SetDelta(kk,delta[kk]);
234           lv_v33_02->SetTimeStampDelta(kk,(Float_t)timedelta[kk]);
235         }
236       }
237     }
238
239     AliCDBMetaData metaDataDCS;
240     metaDataDCS.SetBeamPeriod(0);
241     metaDataDCS.SetResponsible("Chiara Zampolli");
242     metaDataDCS.SetComment("This preprocessor fills an AliTOFDataDCS object.");
243     Log("Storing DCS Data");
244     resultDCSStore = StoreReferenceData("Calib","DCSData",array, &metaDataDCS);
245     if (!resultDCSStore){
246       Log("Some problems occurred while storing DCS data results in Reference Data, TOF exiting from Shuttle");
247       return 2;// return error Code for processed DCS data not stored 
248       // in reference data
249     }
250     
251     Log("Storing DCS Data in OCDB");
252     resultDCSMap = Store("Calib","DCSData",array, &metaDataDCS);
253     if (!resultDCSStore){
254       Log("Some problems occurred while storing DCS data results in OCDB, TOF exiting from Shuttle");
255       return 3;// return error Code for processed DCS data not stored 
256       // in reference data
257     }
258     
259     if (array) delete array;
260     return 0;
261
262   }
263
264 }
265 //_____________________________________________________________________________
266
267 UInt_t AliTOFPreprocessorFDR::Process(TMap* dcsAliasMap)
268 {
269   // Fills data into a AliTOFDataDCS object
270   // return codes:
271   // return=0  : all ok
272   // return=1  : no DCS input data Map
273   // return=2  : no DCS processed data was stored in Ref Data
274   // return=3  : no DCS processed data was stored in OCDB
275
276   TH1::AddDirectory(0);
277
278   // processing 
279
280   Int_t iresultDCS = ProcessDCSDataPoints(dcsAliasMap);
281   if ((iresultDCS == 1) || (iresultDCS == 2) || (iresultDCS == 3)) return iresultDCS; 
282   
283   return 0;
284 }
285
286