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