]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDPreprocessor.cxx
12ea0ff231750bd8d5ff21569c98dcda7ae1e1d1
[u/mrichter/AliRoot.git] / PMD / AliPMDPreprocessor.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 //  Source File : AliPMDPreprocessor.cxx               //
18 //                                                     //
19 //                                                     //
20 //-----------------------------------------------------//
21
22 // --- ROOT system
23 #include <TFile.h>
24 #include <TTimeStamp.h>
25 #include <TObjString.h>
26 #include <TTree.h>
27
28 #include "AliLog.h"
29 #include "AliShuttleInterface.h"
30 #include "AliCDBMetaData.h"
31 #include "AliPMDCalibData.h"
32 #include "AliPMDHotData.h"
33 #include "AliPMDPedestal.h"
34 #include "AliPMDPreprocessor.h"
35
36
37 ClassImp(AliPMDPreprocessor)
38   
39 //______________________________________________________________________________________________
40 AliPMDPreprocessor::AliPMDPreprocessor(AliShuttleInterface* shuttle) :
41   AliPreprocessor("PMD", shuttle)
42 {
43   // constructor
44   AddRunType("PHYSICS");
45   AddRunType("PEDESTAL");
46 }
47
48 //______________________________________________________________________________________________
49 AliPMDPreprocessor::~AliPMDPreprocessor()
50 {
51   // destructor
52 }
53
54 //______________________________________________________________________________________________
55 void AliPMDPreprocessor::Initialize(Int_t run, UInt_t startTime,
56         UInt_t endTime)
57 {
58   // Creates AliPMDDataDAQ object
59
60   AliPreprocessor::Initialize(run, startTime, endTime);
61   
62   AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
63                TTimeStamp(startTime).AsString(),
64                TTimeStamp(endTime).AsString()));
65
66   fRun = run;
67   fStartTime = startTime;
68   fEndTime = endTime;
69
70 }
71
72 //-----------------------------------------
73 Bool_t AliPMDPreprocessor::ProcessDAQ()
74 {
75   TString RunType = GetRunType();
76   Log(Form("RunType %s",RunType.Data()));
77   if (RunType !="PHYSICS" || RunType != "PEDESTAL") {
78     return kFALSE;
79   }
80
81   return kTRUE;
82 }
83
84
85 //_____________________________________________________________________
86 UInt_t AliPMDPreprocessor::Process(TMap* pdaqAliasMap)
87 {
88   
89   if(!pdaqAliasMap) return 1;
90   TString runType = GetRunType();
91   if(runType == "PEDESTAL"){
92     AliPMDPedestal *pedestal = new AliPMDPedestal();
93     
94     TList* filesources = GetFileSources(kDAQ, "PMD_PED.root");
95     
96     if(!filesources) {
97       Log(Form("No sources found for PMD_PED.root!"));
98       return 1;
99     }
100     
101     AliInfo("Here's the list of sources for PMD_PED.root");
102     filesources->Print();
103     
104     TIter iter(filesources);
105     TObjString* source;
106     UInt_t result = 0;
107     TString filename;
108     while((source=dynamic_cast<TObjString*> (iter.Next()))){
109       filename = GetFile(kDAQ, "PMD_PED.root", source->GetName());
110       if(filename.Length() == 0) {
111         Log(Form("Error retrieving file from source %s failed!", source->GetName()));
112         delete filesources;
113         return 1;
114       }
115       
116       Log(Form("File with id PMD_PED.root got from %s", source->GetName()));
117       
118       Int_t det, sm, row, col;
119       Float_t mean, rms;
120       
121       TFile *f= new TFile(filename.Data());
122       if(!f || !f->IsOpen()) 
123         {
124           Log(Form("Error opening file with Id PMD_PED.root from source %s!", source->GetName()));
125           return 1;
126         } 
127       TTree *tree = dynamic_cast<TTree *> (f->Get("ped"));
128       if (!tree) 
129         {
130           Log("Could not find object \"ped\" in PED file!");
131           return 1;
132         }
133             
134       tree->SetBranchAddress("det",  &det);
135       tree->SetBranchAddress("sm",   &sm);
136       tree->SetBranchAddress("row",  &row);
137       tree->SetBranchAddress("col",  &col);
138       tree->SetBranchAddress("mean", &mean);
139       tree->SetBranchAddress("rms",  &rms);
140       
141       Int_t nEntries = (Int_t) tree->GetEntries();
142       for(Int_t i = 0; i < nEntries; i++)
143         {
144           tree->GetEntry(i);
145           pedestal->SetPedMeanRms(det,sm,row,col,mean,rms);
146         }
147       f->Close();
148       delete f;
149     }
150     AliCDBMetaData metaData;
151     metaData.SetBeamPeriod(0);
152     metaData.SetComment("test PMD preprocessor");
153     
154     result = Store("Calib","Ped", pedestal, &metaData,0,kTRUE);
155     delete pedestal;
156     if(result==0)
157       {
158         Log("Error storing");                        
159         return 1;
160       }
161     else
162       {
163         return 0;
164       }
165     
166   }else if (runType == "PHYSICS"){
167     
168     AliPMDCalibData *calibda = new AliPMDCalibData();
169     
170     TList* filesources = GetFileSources(kDAQ, "PMDGAINS.root");
171     
172     if(!filesources) {
173       Log(Form("No sources found for PMDGAINS.root!"));
174       return 1;
175     }
176     
177     AliInfo("Here's the list of sources for PMDGAINS.root");
178     filesources->Print();
179     
180     TIter iter(filesources);
181     TObjString* source;
182     UInt_t result = 0;
183     TString filename;
184     while((source=dynamic_cast<TObjString*> (iter.Next()))){
185       filename = GetFile(kDAQ, "PMDGAINS.root", source->GetName());
186       if(filename.Length() == 0) {
187         Log(Form("Error retrieving file from source %s failed!", source->GetName()));
188         delete filesources;
189         return 1;
190       }
191       
192       Log(Form("File with id PMDGAINS.root got from %s", source->GetName()));
193       
194       Int_t det, sm, row, col;
195       Float_t gain;
196
197       TFile *f1= new TFile(filename.Data());
198       if(!f1 || !f1->IsOpen()) 
199         {
200           Log(Form("Error opening file with Id PMDGAINS.root from source %s!", source->GetName()));
201           return 1;
202         } 
203       TTree *tree = dynamic_cast<TTree *> (f1->Get("ic"));
204       if (!tree) 
205         {
206           Log("Could not find object \"ic\" in DAQ file!");
207           return 1;
208         }
209       
210       tree->SetBranchAddress("det",  &det);
211       tree->SetBranchAddress("sm",   &sm);
212       tree->SetBranchAddress("row",  &row);
213       tree->SetBranchAddress("col",  &col);
214       tree->SetBranchAddress("gain", &gain);
215       
216
217       
218       Int_t nEntries = (Int_t) tree->GetEntries();
219       for(Int_t i = 0; i < nEntries; i++)
220         {
221           tree->GetEntry(i);
222           
223           //if(DET>1 || SM>23 || ROW>95 || COL>95) {
224           //  printf("Error! gain[%d,%d,%d,%d] = %f\n",
225           //   DET,SM,ROW,COL,GAIN);
226           //  continue;
227           //}
228           
229           calibda->SetGainFact(det,sm,row,col,gain);
230         }
231       f1->Close();
232       delete f1;
233     }
234     AliCDBMetaData metaData;
235     metaData.SetBeamPeriod(0);
236     metaData.SetComment("test PMD preprocessor");
237     result = Store("Calib","Gain", calibda, &metaData);
238     delete calibda;
239     if(result==0)
240       {
241         Log("Error storing");                        
242         return 1;
243       }
244     //----------------------------------------------------
245     AliPMDHotData *hotda = new AliPMDHotData();
246     TList* filesource = GetFileSources(kDAQ, "PMD_HOT.root");
247         
248     if(!filesource) {
249       Log(Form("No sources found for PMD_HOT.root!"));
250       return 1;
251     }
252     
253     AliInfo("Here's the list of sources for PMD_HOT.root");
254     filesource->Print();
255     
256     TIter iter2(filesource);
257     TObjString* sources;
258     UInt_t hotresult = 0;
259     TString filenames;
260     while((sources=dynamic_cast<TObjString*> (iter2.Next()))){
261       filenames = GetFile(kDAQ, "PMD_HOT.root", sources->GetName());
262       if(filenames.Length() == 0) {
263         Log(Form("Error retrieving file from source %s failed!", sources->GetName()));
264         delete filesource;
265         return 1;
266       }
267       
268       Log(Form("File with id PMD_HOT.root got from %s", sources->GetName()));
269       
270       Int_t det, sm, row, col;
271       Float_t flag;
272       
273       TFile *f2= new TFile(filenames.Data());
274       if(!f2 || !f2->IsOpen()) 
275         {
276           Log(Form("Error opening file with Id PMD_HOT.root from source %s!", sources->GetName()));
277           return 1;
278         } 
279       TTree *tree1 = dynamic_cast<TTree *> (f2->Get("hot"));
280       if (!tree1) 
281         {
282           Log("Could not find object \"hot\" in DAQ file!");
283           return 1;
284         }
285       
286       tree1->SetBranchAddress("det",  &det);
287       tree1->SetBranchAddress("sm",   &sm);
288       tree1->SetBranchAddress("row",  &row);
289       tree1->SetBranchAddress("col",  &col);
290       tree1->SetBranchAddress("flag", &flag);
291       
292       
293       
294       Int_t nEntries = (Int_t) tree1->GetEntries();
295       for(Int_t j = 0; j < nEntries; j++)
296         {
297           tree1->GetEntry(j);
298           
299           //if(det>1 || sm>23 || row>95 || col>95) {
300           // printf("Error! gain[%d,%d,%d,%d] = %f\n",
301           // det,sm,row,col,flag);
302           //continue;
303           //}
304           
305           hotda->SetHotChannel(det,sm,row,col,flag);
306         }
307       f2->Close();
308       delete f2;
309     }
310     hotresult = Store("Calib","Hot", hotda, &metaData);
311     delete hotda;
312     if(hotresult==0)
313       {
314         Log("Error storing");                        
315         return 1;
316       }
317     //-------------------------------------------------------------------  
318
319         
320     // Store DCS data for reference
321     AliCDBMetaData metadata;
322     metadata.SetComment("DCS data for PMD");
323     Bool_t resStore = kFALSE;
324     resStore = StoreReferenceData("DCS","Data",pdaqAliasMap,&metadata);
325     if(resStore==0)
326       {
327         Log("Error storing");                        
328         return 1;
329       }
330     else
331       {
332         return 0;
333       }
334     
335   }
336     
337   return 2;
338 }
339
340