New stager settings
[u/mrichter/AliRoot.git] / TPC / TPCCEda.cxx
CommitLineData
5a3a40fa 1/*
9c754ce7 2TPC DA for online calibration
3
4Contact: Haavard.Helstrup@cern.ch
5Link:
6Run Type: PHYSICS_RUN STANDALONE DAQ
7DA Type: MON
8Number of events needed: 500
9Input Files:
10Output Files: tpcCE.root, to be exported to the DAQ FXS
11Trigger types used: PHYSICS_EVENT
12
13*/
14
15/*
5a3a40fa 16
17TPCCEda.cxx - calibration algorithm for TPC Central Electrode events
18
1910/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1
2006/12/2007 haavard.helstrup@cern.ch : created CE DA based on pulser code
21
22contact: marian.ivanov@cern.ch
23
24
25This process reads RAW data from the files provided as command line arguments
26and save results in a file (named from RESULT_FILE define - see below).
27
28*/
29
9c754ce7 30#define RESULT_FILE "tpcCE.root"
04049c81 31#define MAPPING_FILE "tpcMapping.root"
5a3a40fa 32
33
34#include <daqDA.h>
35#include "event.h"
36#include "monitor.h"
37#include <stdio.h>
38#include <stdlib.h>
39
40//
41//Root includes
42//
43#include <TFile.h>
44#include "TROOT.h"
45#include "TPluginManager.h"
46//
47//AliRoot includes
48//
49#include "AliRawReader.h"
50#include "AliRawReaderDate.h"
51#include "AliTPCRawStream.h"
52#include "AliTPCROC.h"
53#include "AliTPCCalROC.h"
54#include "AliTPCCalPad.h"
55#include "AliMathBase.h"
56#include "TTreeStream.h"
57
58//
59// TPC calibration algorithm includes
60//
61#include "AliTPCCalibCE.h"
62
63
64
65
66/* Main routine
67 Arguments: list of DATE raw data files
68*/
69int main(int argc, char **argv) {
70
71 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
72 "*",
73 "TStreamerInfo",
74 "RIO",
75 "TStreamerInfo()");
76
77
78 int i,status;
04049c81 79
80 /* copy locally the mapping file from daq detector config db */
81 status = daqDA_DB_getFile(MAPPING_FILE,"./tpcMapping.root");
82 if (status) {
83 printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
84 printf("Continue anyway ... maybe it works?\n"); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
85 //return -1; // temporarily uncommented for testing on pcald47 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
86 }
87
88 /* open the mapping file and retrieve mapping object */
89 AliTPCmapper *mapping = 0; // The TPC mapping
90 TFile *fileMapping = new TFile(MAPPING_FILE, "read");
91 mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
92 if (mapping == 0) {
93 printf("Failed to get mapping object from %s. Exiting ...\n", MAPPING_FILE);
94 delete fileMapping;
95 return -1;
96 } else {
97 printf("Got mapping object from %s\n", MAPPING_FILE);
98 }
99
100
5a3a40fa 101 AliTPCCalibCE calibCE; // pedestal and noise calibration
102
103 if (argc<2) {
104 printf("Wrong number of arguments\n");
105 return -1;
106 }
107
108
109 /* log start of process */
110 printf("TPC CE DA started - %s\n",__FILE__);
111
112
ca273e23 113 /* set time bin range */
114 calibCE.SetRangeTime(800,940);
04049c81 115 calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
ca273e23 116
5a3a40fa 117 /* declare monitoring program */
118 status=monitorDeclareMp( __FILE__ );
119 if (status!=0) {
120 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
121 return -1;
122 }
123
124
125 /* loop over RAW data files */
126 int nevents=0;
127 for(i=1;i<argc;i++) {
128
129 /* define data source : this is argument i */
130 printf("Processing file %s\n", argv[i]);
131 status=monitorSetDataSource( argv[i] );
132 if (status!=0) {
133 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
134 return -1;
135 }
136
137 /* read until EOF */
138 while (true) {
139 struct eventHeaderStruct *event;
140
141 /* check shutdown condition */
142 if (daqDA_checkShutdown()) {break;}
143
144 /* get next event (blocking call until timeout) */
145 status=monitorGetEventDynamic((void **)&event);
146 if (status==MON_ERR_EOF) {
147 printf ("End of File %d detected\n",i);
148 break; /* end of monitoring file has been reached */
149 }
150
151 if (status!=0) {
152 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
153 break;
154 }
155
156 /* retry if got no event */
157 if (event==NULL) {
158 continue;
159 }
160 nevents++;
161
162 // Pulser calibration
163
164 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
165 calibCE.ProcessEvent(rawReader);
166 delete rawReader;
167
168 /* free resources */
169 free(event);
170 }
171 }
172
173 calibCE.Analyse();
174 printf ("%d events processed\n",nevents);
175
176 TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
177 calibCE.Write("calibCE");
178 delete fileTPC;
179 printf("Wrote %s\n",RESULT_FILE);
180
f2c72763 181 /* store the result file on FES */
182
183 status=daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE);
184 if (status) {
185 status = -2;
186 }
187
5a3a40fa 188 return status;
189}