]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDPEDESTALda.cxx
68a4723b9aa8173f3730e9cc719adbce9015a6a4
[u/mrichter/AliRoot.git] / TRD / TRDPEDESTALda.cxx
1 /*
2
3 - "Contact: r.bailhache@gsi.de"
4 - "Link: http://www-linux.gsi.de/~bailhach/PEDESTAL/raw.root.date" 
5 - "Run Type: dedicated pedestals run"
6 - "DA Type: LDC"
7 - "Number of events needed: 100"
8 - "Input Files: no config files, no previous result files, RAW DATA files from DDL = 1024 to DDL = 1041 included"
9 - "Output Files: trdCalibration.root, trdCalibration.root, no persitent file over runs"
10 - "Trigger types used: PEDESTAL_RUN"
11
12 */
13
14 #define RESULT_FILE "trdCalibration.root"
15
16 extern "C" {
17 #include <daqDA.h>
18 }
19
20 #include "event.h"
21 #include "monitor.h"
22 #include <stdio.h>
23 #include <stdlib.h>
24
25 //
26 // Root includes
27 //
28 #include <TFile.h>
29 #include <TStopwatch.h>
30
31 //
32 // AliRoot includes
33 //
34 #include "AliRawReader.h"
35 #include "AliRawReaderDate.h"
36 #include "AliTRDRawStreamTB.h"
37 #include "AliCDBManager.h"
38 //
39 // AliRoot TRD calib classes
40 //
41 #include "AliTRDCalibPadStatus.h"
42
43
44 /* Main routine
45       Arguments: list of DATE raw data files
46 */
47 int main(int argc, char **argv) {
48
49   int status;
50
51
52   /* log start of process */
53   printf("TRD DA PEDESTAL started\n");  
54
55
56   /* check that we got some arguments = list of files */
57   if (argc<2) {
58     printf("Wrong number of arguments\n");
59     return -1;
60   }
61
62
63   /* copy locally a file from daq detector config db */
64   //status=daqDA_DB_getFile("myconfig","./myconfig.txt");
65   //if (status) {
66   //  printf("Failed to get config file : %d\n",status);
67   //  return -1;
68   //}
69   /* and possibly use it */
70   
71
72   /* init some counters */
73   int nevents_total=0;
74   int nevents      =0;
75  
76   //Instance of AliCDBManager: needed by AliTRDRawStream
77   AliCDBManager *man = AliCDBManager::Instance();
78   man->SetDefaultStorage("local://$ALICE_ROOT");
79   man->SetRun(0);
80   // AliTRDCalibPadStatus object
81   AliTRDCalibPadStatus calipad = AliTRDCalibPadStatus();
82   Bool_t passpadstatus = kTRUE;
83
84
85   /*see the time*/
86   TStopwatch timer;
87   timer.Start();
88   
89   /* some warning less */
90   AliTRDRawStreamTB::SupressWarnings(kTRUE); 
91
92   /* read the data files */
93   int n;
94   for (n=1;n<argc;n++) {
95    
96     /* define data source : this is argument i */
97     printf("Processing file %s\n",argv[n]);
98     status=monitorSetDataSource( argv[n] );
99     if (status!=0) {
100       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
101       return -1;
102     }
103
104     /* read the file  until EOF */
105     for(;;) {
106       struct eventHeaderStruct *event;
107       
108       /* get next event */
109       status=monitorGetEventDynamic((void **)&event);
110       if (status==MON_ERR_EOF) {
111         printf("End of File %d detected\n",n);
112         break; /* end of monitoring file has been reached */
113       }
114       if (status!=0) {
115         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
116         break;
117       }
118
119       /* retry if got no event */
120       if (event==NULL) {
121         break;
122       }
123
124       if(passpadstatus){
125
126         AliRawReader *rawReader = new AliRawReaderDate((void*)event);
127         rawReader->Select("TRD");
128         AliTRDRawStreamTB *trdRawStream = new AliTRDRawStreamTB((AliRawReader *)rawReader);
129         //trdRawStream->Init();
130         if(!calipad.ProcessEvent(trdRawStream,(Bool_t)nevents_total)) passpadstatus = kFALSE;
131         nevents++;
132         delete trdRawStream;
133         delete rawReader;
134      
135       }
136
137       nevents_total++;
138
139       /* free resources */
140       free(event);
141     }
142   }
143
144
145   /* report progress */
146   printf("%d events processed and %d used\n",nevents_total,nevents);
147
148   /*see the time*/
149   timer.Stop();
150   timer.Print();
151
152   /* write file in any case to see what happens in case of problems*/
153   /*see the time*/
154   TStopwatch timer1;
155   timer1.Start();
156   TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
157   calipad.AnalyseHisto();
158   calipad.Write("calibpadstatus");
159   fileTRD->Close();   
160   printf("Wrote local file %s\n",RESULT_FILE);
161   /*see the time*/
162   timer1.Stop();
163   timer1.Print();
164   
165   /* store the result file on FES */
166   status=daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE);
167   if (status) {
168     printf("Failed to export file : %d\n",status);
169     return -1;
170   }
171   
172    
173   /* report progress */
174   daqDA_progressReport(100);
175
176   
177   return status;
178 }