]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PMD/AliPMDPreprocessor.cxx
Add method to return XY pattern array (Christian)
[u/mrichter/AliRoot.git] / PMD / AliPMDPreprocessor.cxx
1 // --- ROOT system
2 #include <TFile.h>
3 #include <TTimeStamp.h>
4
5 #include "AliPMDPreprocessor.h"
6 #include "AliPMDCalibData.h"
7 #include "AliLog.h"
8 #include "AliShuttleInterface.h"
9 #include "AliCDBMetaData.h"
10 #include <TTimeStamp.h>
11 #include <TObjString.h>
12 #include <TTree.h>
13 #include <TSystem.h>
14
15
16 ClassImp(AliPMDPreprocessor)
17
18 //______________________________________________________________________________________________
19 AliPMDPreprocessor::AliPMDPreprocessor(AliShuttleInterface* shuttle) :
20   AliPreprocessor("PMD", shuttle)
21 {
22   // constructor
23 }
24
25 //______________________________________________________________________________________________
26 AliPMDPreprocessor::~AliPMDPreprocessor()
27 {
28   // destructor
29 }
30
31 //______________________________________________________________________________________________
32 void AliPMDPreprocessor::Initialize(Int_t run, UInt_t startTime,
33         UInt_t endTime)
34 {
35   // Creates AliPMDDataDAQ object
36
37   AliPreprocessor::Initialize(run, startTime, endTime);
38
39         AliInfo(Form("\n\tRun %d \n\tStartTime %s \n\tEndTime %s", run,
40                 TTimeStamp(startTime).AsString(),
41                 TTimeStamp(endTime).AsString()));
42
43         fRun = run;
44         fStartTime = startTime;
45         fEndTime = endTime;
46
47 }
48
49 //______________________________________________________________________________________________
50 UInt_t AliPMDPreprocessor::Process(TMap* pdaqAliasMap)
51 {
52
53  if(!pdaqAliasMap) return 0;
54         
55         AliPMDCalibData *calibda = new AliPMDCalibData();
56
57         TList* filesources = GetFileSources(kDAQ, "PMDGAINS");
58
59         if(!filesources) {
60                 Log(Form("No sources found for PMDGAINS!"));
61                 return 0;
62         }
63
64         AliInfo("Here's the list of sources for PMDGAINS");
65         filesources->Print();
66
67         TIter iter(filesources);
68         TObjString* source;
69         int i=0;
70         UInt_t result = 0;
71         TString filename;
72         while((source=dynamic_cast<TObjString*> (iter.Next()))){
73                 filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
74                 if(filename.Length() == 0) {
75                         Log(Form("Error retrieving file from source %s failed!", source->GetName()));
76                         delete filesources;
77                         return 0;
78                 }
79
80                 Log(Form("File with id PMDGAINS got from %s", source->GetName()));
81                 Int_t DET,SM,ROW,COL;
82                 Float_t GAIN;
83                 TFile *f= new TFile(filename.Data());
84                 if(!f || !f->IsOpen()) 
85                 {
86                         Log(Form("Error opening file with Id PMDGAINS from source %s!", source->GetName()));
87                         return 0;
88                 } 
89                 TTree *tree = dynamic_cast<TTree *> (f->Get("ic"));
90                 if (!tree) 
91                 {
92                         Log("Could not find object \"ic\" in DAQ file!");
93                         return 0;
94                 }
95                 
96                 tree->SetBranchAddress("DET",       &DET);
97                 tree->SetBranchAddress("SM",        &SM);
98                 tree->SetBranchAddress("ROW",        &ROW);
99                 tree->SetBranchAddress("COL",        &COL);
100                 tree->SetBranchAddress("GAIN",   &GAIN);
101                 Int_t nEntries = (Int_t) tree->GetEntries();
102                 for(Int_t i = 0; i < nEntries; i++)
103                 {
104                         tree->GetEntry(i);
105 //                      if(DET>1 || SM>23 || ROW>95 || COL>95) {
106 //                              printf("Error! gain[%d,%d,%d,%d] = %f\n",DET,SM,ROW,COL,GAIN);
107 //                              continue;
108  //                     }
109                         calibda->SetGainFact(DET,SM,ROW,COL,GAIN);
110                 }
111                 f->Close();
112                 delete f;
113         }
114
115   //Now we have to store the final CDB file
116   AliCDBMetaData metaData;
117   metaData.SetBeamPeriod(0);
118   metaData.SetComment("test PMD preprocessor");
119
120   result = Store("Calib","Data", calibda, &metaData);
121
122  delete calibda;
123  return result;
124 }
125