Digits and raw data updated for commissioning
[u/mrichter/AliRoot.git] / TPC / TPCPEDESTALda.cxx
CommitLineData
c12208b8 1/*
2
3TPCda_pedestal.cxx - calibration algorithm for TPC pedestal runs
4
510/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
6
7contact: marian.ivanov@cern.ch
8
9
10This process reads RAW data from the files provided as command line arguments
11and save results in a file (named from RESULT_FILE define - see below).
12
13*/
14
15#define RESULT_FILE "tpcPedestal.root"
16
17
18extern "C" {
19#include <daqDA.h>
20}
21#include "event.h"
22#include "monitor.h"
23#include <stdio.h>
24#include <stdlib.h>
87d57858 25#include <fstream.h>
c12208b8 26
27//
28//Root includes
29//
30#include <TFile.h>
31
32//
33//AliRoot includes
34//
35#include "AliRawReader.h"
36#include "AliRawReaderDate.h"
87d57858 37#include "AliTPCmapper.h"
c12208b8 38#include "AliTPCRawStream.h"
39#include "AliTPCROC.h"
40#include "AliTPCCalROC.h"
41#include "AliTPCCalPad.h"
42#include "AliMathBase.h"
43#include "TTreeStream.h"
44
45//
46// TPC calibration algorithm includes
47//
48#include "AliTPCCalibPedestal.h"
49
50
51
52
53/* Main routine
54 Arguments: list of DATE raw data files
55*/
56int main(int argc, char **argv) {
57
58 int i,status;
59 AliTPCCalibPedestal calibPedestal; // pedestal and noise calibration
60
61 if (argc<2) {
62 printf("Wrong number of arguments\n");
63 return -1;
64 }
65
66
67 /* log start of process */
68 printf("TPC DA started - %s\n",__FILE__);
69
70
71 /* declare monitoring program */
72 status=monitorDeclareMp( __FILE__ );
73 if (status!=0) {
74 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
75 return -1;
76 }
77
78
79 /* loop over RAW data files */
80 int nevents=0;
81 for(i=1;i<argc;i++) {
82
83 /* define data source : this is argument i */
84 printf("Processing file %s\n", argv[i]);
85 status=monitorSetDataSource( argv[i] );
86 if (status!=0) {
87 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
88 return -1;
89 }
90
91 /* read until EOF */
92 for(;;) {
93 struct eventHeaderStruct *event;
94
95 /* check shutdown condition */
96 if (daqDA_checkShutdown()) {break;}
97
98 /* get next event (blocking call until timeout) */
99 status=monitorGetEventDynamic((void **)&event);
100 if (status==MON_ERR_EOF) {
101 printf ("End of File %d detected\n",i);
102 break; /* end of monitoring file has been reached */
103 }
104
105 if (status!=0) {
106 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
107 break;
108 }
109
110 /* retry if got no event */
111 if (event==NULL) {
112 continue;
113 }
114 nevents++;
115
116 // Pedestal calibration
117 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
118 calibPedestal.ProcessEvent(rawReader);
119 delete rawReader;
120
121 /* free resources */
122 free(event);
123 }
124 }
125
126 calibPedestal.Analyse();
127 printf ("%d events processed\n",nevents);
128
129 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
130 calibPedestal.Write("calibPedestal");
131 delete fileTPC;
132 printf("Wrote %s\n",RESULT_FILE);
133
87d57858 134 // Prepare files for local ALTRO configuration through DDL
135 AliTPCmapper mapping;
136
137 ofstream out;
138 char filename[255];
139 sprintf(filename,"Pedestals.data");
140 out.open(filename);
141
142 Int_t ctr = 0;
143
144 out << 10 << endl; // PEDESTALS
145 for ( int roc = 0; roc <= 71; roc++ ) {
146 if ( !calibPedestal.GetCalRocPedestal(roc) ) continue;
147 Int_t side = mapping.GetSideFromRoc(roc);
148 Int_t sec = mapping.GetSectorFromRoc(roc);
149 printf("**Analysing ROC %d (side %d, sector %d) ...\n", roc, side, sec);
150 for ( int row = 0; row < mapping.GetNpadrows(roc); row++ ) {
151 for ( int pad = 0; pad < mapping.GetNpads(roc, row); pad++ ) {
152 Int_t rcu = mapping.GetRcu(roc, row, pad);
153 Int_t hwadd = mapping.GetHWAddress(roc, row, pad);
154 Float_t ped = calibPedestal.GetCalRocPedestal(roc)->GetValue(row,pad);
155 out << ctr << "\t" << side << "\t" << sec << "\t" << rcu << "\t" << hwadd << "\t" << ped << std::endl;
156 ctr++;
157 }
158 }
159 }
160
161 out.close();
162
c12208b8 163 return status;
164}