New reader for the pedestal run and vdrift (Julian) and some bug fixing (Raphaelle)
[u/mrichter/AliRoot.git] / TRD / TRDPEDESTALda.cxx
CommitLineData
6ace5fe2 1/*
2
c5348551 3Contact: r.bailhache@gsi.de
27b46d95 4Link:
5Reference run: 12170
25781e34 6Run Type: PEDESTAL
c5348551 7DA Type: LDC
8Number of events needed: 100
27b46d95 9Input Files: TRD raw files
10Output Files: trdCalibration.root
f2a468d7 11Trigger types used: PHYSICS_EVENT
6ace5fe2 12
13*/
14
5f518e55 15#define RESULT_FILE "trdPedestal.root"
16#define FILE_ID "PADSTATUS"
6ace5fe2 17
18extern "C" {
19#include <daqDA.h>
20}
21
22#include "event.h"
23#include "monitor.h"
24#include <stdio.h>
25#include <stdlib.h>
26
27//
28// Root includes
29//
30#include <TFile.h>
31#include <TStopwatch.h>
25781e34 32#include "TROOT.h"
33#include "TPluginManager.h"
6ace5fe2 34//
35// AliRoot includes
36//
37#include "AliRawReader.h"
38#include "AliRawReaderDate.h"
987ba9a3 39#include "AliTRDrawStream.h"
5e64ce0d 40#include "AliTRDrawStreamBase.h"
6ace5fe2 41#include "AliCDBManager.h"
1785640c 42
43//
44//AMORE
45//
46#include <AmoreDA.h>
47
6ace5fe2 48//
49// AliRoot TRD calib classes
50//
51#include "AliTRDCalibPadStatus.h"
52
1785640c 53//functios, implementation below
54//void SendToAmoreDB(TObject *o, unsigned long32 runNb);
6ace5fe2 55
56/* Main routine
57 Arguments: list of DATE raw data files
58*/
59int main(int argc, char **argv) {
60
25781e34 61 /* magic line from Rene */
62 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
63 "*",
64 "TStreamerInfo",
65 "RIO",
66 "TStreamerInfo()");
67
6ace5fe2 68 int status;
69
70
71 /* log start of process */
72 printf("TRD DA PEDESTAL started\n");
73
74
75 /* check that we got some arguments = list of files */
76 if (argc<2) {
77 printf("Wrong number of arguments\n");
78 return -1;
79 }
80
81
82 /* copy locally a file from daq detector config db */
83 //status=daqDA_DB_getFile("myconfig","./myconfig.txt");
84 //if (status) {
85 // printf("Failed to get config file : %d\n",status);
86 // return -1;
87 //}
88 /* and possibly use it */
89
90
91 /* init some counters */
1785640c 92 int nevents_total=0;
6ace5fe2 93 int nevents =0;
94
95 //Instance of AliCDBManager: needed by AliTRDRawStream
162a3e73 96 //AliCDBManager *man = AliCDBManager::Instance();
162637e4 97 //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
162a3e73 98 //man->SetRun(0);
6ace5fe2 99 // AliTRDCalibPadStatus object
100 AliTRDCalibPadStatus calipad = AliTRDCalibPadStatus();
101 Bool_t passpadstatus = kTRUE;
1785640c 102 //unsigned long32 runNb=0; //run number
6ace5fe2 103
162a3e73 104 // setting
987ba9a3 105 // AliTRDrawStream::SetNoDebug();
0ca1720e 106 AliTRDrawStream::DisableSkipData();
987ba9a3 107 AliTRDrawStream::SetNoErrorWarning();
108 //AliTRDrawStream::SetForceCleanDataOnly();
0ca1720e 109 //AliTRDrawStream::AllowCorruptedData();
110 //AliTRDrawStream::DisableStackNumberChecker();
111 //AliTRDrawStream::DisableStackLinkNumberChecker();
987ba9a3 112 //AliTRDrawStream::SetSkipCDH();
113 //AliTRDrawStream::SetExtraWordsFix();
114 //AliTRDrawStream::EnableDebugStream();
115 //AliTRDrawStream::SetDumpHead(320);
116 //AliTRDrawStream::SetDumpHead(80);
6ace5fe2 117
118 /* read the data files */
119 int n;
120 for (n=1;n<argc;n++) {
121
122 /* define data source : this is argument i */
123 printf("Processing file %s\n",argv[n]);
124 status=monitorSetDataSource( argv[n] );
125 if (status!=0) {
126 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
127 return -1;
128 }
129
130 /* read the file until EOF */
131 for(;;) {
132 struct eventHeaderStruct *event;
f2a468d7 133 eventTypeType eventT;
6ace5fe2 134
135 /* get next event */
136 status=monitorGetEventDynamic((void **)&event);
137 if (status==MON_ERR_EOF) {
138 printf("End of File %d detected\n",n);
139 break; /* end of monitoring file has been reached */
140 }
141 if (status!=0) {
142 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
143 break;
144 }
145
146 /* retry if got no event */
147 if (event==NULL) {
148 break;
149 }
150
f2a468d7 151 /* use event - here, just write event id to result file */
152 eventT=event->eventType;
153
154 if((eventT==PHYSICS_EVENT) && (passpadstatus)){
6ace5fe2 155
156 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
f222df8d 157 rawReader->Select("TRD");
1785640c 158
159 Int_t result = calipad.ProcessEvent2((AliTRDrawReader *)rawReader);
8799e123 160 // 0 error, 1 no input, 2 output
161 if(result == 2) nevents++;
162 if(result == 0) passpadstatus = kFALSE;
6ace5fe2 163 delete rawReader;
8799e123 164
6ace5fe2 165 }
166
1785640c 167 nevents_total++;
168
169 // get the run number
170 //runNb = event->eventRunNb;
6ace5fe2 171
172 /* free resources */
173 free(event);
174 }
175 }
176
177
178 /* report progress */
1785640c 179 printf("%d events processed and %d used\n",nevents_total,nevents);
6ace5fe2 180
6ace5fe2 181 /* write file in any case to see what happens in case of problems*/
182 TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
8799e123 183 if(nevents < 30) calipad.Destroy();
289cc637 184 calipad.AnalyseHisto();
6ace5fe2 185 calipad.Write("calibpadstatus");
186 fileTRD->Close();
25781e34 187
6ace5fe2 188 /* store the result file on FES */
5f518e55 189 status=daqDA_FES_storeFile(RESULT_FILE,FILE_ID);
6ace5fe2 190 if (status) {
191 printf("Failed to export file : %d\n",status);
192 return -1;
193 }
6ace5fe2 194
195
196 return status;
1785640c 197
198 /*
199
200 // send objects to AMORE
201 //SendToAmoreDB(calibpad,runNb);
202
203 void SendToAmoreDB(TObject *calipad, unsigned long32 runNb)
204 {
205 //cheet a little -- temporary solution (hopefully)
206 //
207 //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
208 //table in which the calib objects are stored. This table is dropped each time AmoreDA
209 //is initialised. This of course makes a problem if we would like to store different
210 //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
211 //the AMORE_DA_NAME env variable is overwritten.
212
213
214 //
215 // The reference data are stored in:
216 // PadStatus1 for sm-00-01-02
217 // PadStatus2 for sm-03-04-05
218 // PadStatus3 for sm-06-07-08
219 // PadStatus4 for sm-09-10-11
220 // PadStatus5 for sm-12-13-14
221 // PadStatus6 for sm-15-16-17
222 // PadStatus0 if nothing found..means problems
223 //
224
225 ///////////////////
226 // Find wich LDC
227 ///////////////////
228 Int_t ldcnumber = -1;
229 Int_t sm = -1;
230 for (Int_t idet=0; idet<540; idet++) {
231 AliTRDCalROC *rocMean = calipad->GetCalRocMean(idet, kFALSE);
232 if ( rocMean ) {
233 sm = AliTRDgeometry::GetSector(idet);
234 if((sm==0) || (sm==1) || (sm==2)) ldcnumber = 1;
235 if((sm==3) || (sm==4) || (sm==5)) ldcnumber = 2;
236 if((sm==6) || (sm==7) || (sm==8)) ldcnumber = 3;
237 if((sm==9) || (sm==10) || (sm==11)) ldcnumber = 1;
238 if((sm==12) || (sm==13) || (sm==14)) ldcnumber = 2;
239 if((sm==15) || (sm==16) || (sm==17)) ldcnumber = 3;
240 }
241 }
242 const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
243
244 gSystem->Setenv("AMORE_DA_NAME",Form("TRD-dataQA-%02d-%s",ldcnumber,FILE_ID));
245
246 /////////////////////
247 // Send the stuff
248 ////////////////////
249 if (ldcnumber>-1){
250 TDatime time;
251 TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
252
253 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
254 Int_t statusDA=0;
255 statusDA+=amoreDA.Send("Pedestals",calibpad);
256 statusDA+=amoreDA.Send("Info",&info);
257 if ( statusDA )
258 printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
259 } else {
260 printf("Waring: No data found!\n");
261 }
262
263 // reset env var
264 if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
265
266 }
267
268 */
269
270
271
1ac4bb35 272}
0ca1720e 273