]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDPEDESTALda.cxx
Fixed bug causing a crash if digits needed by the pretrigger simulation are not avail...
[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 "AliTRDrawFastStream.h"
40 #include "AliTRDrawStreamBase.h"
41 #include "AliCDBManager.h"
42
43 //
44 //AMORE
45 //
46 #include <AmoreDA.h>
47
48 //
49 // AliRoot TRD calib classes
50 //
51 #include "AliTRDCalibPadStatus.h"
52
53 //functios, implementation below
54 //void SendToAmoreDB(TObject *o, unsigned long32 runNb);
55
56 /* Main routine
57       Arguments: list of DATE raw data files
58 */
59 int main(int argc, char **argv) {
60
61   /* magic line from Rene */
62   gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
63                                         "*",
64                                         "TStreamerInfo",
65                                         "RIO",
66                                         "TStreamerInfo()");
67   
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 */
92   int nevents_total=0;
93   int nevents      =0;
94  
95   //Instance of AliCDBManager: needed by AliTRDRawStream
96   //AliCDBManager *man = AliCDBManager::Instance();
97   //man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
98   //man->SetRun(0);
99   // AliTRDCalibPadStatus object
100   AliTRDCalibPadStatus calipad = AliTRDCalibPadStatus();
101   Bool_t passpadstatus = kTRUE;
102   //unsigned long32 runNb=0;      //run number
103
104   // setting
105   AliTRDrawFastStream::DisableSkipData();
106  
107
108   /* read the data files */
109   int n;
110   for (n=1;n<argc;n++) {
111    
112     /* define data source : this is argument i */
113     printf("Processing file %s\n",argv[n]);
114     status=monitorSetDataSource( argv[n] );
115     if (status!=0) {
116       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
117       return -1;
118     }
119
120     /* read the file  until EOF */
121     for(;;) {
122       struct eventHeaderStruct *event;
123       eventTypeType eventT;
124       
125       /* get next event */
126       status=monitorGetEventDynamic((void **)&event);
127       if (status==MON_ERR_EOF) {
128         printf("End of File %d detected\n",n);
129         break; /* end of monitoring file has been reached */
130       }
131       if (status!=0) {
132         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
133         break;
134       }
135
136       /* retry if got no event */
137       if (event==NULL) {
138         break;
139       }
140
141       /* use event - here, just write event id to result file */
142       eventT=event->eventType;
143
144       if((eventT==PHYSICS_EVENT) && (passpadstatus)){
145
146         AliRawReader *rawReader = new AliRawReaderDate((void*)event);
147         rawReader->Select("TRD");
148         
149         Int_t result = calipad.ProcessEvent2((AliRawReader *) rawReader);
150         // 0 error, 1 no input, 2 output
151         if(result == 2) nevents++;
152         if(result == 0) passpadstatus = kFALSE;
153         delete rawReader;
154       
155       }
156
157       nevents_total++;
158
159       // get the run number
160       //runNb = event->eventRunNb;
161
162       /* free resources */
163       free(event);
164     }
165   }
166
167
168   /* report progress */
169   printf("%d events processed and %d used\n",nevents_total,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   /*
189
190   // send objects to AMORE
191   //SendToAmoreDB(calibpad,runNb);
192   
193   void SendToAmoreDB(TObject *calipad, unsigned long32 runNb)
194   {
195   //cheet a little -- temporary solution (hopefully)
196   //
197   //currently amoreDA uses the environment variable AMORE_DA_NAME to create the mysql
198   //table in which the calib objects are stored. This table is dropped each time AmoreDA
199   //is initialised. This of course makes a problem if we would like to store different
200   //calibration entries in the AMORE DB. Therefore in each DA which writes to the AMORE DB
201   //the AMORE_DA_NAME env variable is overwritten.
202   
203   
204   //
205   // The reference data are stored in:
206   // PadStatus1 for sm-00-01-02
207   // PadStatus2 for sm-03-04-05
208   // PadStatus3 for sm-06-07-08
209   // PadStatus4 for sm-09-10-11
210   // PadStatus5 for sm-12-13-14
211   // PadStatus6 for sm-15-16-17
212   // PadStatus0 if nothing found..means problems
213   //
214   
215   ///////////////////
216   // Find wich LDC
217   ///////////////////
218   Int_t ldcnumber = -1;
219   Int_t sm = -1;
220   for (Int_t idet=0; idet<540; idet++) {
221   AliTRDCalROC *rocMean  = calipad->GetCalRocMean(idet, kFALSE);
222     if ( rocMean )  {
223       sm  = AliTRDgeometry::GetSector(idet);  
224       if((sm==0) || (sm==1) || (sm==2)) ldcnumber = 1;
225       if((sm==3) || (sm==4) || (sm==5)) ldcnumber = 2;
226       if((sm==6) || (sm==7) || (sm==8)) ldcnumber = 3;
227       if((sm==9) || (sm==10) || (sm==11)) ldcnumber = 1;
228       if((sm==12) || (sm==13) || (sm==14)) ldcnumber = 2;
229       if((sm==15) || (sm==16) || (sm==17)) ldcnumber = 3;
230     }
231   }
232   const char *amoreDANameorig=gSystem->Getenv("AMORE_DA_NAME");
233   
234   gSystem->Setenv("AMORE_DA_NAME",Form("TRD-dataQA-%02d-%s",ldcnumber,FILE_ID));
235  
236   /////////////////////
237   // Send the stuff
238   ////////////////////
239   if (ldcnumber>-1){
240   TDatime time;
241   TObjString info(Form("Run: %u; Date: %s",runNb,time.AsSQLString()));
242   
243   amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
244   Int_t statusDA=0;
245   statusDA+=amoreDA.Send("Pedestals",calibpad);
246   statusDA+=amoreDA.Send("Info",&info);
247   if ( statusDA )
248   printf("Waring: Failed to write one of the calib objects to the AMORE database\n");
249   }  else {
250   printf("Waring: No data found!\n");
251   }
252   
253   // reset env var
254   if (amoreDANameorig) gSystem->Setenv("AMORE_DA_NAME",amoreDANameorig);
255   
256   }
257   
258   */
259
260
261
262 }
263