]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/TPCRAWda.cxx
Jens Wiechula modifications.
[u/mrichter/AliRoot.git] / TPC / TPCRAWda.cxx
1 /*
2 TPC DA for online calibration
3
4 Contact: Jens.Wiechula@cern.ch
5 Link:
6 Run Type: PHYSICS STANDALONE
7 DA Type: MON
8 Number of events needed: 200
9 Input Files: /castor/cern.ch/alice/raw/global/2009/08/22/11/09000080958023.30.root
10 Output Files: tpcCalibRaw.root, to be exported to the DAQ FXS
11 fileId:   tpcCalibRaw
12 Trigger types used: PHYSICS_EVENT
13
14 */
15
16 /*
17
18 TPCRAWda.cxx - calibration algorithm for TPC pulser events
19
20 30/09/2009  J.Wiechula@gsi.de:     First implementation. 
21
22
23 This process reads RAW data from the files provided as command line arguments
24 and save results in a file (named from RESULT_FILE define - see below).
25
26 */
27
28 #define RESULT_FILE "tpcCalibRaw.root"
29 #define FILE_ID "tpcCalibRaw"
30 #define MAPPING_FILE "tpcMapping.root"
31 #define CONFIG_FILE "TPCRAWda.conf"
32 #define AliDebugLevel() -1
33
34
35 #include <daqDA.h>
36 #include "event.h"
37 #include "monitor.h"
38 #include <stdio.h>
39 #include <stdlib.h>
40
41 //
42 //Root includes
43 //
44 #include <TFile.h>
45 #include "TROOT.h"
46 #include "TPluginManager.h"
47 #include "TString.h"
48 #include "TObjString.h"
49 #include "TDatime.h"
50 //
51 //AliRoot includes
52 //
53 #include "AliRawReader.h"
54 #include "AliRawReaderDate.h"
55 #include "AliTPCmapper.h"
56 #include "AliTPCROC.h"
57 #include "AliTPCCalROC.h"
58 #include "AliTPCCalPad.h"
59 #include "AliMathBase.h"
60 #include "TTreeStream.h"
61 #include "AliLog.h"
62 #include "TSystem.h"
63 // #include "AliTPCConfigDA.h"
64 //
65 //AMORE
66 //
67 #include <AmoreDA.h>
68 //
69 // TPC calibration algorithm includes
70 //
71 #include "AliTPCCalibRaw.h"
72
73 /* Main routine
74       Arguments: list of DATE raw data files
75 */
76 int main(int argc, char **argv) {
77   /* log start of process */
78   printf("TPC RAW DA started - %s\n",__FILE__);
79
80   if (argc<2) {
81     printf("Wrong number of arguments\n");
82     return -1;
83   }
84   AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
85   AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
86   AliLog::SetModuleDebugLevel("RAW",-5);
87
88   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
89                                         "*",
90                                         "TStreamerInfo",
91                                         "RIO",
92                                         "TStreamerInfo()");
93
94
95   /* declare monitoring program */
96   int i,status;
97   status=monitorDeclareMp( __FILE__ );
98   if (status!=0) {
99     printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
100     return -1;
101   }
102
103   // variables 
104   AliTPCmapper *mapping = 0;   // The TPC mapping
105   char localfile[255];
106   unsigned long32 runNb=0;      //run number
107   // configuration options 
108   Bool_t fastDecoding = kFALSE;
109   // if  test setup get parameters from $DAQDA_TEST_DIR 
110    
111   if (!mapping){
112     /* copy locally the mapping file from daq detector config db */
113     sprintf(localfile,"./%s",MAPPING_FILE);
114     status = daqDA_DB_getFile(MAPPING_FILE,localfile);
115     if (status) {
116       printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
117       return -1;
118     }
119
120     /* open the mapping file and retrieve mapping object */
121     TFile *fileMapping = new TFile(MAPPING_FILE, "read");
122     mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
123     delete fileMapping;
124   }
125
126   if (mapping == 0) {
127     printf("Failed to get mapping object from %s.  ...\n", MAPPING_FILE);
128     return -1;
129   } else {
130     printf("Got mapping object from %s\n", MAPPING_FILE);
131   }
132
133   //
134   // DA configuration from configuration file
135   //
136  //retrieve configuration file
137 //   sprintf(localfile,"./%s",CONFIG_FILE);
138 //   status = daqDA_DB_getFile(CONFIG_FILE,localfile);
139 //   if (status) {
140 //     printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
141 //     return -1;
142 //   }
143 //   AliTPCConfigDA config(CONFIG_FILE);
144
145   // create calibration object
146 //   AliTPCCalibRaw calibRaw(config.GetConfigurationMap());   // pulser calibration algorithm
147   AliTPCCalibRaw calibRaw;   // pulser calibration algorithm
148   calibRaw.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
149
150   //===========================//
151   // loop over RAW data files //
152   //==========================//
153   int nevents=0;
154   for(i=1;i<argc;i++) {
155
156     /* define data source : this is argument i */
157     printf("Processing file %s\n", argv[i]);
158     status=monitorSetDataSource( argv[i] );
159     if (status!=0) {
160       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
161       return -1;
162     }
163
164     /* read until EOF */
165     while (true) {
166       struct eventHeaderStruct *event;
167
168       /* check shutdown condition */
169       if (daqDA_checkShutdown()) {break;}
170
171       /* get next event (blocking call until timeout) */
172       status=monitorGetEventDynamic((void **)&event);
173       if (status==MON_ERR_EOF) {
174         printf ("End of File %d detected\n",i);
175         break; /* end of monitoring file has been reached */
176       }
177
178       if (status!=0) {
179         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
180         break;
181       }
182
183       /* retry if got no event */
184       if (event==NULL) {
185         continue;
186       }
187       nevents++;
188       // get the run number
189       runNb = event->eventRunNb;
190       //  Raw calibration
191       calibRaw.ProcessEvent(event);
192
193       /* free resources */
194       free(event);
195     }
196   }
197
198   //
199   // Analyse pulser data and write them to rootfile
200   //
201   calibRaw.Analyse();
202   printf ("%d events processed\n",nevents);
203
204   TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
205   calibRaw.Write("tpcCalibRaw");
206   delete fileTPC;
207   printf("Wrote %s\n",RESULT_FILE);
208
209   /* store the result file on FES */
210
211   status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
212   if (status) {
213     status = -2;
214   }
215   //
216   //Send objects to the AMORE DB
217   //
218   printf ("AMORE part\n");
219   const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
220   //cheet a little -- temporary solution (hopefully)
221   // 
222   //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
223   //table in which the calib objects are stored. This table is dropped each time AmoreDA
224   //is initialised. This of course makes a problem if we would like to store different
225   //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
226   //the AMORE_DA_NAME env variable is overwritten.  
227  
228   gSystem->Setenv("AMORE_DA_NAME","TPC-RAW");
229   // 
230   // end cheet
231   TDatime time;
232   TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
233     
234   amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
235   Int_t statusDA=0;  
236   statusDA+=amoreDA.Send("CalibRaw",&calibRaw);
237   statusDA+=amoreDA.Send("Info",&info);
238   if ( statusDA!=0 )
239     printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
240   // reset env var  
241   if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
242
243   return status;
244 }