Fixes in order to write correct raw-data on big-endian platforms (Marco)
[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 1;
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 1;
62         }
63
64         AliInfo("Here's the list of sources for PMDGAINS");
65         filesources->Print();
66
67         TIter iter(filesources);
68         TObjString* source;
69         UInt_t result = 0;
70         TString filename;
71         while((source=dynamic_cast<TObjString*> (iter.Next()))){
72                 filename = GetFile(kDAQ, "PMDGAINS", source->GetName());
73                 if(filename.Length() == 0) {
74                         Log(Form("Error retrieving file from source %s failed!", source->GetName()));
75                         delete filesources;
76                         return 1;
77                 }
78
79                 Log(Form("File with id PMDGAINS got from %s", source->GetName()));
80                 Int_t DET,SM,ROW,COL;
81                 Float_t GAIN;
82                 TFile *f= new TFile(filename.Data());
83                 if(!f || !f->IsOpen()) 
84                 {
85                         Log(Form("Error opening file with Id PMDGAINS from source %s!", source->GetName()));
86                         return 1;
87                 } 
88                 TTree *tree = dynamic_cast<TTree *> (f->Get("ic"));
89                 if (!tree) 
90                 {
91                         Log("Could not find object \"ic\" in DAQ file!");
92                         return 1;
93                 }
94                 
95                 tree->SetBranchAddress("DET",       &DET);
96                 tree->SetBranchAddress("SM",        &SM);
97                 tree->SetBranchAddress("ROW",        &ROW);
98                 tree->SetBranchAddress("COL",        &COL);
99                 tree->SetBranchAddress("GAIN",   &GAIN);
100                 Int_t nEntries = (Int_t) tree->GetEntries();
101                 for(Int_t i = 0; i < nEntries; i++)
102                 {
103                         tree->GetEntry(i);
104 //                      if(DET>1 || SM>23 || ROW>95 || COL>95) {
105 //                              printf("Error! gain[%d,%d,%d,%d] = %f\n",DET,SM,ROW,COL,GAIN);
106 //                              continue;
107  //                     }
108                         calibda->SetGainFact(DET,SM,ROW,COL,GAIN);
109                 }
110                 f->Close();
111                 delete f;
112         }
113
114   //Now we have to store the final CDB file
115   AliCDBMetaData metaData;
116   metaData.SetBeamPeriod(0);
117   metaData.SetComment("test PMD preprocessor");
118
119   result = Store("Calib","Data", calibda, &metaData);
120
121  delete calibda;
122 if(result==0)
123       { Log("Error storing");                        
124         return 1;
125  }
126  else
127  {
128         return 0;
129  }
130
131 }
132