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