]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/ITSSDDINJda.cxx
Fix problem in simulated raw data + code cleanup (F.Prino)
[u/mrichter/AliRoot.git] / ITS / ITSSDDINJda.cxx
1 //////////////////////////////////////////////////////////////////////////////
2 // Detector Algorithm for analysis of SDD injector events.                  //
3 //                                                                          //
4 // Produces ASCII output files with:                                        //
5 // 1. event number                                                          //
6 // 2. event timestamp                                                       //
7 // 3. Fit parameters of drift vel. vs. anode                                //
8 // Tar Files are written to FXS                                             //
9 //                                                                          //
10 // Author: F. Prino (prino@to.infn.it)                                      //
11 //                                                                          //
12 //////////////////////////////////////////////////////////////////////////////
13
14
15
16 extern "C" {
17 #include "daqDA.h"
18 }
19
20 #include "event.h"
21 #include "monitor.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 // ROOT includes
27 #include <TFile.h>
28 #include <TH1F.h>
29 #include <TH2F.h>
30 #include <TSystem.h>
31
32 // AliRoot includes
33 #include "AliRawReaderDate.h"
34 #include "AliITSOnlineSDDInjectors.h"
35 #include "AliITSRawStreamSDD.h"
36 /* Main routine
37       Arguments: list of DATE raw data files
38 */
39 int main(int argc, char **argv) {
40
41   int status = 0;
42
43
44   /* log start of process */
45   printf("ITS SDD INJ algorithm program started\n");  
46
47
48   /* check that we got some arguments = list of files */
49   if (argc<2) {
50     printf("Wrong number of arguments\n");
51     return -1;
52   }
53
54
55   Int_t eqOffset = 256;
56   Int_t DDLrange = 24;
57   Int_t maxNEvents=10; // maximum number of events to be analyzed
58   const Int_t nSDDmodules=12;  // temp for test raw data
59   AliITSOnlineSDDInjectors **injan=new AliITSOnlineSDDInjectors*[2*nSDDmodules];
60   TH2F **histo=new TH2F*[2*nSDDmodules];
61   Int_t nWrittenEv[2*nSDDmodules];
62
63   Char_t hisnam[20];
64   for(Int_t imod=0; imod<nSDDmodules;imod++){
65     for(Int_t isid=0;isid<2;isid++){
66       Int_t index=2*imod+isid;
67       injan[index]=new AliITSOnlineSDDInjectors(imod,isid);
68       sprintf(hisnam,"his%03ds%d",imod,isid);
69       histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
70       nWrittenEv[index]=0;
71     }
72   }
73   
74   /* report progress */
75   daqDA_progressReport(10);
76   Int_t iev=0;
77   /* read the data files */
78   int n;
79   for (n=1;n<argc;n++) {
80    
81     status=monitorSetDataSource( argv[n] );
82     if (status!=0) {
83       printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
84       return -1;
85     }
86
87     /* report progress */
88     /* in this example, indexed on the number of files */
89     // Progress report inside the event loop as well?
90     daqDA_progressReport(10+80*n/argc);
91
92     /* read the file */
93     for(;;) {
94       struct eventHeaderStruct *event;
95       eventTypeType eventT;
96
97       /* get next event */
98       status=monitorGetEventDynamic((void **)&event);
99       if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
100       if (status!=0) {
101         printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
102         return -1;
103       }
104
105       /* retry if got no event */
106       if (event==NULL) {
107         break;
108       }
109
110       iev++; 
111       if(iev>maxNEvents) break;
112       
113       /* use event - here, just write event id to result file */
114       eventT=event->eventType;
115       switch (event->eventType){
116         
117         /* START OF RUN */
118       case START_OF_RUN:
119         break;
120         
121         /* END OF RUN */
122       case END_OF_RUN:
123         break;
124         
125         //      case PHYSICS_EVENT:  // comment this line for test raw data
126         //      break;               // comment this line for test raw data
127
128       case CALIBRATION_EVENT:
129         break;  // uncomment this line for test raw data
130       case PHYSICS_EVENT: // uncomment this line for test raw data
131         printf(" event number = %i \n",iev);
132         AliRawReader *rawReader = new AliRawReaderDate((void*)event);
133         rawReader->RequireHeader(kFALSE);
134         rawReader->SelectEquipment(17,eqOffset+1,eqOffset+DDLrange);
135
136         UInt_t timeSt=rawReader->GetTimestamp();
137         //UInt_t timeSt=iev*5000+12;  // fake timestamp for test
138         Int_t evtyp=0;
139         while(rawReader->ReadHeader()){
140           const UInt_t *subev = rawReader->GetSubEventAttributes();
141           if(subev[0]==0 && subev[1]==0 && subev[2]==0) evtyp=1; 
142         }
143
144         rawReader->Reset();
145         for(Int_t imod=0; imod<nSDDmodules;imod++){
146           for(Int_t isid=0; isid<2;isid++){
147             Int_t index=2*imod+isid;
148             histo[index]->Reset();
149           }
150         }
151         AliITSRawStreamSDD s(rawReader);
152         
153         while(s.Next()){
154           Int_t iddl=rawReader->GetDDLID();
155           iddl=0; // temporary for test raw data
156           Int_t isddmod=s.GetModuleNumber(iddl,s.GetCarlosId()); 
157           isddmod-=240;  // to have SDD modules from 0 to 259
158           isddmod=s.GetCarlosId(); // temporary for test raw data
159           if(isddmod<nSDDmodules&&s.IsCompletedModule()==kFALSE){ 
160             Int_t index=2*isddmod+s.GetChannel(); 
161             histo[index]->Fill(s.GetCoord2(),s.GetCoord1(),s.GetSignal());
162           }
163         }
164         delete rawReader;
165         for(Int_t imod=0; imod<nSDDmodules;imod++){
166           for(Int_t isid=0; isid<2;isid++){
167             Int_t index=2*imod+isid;
168             injan[index]->Reset();
169             injan[index]->AnalyzeEvent(histo[index]);    
170             injan[index]->WriteToASCII(iev,timeSt,nWrittenEv[index]);
171             nWrittenEv[index]++;
172           }
173         }
174         
175         /* free resources */
176         free(event);
177       }
178     }
179     
180   }
181     
182   Char_t filnam[100],command[120];
183   for(Int_t imod=0; imod<nSDDmodules;imod++){
184     for(Int_t isid=0; isid<2;isid++){
185       sprintf(filnam,"SDDinj_mod%03d_sid%d.data",imod,isid);
186       sprintf(command,"tar -rf SDDinj_LDC1.tar %s",filnam);
187       gSystem->Exec(command);
188     }  
189   }
190
191   /* write report */
192   printf("Run #%s, received %d injector events\n",getenv("DATE_RUN_NUMBER"),iev);
193
194   /* report progress */
195   daqDA_progressReport(90);
196
197
198   status=daqDA_FES_storeFile("./SDDinj_LDC1.tar","SDD_Calib");
199
200   /* report progress */
201   daqDA_progressReport(100);
202
203
204
205   return status;
206 }