]>
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 | ||
12f70d37 | 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. | |
12f70d37 | 24 | 23/04/2011 Christian.Lippmann@cern.ch : Added output of acsii files for online |
a1b9c189 | 25 | 26/09/2014 Christian.Lippmann@cern.ch : CHange for new DAQ setup with one CRORC per LDC |
26 | 26/09/2014 Jens.Wiechula@cern.ch : comment out obsolete AliTPCRawStream | |
12f70d37 | 27 | |
28 | contact: marian.ivanov@cern.ch | |
ec2624ea | 29 | |
30 | ||
31 | This process reads RAW data from the files provided as command line arguments | |
32 | and save results in a file (named from RESULT_FILE define - see below). | |
33 | ||
34 | */ | |
35 | ||
36 | #define RESULT_FILE "tpcPulser.root" | |
bd955ed2 | 37 | #define FILE_ID "pulser" |
04049c81 | 38 | #define MAPPING_FILE "tpcMapping.root" |
ac940b58 | 39 | #define CONFIG_FILE "TPCPULSERda.conf" |
12f70d37 | 40 | #define Q_FILE "tpcPulserQ.data" |
41 | #define DEAD_FILE "tpcDeadChannelsPulser.data" | |
b401648b | 42 | #define AliDebugLevel() -1 |
ec2624ea | 43 | |
44 | ||
45 | #include <daqDA.h> | |
46 | #include "event.h" | |
47 | #include "monitor.h" | |
48 | #include <stdio.h> | |
49 | #include <stdlib.h> | |
12f70d37 | 50 | #include <fstream> |
ec2624ea | 51 | |
52 | // | |
53 | //Root includes | |
54 | // | |
55 | #include <TFile.h> | |
56 | #include "TROOT.h" | |
57 | #include "TPluginManager.h" | |
ac940b58 | 58 | #include "TString.h" |
59 | #include "TObjString.h" | |
60 | #include "TDatime.h" | |
ec2624ea | 61 | // |
62 | //AliRoot includes | |
63 | // | |
64 | #include "AliRawReader.h" | |
65 | #include "AliRawReaderDate.h" | |
97b609ee | 66 | #include "AliTPCmapper.h" |
a1b9c189 | 67 | //#include "AliTPCRawStreamV3.h" |
ec2624ea | 68 | #include "AliTPCROC.h" |
69 | #include "AliTPCCalROC.h" | |
70 | #include "AliTPCCalPad.h" | |
71 | #include "AliMathBase.h" | |
72 | #include "TTreeStream.h" | |
b401648b | 73 | #include "AliLog.h" |
74 | #include "TSystem.h" | |
ac940b58 | 75 | #include "AliTPCConfigDA.h" |
76 | // | |
77 | //AMORE | |
78 | // | |
79 | #include <AmoreDA.h> | |
ec2624ea | 80 | // |
81 | // TPC calibration algorithm includes | |
82 | // | |
83 | #include "AliTPCCalibPulser.h" | |
84 | ||
ec2624ea | 85 | /* Main routine |
86 | Arguments: list of DATE raw data files | |
87 | */ | |
88 | int main(int argc, char **argv) { | |
ac940b58 | 89 | /* log start of process */ |
90 | printf("TPC Pulser DA started - %s\n",__FILE__); | |
91 | ||
92 | if (argc<2) { | |
93 | printf("Wrong number of arguments\n"); | |
94 | return -1; | |
95 | } | |
a1b9c189 | 96 | //AliLog::SetClassDebugLevel("AliTPCRawStreamV3",-5); |
bd955ed2 | 97 | AliLog::SetClassDebugLevel("AliRawReaderDate",-5); |
98 | AliLog::SetClassDebugLevel("AliTPCAltroMapping",-5); | |
99 | AliLog::SetModuleDebugLevel("RAW",-5); | |
ec2624ea | 100 | |
ac940b58 | 101 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
102 | "*", | |
103 | "TStreamerInfo", | |
104 | "RIO", | |
105 | "TStreamerInfo()"); | |
ec2624ea | 106 | |
a1b9c189 | 107 | /* |
12f70d37 | 108 | TString daterolename(gSystem->Getenv("DATE_ROLE_NAME")); |
109 | if ( daterolename == "" ) { | |
110 | printf("Error: Variable DATE_ROLE_NAME not defined! Exiting ...\n"); | |
111 | return -1; | |
112 | } | |
113 | bool inner; | |
114 | if ( daterolename.EndsWith("-0") ) inner = true; | |
115 | else if ( daterolename.EndsWith("-1") ) inner = false; | |
116 | else { | |
117 | printf("Error: Variable DATE_ROLE_NAME neither ends with -0 nor -1 (E.g. ldc-TPC-C12-1)! Exiting ...\n"); | |
118 | return -1; | |
119 | } | |
a1b9c189 | 120 | */ |
12f70d37 | 121 | |
ac940b58 | 122 | /* declare monitoring program */ |
ec2624ea | 123 | int i,status; |
ac940b58 | 124 | status=monitorDeclareMp( __FILE__ ); |
125 | if (status!=0) { | |
126 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
127 | return -1; | |
128 | } | |
129 | ||
130 | // variables | |
b401648b | 131 | AliTPCmapper *mapping = 0; // The TPC mapping |
ac940b58 | 132 | char localfile[255]; |
133 | unsigned long32 runNb=0; //run number | |
134 | // configuration options | |
b401648b | 135 | // if test setup get parameters from $DAQDA_TEST_DIR |
5d694e7e | 136 | |
b401648b | 137 | if (!mapping){ |
138 | /* copy locally the mapping file from daq detector config db */ | |
ac940b58 | 139 | sprintf(localfile,"./%s",MAPPING_FILE); |
140 | status = daqDA_DB_getFile(MAPPING_FILE,localfile); | |
b401648b | 141 | if (status) { |
142 | printf("Failed to get mapping file (%s) from DAQdetDB, status=%d\n", MAPPING_FILE, status); | |
ac940b58 | 143 | return -1; |
b401648b | 144 | } |
145 | ||
146 | /* open the mapping file and retrieve mapping object */ | |
147 | TFile *fileMapping = new TFile(MAPPING_FILE, "read"); | |
148 | mapping = (AliTPCmapper*) fileMapping->Get("tpcMapping"); | |
149 | delete fileMapping; | |
04049c81 | 150 | } |
151 | ||
04049c81 | 152 | if (mapping == 0) { |
b401648b | 153 | printf("Failed to get mapping object from %s. ...\n", MAPPING_FILE); |
ac940b58 | 154 | return -1; |
04049c81 | 155 | } else { |
156 | printf("Got mapping object from %s\n", MAPPING_FILE); | |
157 | } | |
158 | ||
ac940b58 | 159 | // |
160 | // DA configuration from configuration file | |
161 | // | |
162 | //retrieve configuration file | |
163 | sprintf(localfile,"./%s",CONFIG_FILE); | |
164 | status = daqDA_DB_getFile(CONFIG_FILE,localfile); | |
165 | if (status) { | |
166 | printf("Failed to get configuration file (%s) from DAQdetDB, status=%d\n", CONFIG_FILE, status); | |
ec2624ea | 167 | return -1; |
168 | } | |
ac940b58 | 169 | AliTPCConfigDA config(CONFIG_FILE); |
170 | // check configuration options | |
6b411ea4 | 171 | Bool_t skipAmore=kFALSE; |
172 | ||
173 | //skip the amore part | |
174 | if ( config.GetConfigurationMap()->GetValue("SkipAmore") ) { | |
175 | skipAmore=((TObjString*)config.GetConfigurationMap()->GetValue("SkipAmore"))->GetString().Atoi(); | |
176 | printf("TPCPULSERda: Skip Amore set in config\n"); | |
ec2624ea | 177 | } |
178 | ||
ac940b58 | 179 | // create calibration object |
180 | AliTPCCalibPulser calibPulser(config.GetConfigurationMap()); // pulser calibration algorithm | |
181 | calibPulser.SetAltroMapping(mapping->GetAltroMapping()); // Use altro mapping we got from daqDetDb | |
ec2624ea | 182 | |
ac940b58 | 183 | //===========================// |
184 | // loop over RAW data files // | |
185 | //==========================// | |
ec2624ea | 186 | int nevents=0; |
187 | for(i=1;i<argc;i++) { | |
188 | ||
189 | /* define data source : this is argument i */ | |
190 | printf("Processing file %s\n", argv[i]); | |
191 | status=monitorSetDataSource( argv[i] ); | |
192 | if (status!=0) { | |
193 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
194 | return -1; | |
195 | } | |
196 | ||
197 | /* read until EOF */ | |
198 | while (true) { | |
199 | struct eventHeaderStruct *event; | |
200 | ||
201 | /* check shutdown condition */ | |
202 | if (daqDA_checkShutdown()) {break;} | |
203 | ||
204 | /* get next event (blocking call until timeout) */ | |
205 | status=monitorGetEventDynamic((void **)&event); | |
206 | if (status==MON_ERR_EOF) { | |
207 | printf ("End of File %d detected\n",i); | |
208 | break; /* end of monitoring file has been reached */ | |
209 | } | |
210 | ||
211 | if (status!=0) { | |
212 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
213 | break; | |
214 | } | |
215 | ||
216 | /* retry if got no event */ | |
217 | if (event==NULL) { | |
218 | continue; | |
219 | } | |
220 | nevents++; | |
ac940b58 | 221 | // get the run number |
222 | runNb = event->eventRunNb; | |
ec2624ea | 223 | // Pulser calibration |
5312f439 | 224 | calibPulser.ProcessEvent(event); |
ec2624ea | 225 | |
226 | /* free resources */ | |
227 | free(event); | |
228 | } | |
229 | } | |
230 | ||
ac940b58 | 231 | // |
232 | // Analyse pulser data and write them to rootfile | |
233 | // | |
234 | calibPulser.Analyse(); | |
ec2624ea | 235 | printf ("%d events processed\n",nevents); |
236 | ||
237 | TFile * fileTPC = new TFile (RESULT_FILE,"recreate"); | |
e73181c9 | 238 | calibPulser.Write("tpcCalibPulser"); |
ec2624ea | 239 | delete fileTPC; |
240 | printf("Wrote %s\n",RESULT_FILE); | |
241 | ||
f2c72763 | 242 | /* store the result file on FES */ |
243 | ||
bd955ed2 | 244 | status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID); |
f2c72763 | 245 | if (status) { |
246 | status = -2; | |
247 | } | |
ac940b58 | 248 | // |
249 | //Send objects to the AMORE DB | |
250 | // | |
6b411ea4 | 251 | if (!skipAmore){ |
252 | printf ("AMORE part\n"); | |
253 | const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME"); | |
254 | //cheet a little -- temporary solution (hopefully) | |
255 | // | |
256 | //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql | |
257 | //table in which the calib objects are stored. This table is dropped each time AmoreDA | |
258 | //is initialised. This of course makes a problem if we would like to store different | |
259 | //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB | |
260 | //the AMORE_DA_NAME env variable is overwritten. | |
261 | ||
262 | //find processed sector | |
263 | Char_t sideName='A'; | |
264 | Int_t sector = -1; | |
265 | for ( Int_t roc = 0; roc < 72; roc++ ) { | |
266 | if ( !calibPulser.GetCalRocT0(roc) ) continue; | |
267 | if (mapping->GetSideFromRoc(roc)==1) sideName='C'; | |
268 | sector = mapping->GetSectorFromRoc(roc); | |
269 | } | |
270 | //gSystem->Setenv("AMORE_DA_NAME",Form("TPC-%c%02d-%s",sideName,sector,FILE_ID)); | |
271 | gSystem->Setenv("AMORE_DA_NAME",Form("%s-%s", gSystem->Getenv("DATE_ROLE_NAME"), FILE_ID)); | |
272 | // | |
273 | // end cheet | |
274 | if (sector>-1){ | |
275 | TDatime time; | |
276 | TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString())); | |
277 | ||
278 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
279 | Int_t statusDA=0; | |
280 | statusDA+=amoreDA.Send("PulserT0",calibPulser.GetCalPadT0()); | |
281 | statusDA+=amoreDA.Send("PulserQ",calibPulser.GetCalPadQ()); | |
282 | statusDA+=amoreDA.Send("PulserRMS",calibPulser.GetCalPadRMS()); | |
283 | statusDA+=amoreDA.Send("arrayTmean",calibPulser.GetMeanTimeSectorArray()); | |
284 | statusDA+=amoreDA.Send("Info",&info); | |
285 | if ( statusDA!=0 ) | |
286 | printf("Waring: Failed to write one of the calib objects to the AMORE database\n"); | |
287 | } else { | |
288 | printf("Waring: No data found!\n"); | |
289 | } | |
290 | // reset env var | |
291 | if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig); | |
6a02fd57 | 292 | } |
e9d80afd | 293 | |
12f70d37 | 294 | // |
295 | // Now prepare ASCII files for local ALTRO configuration through DDL. | |
296 | // | |
297 | ofstream deadchannelfile; | |
298 | ofstream qfile; | |
299 | ||
300 | qfile.open(Q_FILE); | |
301 | deadchannelfile.open(DEAD_FILE); | |
302 | ||
303 | qfile << 19 << std::endl; // Pulser Q | |
304 | deadchannelfile << 14 << std::endl; // Mark file to contain NOISY or DEAD CHANNELS | |
305 | ||
306 | Int_t ctr_channel = 0; | |
307 | Int_t ctr_dead= 0; | |
308 | ||
309 | // inner==true : calROC from ldc-0 contains: rcus 0,1 for IROC and rcu 2 for OROC | |
310 | // inner==false: calROC from ldc-1 contains: nothingfor IROC and rcus 3,4,5 for OROC | |
311 | for ( Int_t roc = 0; roc < 72; roc++ ) { | |
312 | if ( !calibPulser.GetCalRocQ(roc) ) continue; | |
313 | bool isIROC= mapping->IsIROC(roc); | |
314 | Int_t side = mapping->GetSideFromRoc(roc); | |
315 | Int_t sec= mapping->GetSectorFromRoc(roc); | |
316 | Int_t minrcu, maxrcu; | |
a1b9c189 | 317 | if( isIROC ) { minrcu=0; maxrcu=1; } |
318 | //else if ( inner) { minrcu=2; maxrcu=2; } | |
319 | //else { minrcu=3; maxrcu=5; } | |
320 | else { minrcu=2; maxrcu=5; } | |
12f70d37 | 321 | for ( int rcu = minrcu; rcu <= maxrcu; rcu++ ) { |
322 | //Int_t patch = mapping->IsIROC(roc) ? rcu : rcu+2; | |
323 | for ( int branch = 0; branch < 2; branch++ ) { | |
324 | for ( int fec = 0; fec < mapping->GetNfec(rcu, branch); fec++ ) { | |
325 | for ( int altro = 0; altro < 8; altro++ ) { | |
326 | for ( int channel = 0; channel < 16; channel++ ) { | |
327 | Int_t hwadd = mapping->CodeHWAddress(branch, fec, altro, channel); | |
328 | Int_t row = mapping->GetPadRow(rcu, hwadd); // row in a ROC | |
329 | Int_t globalrow = mapping->GetGlobalPadRow(rcu, hwadd); // row in full sector | |
330 | Int_t pad = mapping->GetPad(rcu, hwadd); | |
331 | // skip edge pads | |
332 | if ( (pad<1) || (pad>mapping->GetNpads(globalrow)-2) ) continue; | |
333 | Float_t Q = calibPulser.GetCalRocQ(roc)->GetValue(row,pad); | |
334 | qfile << ctr_channel++ << "\t" << side << "\t" << sec << "\t" << rcu << "\t" << hwadd << "\t" << Q << std::endl; | |
335 | if ( fabs(Q) < 2) { // dead channel | |
336 | deadchannelfile << ctr_dead++ << "\t" << side << "\t" << sec << "\t" | |
337 | << rcu << "\t" << hwadd << "\t" << Q << std::endl; | |
338 | } | |
339 | } // end channel for loop | |
340 | } // end altro for loop | |
341 | } // end fec for loop | |
342 | } // end branch for loop | |
343 | } // end rcu for loop | |
344 | } // end roc loop | |
345 | ||
346 | qfile.close(); | |
347 | deadchannelfile.close(); | |
348 | ||
349 | printf("Wrote ASCII file. Found %d dead channels.\n", ctr_dead); | |
350 | ||
351 | return status; | |
ec2624ea | 352 | } |