]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/TPCCEda.cxx
--This li
[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 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 19/09/2008  J.Wiechula@gsi.de:           Added support for configuration files.
23
24 contact: marian.ivanov@cern.ch
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 "tpcCE.root"
33 #define FILE_ID "CE"
34 #define MAPPING_FILE "tpcMapping.root"
35 #define CONFIG_FILE "TPCCEda.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 #include "TString.h"
52 #include "TObjString.h"
53 #include "TDatime.h"
54 //
55 //AliRoot includes
56 //
57 #include "AliRawReader.h"
58 #include "AliRawReaderDate.h"
59 #include "AliTPCmapper.h"
60 #include "AliTPCRawStream.h"
61 #include "AliTPCROC.h"
62 #include "AliTPCCalROC.h"
63 #include "AliTPCCalPad.h"
64 #include "AliMathBase.h"
65 #include "TTreeStream.h"
66 #include "AliLog.h"
67 #include "AliTPCConfigDA.h"
68 //
69 //AMORE
70 //
71 #include <AmoreDA.h>
72 //
73 // TPC calibration algorithm includes
74 //
75 #include "AliTPCCalibCE.h"
76
77
78
79
80 /* Main routine
81       Arguments: list of DATE raw data files
82 */
83 int main(int argc, char **argv) {
84   /* log start of process */
85   printf("TPC CE DA started - %s\n",__FILE__);
86
87   if (argc<2) {
88     printf("Wrong number of arguments\n");
89     return -1;
90   }
91   
92   AliLog::SetClassDebugLevel("AliTPCRawStream",-5);
93   AliLog::SetClassDebugLevel("AliRawReaderDate",-5);
94   AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5);
95   AliLog::SetModuleDebugLevel("RAW",-5);
96
97  gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
98                                          "*",
99                                          "TStreamerInfo",
100                                          "RIO",
101                                          "TStreamerInfo()");
102
103  /* declare monitoring program */
104  int i,status;
105  status=monitorDeclareMp( __FILE__ );
106  if (status!=0) {
107    printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
108    return -1;
109  }
110  monitorSetNowait();
111  monitorSetNoWaitNetworkTimeout(1000);
112
113   //variables 
114   AliTPCmapper *mapping = 0;   // The TPC mapping
115   char localfile[255];
116   unsigned long32 runNb=0;      //run number
117   // configuration options 
118   Bool_t fastDecoding = kFALSE;
119  
120   // if  test setup get parameters from $DAQDA_TEST_DIR 
121   if (!mapping){
122     /* copy locally the mapping file from daq detector config db */
123     sprintf(localfile,"./%s",MAPPING_FILE);
124     status = daqDA_DB_getFile(MAPPING_FILE,localfile);
125     if (status) {
126       printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status);
127       return -1;
128     }
129
130     /* open the mapping file and retrieve mapping object */
131     TFile *fileMapping = new TFile(MAPPING_FILE, "read");
132     mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping");
133     delete fileMapping;
134   }
135
136   if (mapping == 0) {
137     printf("Failed to get mapping object from %s.  ...\n", MAPPING_FILE);
138     return -1;
139   } else {
140     printf("Got mapping object from %s\n", MAPPING_FILE);
141   }
142   
143   //
144   // DA configuration from configuration file
145   //
146  //retrieve configuration file
147   sprintf(localfile,"./%s",CONFIG_FILE);
148   status = daqDA_DB_getFile(CONFIG_FILE,localfile);
149   if (status) {
150     printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status);
151     return -1;
152   }
153   AliTPCConfigDA config(CONFIG_FILE);
154   // check configuration
155   if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ){
156     printf("Info: The fast decoder will be used for the processing.\n");
157     fastDecoding=kTRUE;
158   }
159
160   //create calibration object 
161   AliTPCCalibCE calibCE(config.GetConfigurationMap());   // central electrode calibration
162   calibCE.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb
163
164   //===========================//
165   // loop over RAW data files //
166   //==========================//
167   int nevents=0;
168   for ( i=1; i<argc; i++) {
169
170     /* define data source : this is argument i */
171     printf("Processing file %s\n", argv[i]);
172     status=monitorSetDataSource( argv[i] );
173     if (status!=0) {
174       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
175       return -1;
176     }
177
178     /* read until EOF */
179     while (true) {
180       struct eventHeaderStruct *event;
181
182       /* check shutdown condition */
183       if (daqDA_checkShutdown()) {break;}
184
185       /* get next event (blocking call until timeout) */
186       status=monitorGetEventDynamic((void **)&event);
187       if (status==MON_ERR_EOF) {
188         printf ("End of File %d detected\n",i);
189         break; /* end of monitoring file has been reached */
190       }
191
192       if (status!=0) {
193         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
194         break;
195       }
196       
197       /* skip start/end of run events */
198       if ( (event->eventType != physicsEvent) && (event->eventType != calibrationEvent) )
199         continue;
200
201       /* retry if got no event */
202       if (event==NULL)
203         continue;
204       
205       nevents++;
206       // get the run number
207       runNb = event->eventRunNb;
208       //  CE calibration
209 //       AliRawReader *rawReader = new AliRawReaderDate((void*)event);
210 //       if ( fastDecoding ) calibCE.ProcessEventFast(rawReader);
211 //       else calibCE.ProcessEvent(rawReader);
212 //       delete rawReader;
213
214       if ( fastDecoding ) {
215         AliRawReader *rawReader = new AliRawReaderDate((void*)event);
216         calibCE.ProcessEventFast(rawReader);
217         delete rawReader;
218       } else {
219         calibCE.ProcessEvent(event);
220       }
221       
222       /* free resources */
223       free(event);
224     }
225   }
226
227   //
228   // Analyse CE data and write them to rootfile
229   //
230   calibCE.Analyse();
231   printf ("%d events processed\n",nevents);
232
233   TFile * fileTPC = new TFile (RESULT_FILE,"recreate");
234   calibCE.Write("tpcCalibCE");
235   delete fileTPC;
236   printf("Wrote %s\n",RESULT_FILE);
237
238   /* store the result file on FES */
239
240   status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
241   if (status) {
242     status = -2;
243   }
244
245   //
246   //Send objects to the AMORE DB
247   //
248   printf ("AMORE part\n");
249   const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
250   //cheet a little -- temporary solution (hopefully)
251   //
252   //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
253   //table in which the calib objects are stored. This table is dropped each time AmoreDA
254   //is initialised. This of course makes a problem if we would like to store different
255   //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
256   //the AMORE_DA_NAME env variable is overwritten.  
257   gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%s",FILE_ID));
258   //
259   // end cheet
260   TDatime time;
261   TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString()));
262   amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
263   Int_t statusDA=0;
264   statusDA+=amoreDA.Send("CET0",calibCE.GetCalPadT0());
265   statusDA+=amoreDA.Send("CEQ",calibCE.GetCalPadQ());
266   statusDA+=amoreDA.Send("CERMS",calibCE.GetCalPadRMS());
267   statusDA+=amoreDA.Send("Info",&info);
268   if ( statusDA!=0 )
269     printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
270   if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
271
272   return status;
273 }