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