]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDPreprocessor.cxx
Corrected TTimeStamp<->UInt_t conversion
[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             Int_t nEntries = (Int_t) tree->GetEntries();
126             for(Int_t i = 0; i < nEntries; i++)
127             {
128                 tree->GetEntry(i);
129                 pedestal->SetPedMeanRms(det,sm,row,col,mean,rms);
130             }
131             f->Close();
132             delete f;
133         }
134         AliCDBMetaData metaData;
135         metaData.SetBeamPeriod(0);
136         metaData.SetComment("test PMD preprocessor");
137         
138         result = Store("Calib","Ped", pedestal, &metaData,0,kTRUE);
139         delete pedestal;
140         if(result==0)
141         {
142             Log("Error storing");                        
143             return 1;
144         }
145         else
146         {
147             return 0;
148         }
149         
150     }else if (runType == "PHYSICS"){
151         
152         AliPMDCalibData *calibda = new AliPMDCalibData();
153         
154         TList* filesources = GetFileSources(kDAQ, "PMDGAINS");
155         
156         if(!filesources) {
157             Log(Form("No sources found for PMDGAINS!"));
158             return 1;
159         }
160         
161         AliInfo("Here's the list of sources for PMDGAINS");
162         filesources->Print();
163         
164         TIter iter(filesources);
165         TObjString* source;
166         UInt_t result = 0;
167         TString filename;
168         while((source=dynamic_cast<TObjString*> (iter.Next()))){
169             filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
170             if(filename.Length() == 0) {
171                 Log(Form("Error retrieving file from source %s failed!", source->GetName()));
172                 delete filesources;
173                 return 1;
174             }
175             
176             Log(Form("File with id PMDGAINS got from %s", source->GetName()));
177
178             Int_t det, sm, row, col;
179             Float_t gain;
180
181             TFile *f1= new TFile(filename.Data());
182             if(!f1 || !f1->IsOpen()) 
183             {
184                 Log(Form("Error opening file with Id PMDGAINS from source %s!", source->GetName()));
185                 return 1;
186             } 
187             TTree *tree = dynamic_cast<TTree *> (f1->Get("ic"));
188             if (!tree) 
189             {
190                 Log("Could not find object \"ic\" in DAQ file!");
191                 return 1;
192             }
193             
194             tree->SetBranchAddress("det",  &det);
195             tree->SetBranchAddress("sm",   &sm);
196             tree->SetBranchAddress("row",  &row);
197             tree->SetBranchAddress("col",  &col);
198             tree->SetBranchAddress("gain", &gain);
199
200
201
202             Int_t nEntries = (Int_t) tree->GetEntries();
203             for(Int_t i = 0; i < nEntries; i++)
204             {
205                 tree->GetEntry(i);
206
207                 //if(DET>1 || SM>23 || ROW>95 || COL>95) {
208                 //  printf("Error! gain[%d,%d,%d,%d] = %f\n",
209                 //   DET,SM,ROW,COL,GAIN);
210                 //  continue;
211                 //}
212
213                 calibda->SetGainFact(det,sm,row,col,gain);
214             }
215             f1->Close();
216             delete f1;
217         }
218
219         AliCDBMetaData metaData;
220         metaData.SetBeamPeriod(0);
221         metaData.SetComment("test PMD preprocessor");
222         result = Store("Calib","Gain", calibda, &metaData);
223         delete calibda;
224         if(result==0)
225         {
226             Log("Error storing");                        
227             return 1;
228         }
229         else
230         {
231             return 0;
232         }
233         
234   // Store DCS data for reference
235   AliCDBMetaData metadata;
236   metadata.SetComment("DCS data for PMD");
237   Bool_t resStore = kFALSE;
238   resStore = StoreReferenceData("DCS","Data",pdaqAliasMap,&metadata);
239         if(resStore==0)
240         {
241             Log("Error storing");                        
242             return 1;
243         }
244         else
245         {
246             return 0;
247         }
248
249     }
250     
251     return 2;
252 }
253
254