]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDPreprocessor.cxx
Preprocessor with DCS
[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 "AliPMDPedestal.h"
33 #include "AliPMDPreprocessor.h"
34
35
36 ClassImp(AliPMDPreprocessor)
37   
38 //______________________________________________________________________________________________
39 AliPMDPreprocessor::AliPMDPreprocessor(AliShuttleInterface* shuttle) :
40   AliPreprocessor("PMD", shuttle)
41 {
42   // constructor
43 }
44
45 //______________________________________________________________________________________________
46 AliPMDPreprocessor::~AliPMDPreprocessor()
47 {
48   // destructor
49 }
50
51 //______________________________________________________________________________________________
52 void AliPMDPreprocessor::Initialize(Int_t run, UInt_t startTime,
53         UInt_t endTime)
54 {
55   // Creates AliPMDDataDAQ object
56
57     AliPreprocessor::Initialize(run, startTime, endTime);
58
59     AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
60                  TTimeStamp(startTime).AsString(),
61                  TTimeStamp(endTime).AsString()));
62
63     fRun = run;
64     fStartTime = startTime;
65     fEndTime = endTime;
66
67 }
68
69 //______________________________________________________________________________________________
70 UInt_t AliPMDPreprocessor::Process(TMap* pdaqAliasMap)
71 {
72     
73     if(!pdaqAliasMap) return 1;
74     TString runType = GetRunType();
75     if(runType == "PEDESTAL_RUN"){
76         AliPMDPedestal *pedestal = new AliPMDPedestal();
77         
78         TList* filesources = GetFileSources(kDAQ, "PMD_PED");
79         
80         if(!filesources) {
81             Log(Form("No sources found for PMD_PED!"));
82             return 1;
83         }
84         
85         AliInfo("Here's the list of sources for PMD_PED");
86         filesources->Print();
87         
88         TIter iter(filesources);
89         TObjString* source;
90         UInt_t result = 0;
91         TString filename;
92         while((source=dynamic_cast<TObjString*> (iter.Next()))){
93             filename = GetFile(kDAQ, "PMD_PED", source->GetName());
94             if(filename.Length() == 0) {
95                 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
96                 delete filesources;
97                 return 1;
98             }
99             
100             Log(Form("File with id PMD_PED got from %s", source->GetName()));
101
102             Int_t det, sm, row, col;
103             Float_t mean, rms;
104
105             TFile *f= new TFile(filename.Data());
106             if(!f || !f->IsOpen()) 
107             {
108                 Log(Form("Error opening file with Id PMD_PED from source %s!", source->GetName()));
109                 return 1;
110             } 
111             TTree *tree = dynamic_cast<TTree *> (f->Get("ped"));
112             if (!tree) 
113             {
114                 Log("Could not find object \"ped\" in PED file!");
115                 return 1;
116             }
117             
118             tree->SetBranchAddress("det",  &det);
119             tree->SetBranchAddress("sm",   &sm);
120             tree->SetBranchAddress("row",  &row);
121             tree->SetBranchAddress("col",  &col);
122             tree->SetBranchAddress("mean", &mean);
123             tree->SetBranchAddress("rms",  &rms);
124
125
126             Int_t nEntries = (Int_t) tree->GetEntries();
127             for(Int_t i = 0; i < nEntries; i++)
128             {
129                 tree->GetEntry(i);
130                 pedestal->SetPedMeanRms(det,sm,row,col,mean,rms);
131             }
132             f->Close();
133             delete f;
134         }
135         AliCDBMetaData metaData;
136         metaData.SetBeamPeriod(0);
137         metaData.SetComment("test PMD preprocessor");
138         
139         result = Store("Calib","Ped", pedestal, &metaData);
140         delete pedestal;
141         if(result==0)
142         {
143             Log("Error storing");                        
144             return 1;
145         }
146         else
147         {
148             return 0;
149         }
150         
151     }else if (runType == "PHYSICS"){
152         
153         AliPMDCalibData *calibda = new AliPMDCalibData();
154         
155         TList* filesources = GetFileSources(kDAQ, "PMDGAINS");
156         
157         if(!filesources) {
158             Log(Form("No sources found for PMDGAINS!"));
159             return 1;
160         }
161         
162         AliInfo("Here's the list of sources for PMDGAINS");
163         filesources->Print();
164         
165         TIter iter(filesources);
166         TObjString* source;
167         UInt_t result = 0;
168         TString filename;
169         while((source=dynamic_cast<TObjString*> (iter.Next()))){
170             filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
171             if(filename.Length() == 0) {
172                 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
173                 delete filesources;
174                 return 1;
175             }
176             
177             Log(Form("File with id PMDGAINS got from %s", source->GetName()));
178
179             Int_t det, sm, row, col;
180             Float_t gain;
181
182             TFile *f1= new TFile(filename.Data());
183             if(!f1 || !f1->IsOpen()) 
184             {
185                 Log(Form("Error opening file with Id PMDGAINS from source %s!", source->GetName()));
186                 return 1;
187             } 
188             TTree *tree = dynamic_cast<TTree *> (f1->Get("ic"));
189             if (!tree) 
190             {
191                 Log("Could not find object \"ic\" in DAQ file!");
192                 return 1;
193             }
194             
195             tree->SetBranchAddress("det",  &det);
196             tree->SetBranchAddress("sm",   &sm);
197             tree->SetBranchAddress("row",  &row);
198             tree->SetBranchAddress("col",  &col);
199             tree->SetBranchAddress("gain", &gain);
200
201             Int_t nEntries = (Int_t) tree->GetEntries();
202             for(Int_t i = 0; i < nEntries; i++)
203             {
204                 tree->GetEntry(i);
205
206                 //if(DET>1 || SM>23 || ROW>95 || COL>95) {
207                 //    printf("Error! gain[%d,%d,%d,%d] = %f\n",
208                 //   DET,SM,ROW,COL,GAIN);
209                 //  continue;
210                 //                      }
211
212                 calibda->SetGainFact(det,sm,row,col,gain);
213             }
214             f1->Close();
215             delete f1;
216         }
217
218         AliCDBMetaData metaData;
219         metaData.SetBeamPeriod(0);
220         metaData.SetComment("test PMD preprocessor");
221         result = Store("Calib","Gain", calibda, &metaData);
222         delete calibda;
223         if(result==0)
224         {
225             Log("Error storing");                        
226             return 1;
227         }
228         else
229         {
230             return 0;
231         }
232         
233   // Store DCS data for reference
234   AliCDBMetaData metadata;
235   metadata.SetComment("DCS data for PMD");
236   Bool_t resStore = kFALSE;
237   resStore = StoreReferenceData("DCS","Data",pdaqAliasMap,&metadata);
238         if(resStore==0)
239         {
240             Log("Error storing");                        
241             return 1;
242         }
243         else
244         {
245             return 0;
246         }
247
248     }
249     
250     return 2;
251 }