]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDPEDESTALda.cxx
a72022c02d3f0a9481ed0491c14351f16e46645d
[u/mrichter/AliRoot.git] / TRD / TRDPEDESTALda.cxx
1 /*
2
3 Contact: r.bailhache@gsi.de
4 Link: run 12170
5 Run Type: PEDESTAL
6 DA Type: LDC
7 Number of events needed: 100
8 Input Files: raw files of the TRD
9 Output Files: trdCalibration.root,to be exported to the DAQ FXS
10 Trigger types used:
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 #include "TROOT.h"
31 #include "TPluginManager.h"
32 //
33 // AliRoot includes
34 //
35 #include "AliRawReader.h"
36 #include "AliRawReaderDate.h"
37 #include "AliTRDrawStreamTB.h"
38 #include "AliTRDrawStreamBase.h"
39 #include "AliCDBManager.h"
40 //
41 // AliRoot TRD calib classes
42 //
43 #include "AliTRDCalibPadStatus.h"
44
45
46 /* Main routine
47       Arguments: list of DATE raw data files
48 */
49 int main(int argc, char **argv) {
50
51   /* magic line from Rene */
52   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
53                                         "*",
54                                         "TStreamerInfo",
55                                         "RIO",
56                                         "TStreamerInfo()");
57   
58   int status;
59
60
61   /* log start of process */
62   printf("TRD DA PEDESTAL started\n");  
63
64
65   /* check that we got some arguments = list of files */
66   if (argc<2) {
67     printf("Wrong number of arguments\n");
68     return -1;
69   }
70
71
72   /* copy locally a file from daq detector config db */
73   //status=daqDA_DB_getFile("myconfig","./myconfig.txt");
74   //if (status) {
75   //  printf("Failed to get config file : %d\n",status);
76   //  return -1;
77   //}
78   /* and possibly use it */
79   
80
81   /* init some counters */
82   int nevents_total=0;
83   int nevents      =0;
84  
85   //Instance of AliCDBManager: needed by AliTRDRawStream
86   //AliCDBManager *man = AliCDBManager::Instance();
87   //man->SetDefaultStorage("local://$ALICE_ROOT");
88   //man->SetRun(0);
89   // AliTRDCalibPadStatus object
90   AliTRDCalibPadStatus calipad = AliTRDCalibPadStatus();
91   Bool_t passpadstatus = kTRUE;
92
93   // setting
94   // AliTRDrawStreamTB::SetNoDebug();
95   AliTRDrawStreamTB::SetNoErrorWarning();
96   AliTRDrawStreamTB::SetForceCleanDataOnly();
97   AliTRDrawStreamTB::AllowCorruptedData();
98   //AliTRDrawStreamTB::SetSkipCDH();
99   //AliTRDrawStreamTB::SetExtraWordsFix();
100   //AliTRDrawStreamTB::EnableDebugStream();
101   //AliTRDrawStreamTB::SetDumpHead(320);
102   //AliTRDrawStreamTB::SetDumpHead(80);
103
104   /* read the data files */
105   int n;
106   for (n=1;n<argc;n++) {
107    
108     /* define data source : this is argument i */
109     printf("Processing file %s\n",argv[n]);
110     status=monitorSetDataSource( argv[n] );
111     if (status!=0) {
112       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
113       return -1;
114     }
115
116     /* read the file  until EOF */
117     for(;;) {
118       struct eventHeaderStruct *event;
119       
120       /* get next event */
121       status=monitorGetEventDynamic((void **)&event);
122       if (status==MON_ERR_EOF) {
123         printf("End of File %d detected\n",n);
124         break; /* end of monitoring file has been reached */
125       }
126       if (status!=0) {
127         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
128         break;
129       }
130
131       /* retry if got no event */
132       if (event==NULL) {
133         break;
134       }
135
136       if(passpadstatus){
137
138         AliRawReader *rawReader = new AliRawReaderDate((void*)event);
139         rawReader->Select("TRD");
140         AliTRDrawStreamTB *trdRawStream = new AliTRDrawStreamTB((AliRawReader *)rawReader);
141         //trdRawStream->Init();
142         if(!calipad.ProcessEvent((AliTRDrawStreamBase *)trdRawStream,(Bool_t)nevents_total)) passpadstatus = kFALSE;
143         nevents++;
144         delete trdRawStream;
145         delete rawReader;
146      
147       }
148
149       nevents_total++;
150
151       /* free resources */
152       free(event);
153     }
154   }
155
156
157   /* report progress */
158   printf("%d events processed and %d used\n",nevents_total,nevents);
159
160   /* write file in any case to see what happens in case of problems*/
161   TFile *fileTRD = new TFile(RESULT_FILE,"recreate");
162   calipad.AnalyseHisto();
163   calipad.Write("calibpadstatus");
164   fileTRD->Close();   
165      
166   /* store the result file on FES */
167   status=daqDA_FES_storeFile(RESULT_FILE,RESULT_FILE);
168   if (status) {
169     printf("Failed to export file : %d\n",status);
170     return -1;
171   }
172
173   
174   return status;
175 }