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