]>
Commit | Line | Data |
---|---|---|
ddeb9c4f | 1 | /* |
2 | TPC DA for online calibration | |
3 | ||
4 | Contact: Jens.Wiechula@cern.ch | |
5 | Link: | |
6 | Run Type: | |
7 | DA Type: | |
8 | Number of events needed: | |
9 | Input Files: | |
10 | Output Files: tpcCalibRaw.root, to be exported to the DAQ FXS | |
11 | fileId: pulser | |
12 | Trigger types used: | |
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 Pulser 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 | // Pulser calibration | |
191 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); | |
192 | calibRaw.ProcessEvent(rawReader); | |
193 | delete rawReader; | |
194 | ||
195 | /* free resources */ | |
196 | free(event); | |
197 | } | |
198 | } | |
199 | ||
200 | // | |
201 | // Analyse pulser data and write them to rootfile | |
202 | // | |
203 | calibRaw.Analyse(); | |
204 | printf ("%d events processed\n",nevents); | |
205 | ||
206 | TFile * fileTPC = new TFile (RESULT_FILE,"recreate"); | |
207 | calibRaw.Write("tpcCalibRaw"); | |
208 | delete fileTPC; | |
209 | printf("Wrote %s\n",RESULT_FILE); | |
210 | ||
211 | /* store the result file on FES */ | |
212 | ||
213 | status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID); | |
214 | if (status) { | |
215 | status = -2; | |
216 | } | |
217 | // | |
218 | //Send objects to the AMORE DB | |
219 | // | |
220 | printf ("AMORE part\n"); | |
221 | const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME"); | |
222 | //cheet a little -- temporary solution (hopefully) | |
223 | // | |
224 | //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql | |
225 | //table in which the calib objects are stored. This table is dropped each time AmoreDA | |
226 | //is initialised. This of course makes a problem if we would like to store different | |
227 | //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB | |
228 | //the AMORE_DA_NAME env variable is overwritten. | |
229 | ||
230 | gSystem->Setenv("AMORE_DA_NAME","TPC-RAW"); | |
231 | // | |
232 | // end cheet | |
233 | TDatime time; | |
234 | TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString())); | |
235 | ||
236 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
237 | Int_t statusDA=0; | |
238 | statusDA+=amoreDA.Send("CalibRaw",&calibRaw); | |
239 | statusDA+=amoreDA.Send("Info",&info); | |
240 | if ( statusDA!=0 ) | |
241 | printf("Waring: Failed to write one of the calib objects to the AMORE database\n"); | |
242 | // reset env var | |
243 | if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig); | |
244 | ||
245 | return status; | |
246 | } |