]>
Commit | Line | Data |
---|---|---|
9c754ce7 | 1 | /* |
2 | TPC DA for online calibration | |
3 | ||
4 | Contact: Haavard.Helstrup@cern.ch | |
5 | Link: | |
c23b10ec | 6 | Run Type: CALIBRATION_PULSER |
9c754ce7 | 7 | DA Type: LDC |
8 | Number of events needed: 100 | |
9 | Input Files: | |
10 | Output Files: tpcPulser.root, to be exported to the DAQ FXS | |
bd955ed2 | 11 | fileId: pulser |
9c754ce7 | 12 | Trigger types used: CALIBRATION_EVENT |
13 | ||
14 | */ | |
15 | ||
ec2624ea | 16 | /* |
17 | ||
18 | TPCda_pulser.cxx - calibration algorithm for TPC pulser events | |
19 | ||
20 | 10/06/2007 sylvain.chapeland@cern.ch : first version - clean skeleton based on DAQ DA case1 | |
21 | 30/09/2007 haavard.helstrup@cern.ch : created pulser DA based on pedestal code | |
ac940b58 | 22 | 19/09/2008 J.Wiechula@gsi.de: Added export of the calibration data to the AMORE data base. |
23 | Added support for configuration files. | |
ec2624ea | 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 "tpcPulser.root" | |
bd955ed2 | 33 | #define FILE_ID "pulser" |
04049c81 | 34 | #define MAPPING_FILE "tpcMapping.root" |
ac940b58 | 35 | #define CONFIG_FILE "TPCPULSERda.conf" |
b401648b | 36 | #define AliDebugLevel() -1 |
ec2624ea | 37 | |
38 | ||
39 | #include <daqDA.h> | |
40 | #include "event.h" | |
41 | #include "monitor.h" | |
42 | #include <stdio.h> | |
43 | #include <stdlib.h> | |
44 | ||
45 | // | |
46 | //Root includes | |
47 | // | |
48 | #include <TFile.h> | |
49 | #include "TROOT.h" | |
50 | #include "TPluginManager.h" | |
ac940b58 | 51 | #include "TString.h" |
52 | #include "TObjString.h" | |
53 | #include "TDatime.h" | |
ec2624ea | 54 | // |
55 | //AliRoot includes | |
56 | // | |
57 | #include "AliRawReader.h" | |
58 | #include "AliRawReaderDate.h" | |
97b609ee | 59 | #include "AliTPCmapper.h" |
ec2624ea | 60 | #include "AliTPCRawStream.h" |
61 | #include "AliTPCROC.h" | |
62 | #include "AliTPCCalROC.h" | |
63 | #include "AliTPCCalPad.h" | |
64 | #include "AliMathBase.h" | |
65 | #include "TTreeStream.h" | |
b401648b | 66 | #include "AliLog.h" |
67 | #include "TSystem.h" | |
ac940b58 | 68 | #include "AliTPCConfigDA.h" |
69 | // | |
70 | //AMORE | |
71 | // | |
72 | #include <AmoreDA.h> | |
ec2624ea | 73 | // |
74 | // TPC calibration algorithm includes | |
75 | // | |
76 | #include "AliTPCCalibPulser.h" | |
77 | ||
ec2624ea | 78 | /* Main routine |
79 | Arguments: list of DATE raw data files | |
80 | */ | |
81 | int main(int argc, char **argv) { | |
ac940b58 | 82 | /* log start of process */ |
83 | printf("TPC Pulser DA started - %s\n",__FILE__); | |
84 | ||
85 | if (argc<2) { | |
86 | printf("Wrong number of arguments\n"); | |
87 | return -1; | |
88 | } | |
bd955ed2 | 89 | AliLog::SetClassDebugLevel("AliTPCRawStream",-5); |
90 | AliLog::SetClassDebugLevel("AliRawReaderDate",-5); | |
91 | AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5); | |
92 | AliLog::SetModuleDebugLevel("RAW",-5); | |
ec2624ea | 93 | |
ac940b58 | 94 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
95 | "*", | |
96 | "TStreamerInfo", | |
97 | "RIO", | |
98 | "TStreamerInfo()"); | |
ec2624ea | 99 | |
100 | ||
ac940b58 | 101 | /* declare monitoring program */ |
ec2624ea | 102 | int i,status; |
ac940b58 | 103 | status=monitorDeclareMp( __FILE__ ); |
104 | if (status!=0) { | |
105 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
106 | return -1; | |
107 | } | |
108 | ||
109 | // variables | |
b401648b | 110 | AliTPCmapper *mapping = 0; // The TPC mapping |
ac940b58 | 111 | char localfile[255]; |
112 | unsigned long32 runNb=0; //run number | |
113 | // configuration options | |
114 | Bool_t fastDecoding = kFALSE; | |
b401648b | 115 | // if test setup get parameters from $DAQDA_TEST_DIR |
5d694e7e | 116 | |
b401648b | 117 | if (!mapping){ |
118 | /* copy locally the mapping file from daq detector config db */ | |
ac940b58 | 119 | sprintf(localfile,"./%s",MAPPING_FILE); |
120 | status = daqDA_DB_getFile(MAPPING_FILE,localfile); | |
b401648b | 121 | if (status) { |
122 | printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status); | |
ac940b58 | 123 | return -1; |
b401648b | 124 | } |
125 | ||
126 | /* open the mapping file and retrieve mapping object */ | |
127 | TFile *fileMapping = new TFile(MAPPING_FILE, "read"); | |
128 | mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping"); | |
129 | delete fileMapping; | |
04049c81 | 130 | } |
131 | ||
04049c81 | 132 | if (mapping == 0) { |
b401648b | 133 | printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE); |
ac940b58 | 134 | return -1; |
04049c81 | 135 | } else { |
136 | printf("Got mapping object from %s\n", MAPPING_FILE); | |
137 | } | |
138 | ||
ac940b58 | 139 | // |
140 | // DA configuration from configuration file | |
141 | // | |
142 | //retrieve configuration file | |
143 | sprintf(localfile,"./%s",CONFIG_FILE); | |
144 | status = daqDA_DB_getFile(CONFIG_FILE,localfile); | |
145 | if (status) { | |
146 | printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status); | |
ec2624ea | 147 | return -1; |
148 | } | |
ac940b58 | 149 | AliTPCConfigDA config(CONFIG_FILE); |
150 | // check configuration options | |
151 | if ( (Int_t)config.GetValue("UseFastDecoder") == 1 ) { | |
152 | printf("Info: The fast decoder will be used for the processing.\n"); | |
153 | fastDecoding=kTRUE; | |
ec2624ea | 154 | } |
155 | ||
ac940b58 | 156 | // create calibration object |
157 | AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm | |
158 | calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb | |
ec2624ea | 159 | |
ac940b58 | 160 | //===========================// |
161 | // loop over RAW data files // | |
162 | //==========================// | |
ec2624ea | 163 | int nevents=0; |
164 | for(i=1;i<argc;i++) { | |
165 | ||
166 | /* define data source : this is argument i */ | |
167 | printf("Processing file %s\n", argv[i]); | |
168 | status=monitorSetDataSource( argv[i] ); | |
169 | if (status!=0) { | |
170 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
171 | return -1; | |
172 | } | |
173 | ||
174 | /* read until EOF */ | |
175 | while (true) { | |
176 | struct eventHeaderStruct *event; | |
177 | ||
178 | /* check shutdown condition */ | |
179 | if (daqDA_checkShutdown()) {break;} | |
180 | ||
181 | /* get next event (blocking call until timeout) */ | |
182 | status=monitorGetEventDynamic((void **)&event); | |
183 | if (status==MON_ERR_EOF) { | |
184 | printf ("End of File %d detected\n",i); | |
185 | break; /* end of monitoring file has been reached */ | |
186 | } | |
187 | ||
188 | if (status!=0) { | |
189 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
190 | break; | |
191 | } | |
192 | ||
193 | /* retry if got no event */ | |
194 | if (event==NULL) { | |
195 | continue; | |
196 | } | |
197 | nevents++; | |
ac940b58 | 198 | // get the run number |
199 | runNb = event->eventRunNb; | |
ec2624ea | 200 | // Pulser calibration |
5312f439 | 201 | // AliRawReader *rawReader = new AliRawReaderDate((void*)event); |
202 | // if ( fastDecoding ) calibPulser.ProcessEventFast(rawReader); | |
203 | // else calibPulser.ProcessEvent(rawReader); | |
204 | // delete rawReader; | |
205 | calibPulser.ProcessEvent(event); | |
ec2624ea | 206 | |
207 | /* free resources */ | |
208 | free(event); | |
209 | } | |
210 | } | |
211 | ||
ac940b58 | 212 | // |
213 | // Analyse pulser data and write them to rootfile | |
214 | // | |
215 | calibPulser.Analyse(); | |
ec2624ea | 216 | printf ("%d events processed\n",nevents); |
217 | ||
218 | TFile * fileTPC = new TFile (RESULT_FILE,"recreate"); | |
e73181c9 | 219 | calibPulser.Write("tpcCalibPulser"); |
ec2624ea | 220 | delete fileTPC; |
221 | printf("Wrote %s\n",RESULT_FILE); | |
222 | ||
f2c72763 | 223 | /* store the result file on FES */ |
224 | ||
bd955ed2 | 225 | status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID); |
f2c72763 | 226 | if (status) { |
227 | status = -2; | |
228 | } | |
ac940b58 | 229 | // |
230 | //Send objects to the AMORE DB | |
231 | // | |
232 | printf ("AMORE part\n"); | |
233 | const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME"); | |
234 | //cheet a little -- temporary solution (hopefully) | |
235 | // | |
236 | //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql | |
237 | //table in which the calib objects are stored. This table is dropped each time AmoreDA | |
238 | //is initialised. This of course makes a problem if we would like to store different | |
239 | //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB | |
240 | //the AMORE_DA_NAME env variable is overwritten. | |
6a02fd57 | 241 | |
242 | //find processed sector | |
243 | Char_t sideName='A'; | |
244 | Int_t sector = 0; | |
245 | for ( Int_t roc = 0; roc < 72; roc++ ) { | |
246 | if ( !calibPulser.GetCalRocT0(roc) ) continue; | |
247 | if (mapping->GetSideFromRoc(roc)==1) sideName='C'; | |
248 | sector = mapping->GetSectorFromRoc(roc); | |
249 | } | |
250 | gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%c%02d-%s",sideName,sector,FILE_ID)); | |
ac940b58 | 251 | // |
252 | // end cheet | |
6a02fd57 | 253 | TDatime time; |
254 | TObjString info(Form("Run: %u; Date: %s",runNb,time.AsString())); | |
ac940b58 | 255 | |
6a02fd57 | 256 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); |
257 | Int_t statusDA=0; | |
258 | statusDA+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0()); | |
259 | statusDA+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ()); | |
260 | statusDA+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS()); | |
261 | statusDA+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray()); | |
262 | statusDA+=amoreDA.Send("Info",&info); | |
263 | if ( statusDA!=0 ) | |
264 | printf("Waring: Failed to write one of the calib objects to the AMORE database\n"); | |
265 | // reset env var | |
266 | if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig); | |
f2c72763 | 267 | |
ec2624ea | 268 | return status; |
269 | } |