]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/ITSSDDBASda.cxx
Changes to obey coding conventions
[u/mrichter/AliRoot.git] / ITS / ITSSDDBASda.cxx
CommitLineData
00252d8f 1/*
2- Contact: - prino@to.infn.it
f2c71038 3- Link: - http://www.to.infn.it/~prino/alice/RawData/run11161.date
4- Run Type: - PEDESTAL_RUN
00252d8f 5- DA Type: - LDC
6- Number of events needed: 100
7- Input Files: -
979b5a5f 8- Output Files: - SDDbase_step1_ddl*c*_sid*.data SDDbase_step2_ddl*c*_sid*.data
00252d8f 9- Trigger types used:
10*/
11
12
e44f571c 13//////////////////////////////////////////////////////////////////////////////
14// Detector Algorithm for analysis of SDD baseline runs. //
15// //
16// Produces ASCII and ROOT output files with: //
17// 1. anode quality bit //
18// 1. Baseline values //
19// 2. Raw noise //
20// 3. Common mode coefficients //
21// 4. Noise corrected for common mode //
22// Files are stored locally. //
23// The next DAQ-DA step on Test Pulse run writes files to FXS //
24// //
25// Author: F. Prino (prino@to.infn.it) //
26// //
27//////////////////////////////////////////////////////////////////////////////
28
29
30
31extern "C" {
32#include "daqDA.h"
33}
34
35#include "event.h"
36#include "monitor.h"
37
38#include <stdio.h>
39#include <stdlib.h>
40
41// ROOT includes
42#include <TFile.h>
43#include <TH1F.h>
44#include <TH2F.h>
00252d8f 45#include <TROOT.h>
46#include <TPluginManager.h>
e44f571c 47
48// AliRoot includes
49#include "AliRawReaderDate.h"
50#include "AliITSOnlineSDDBase.h"
51#include "AliITSOnlineSDDCMN.h"
52#include "AliITSRawStreamSDD.h"
53/* Main routine
54 Arguments: list of DATE raw data files
55*/
56int main(int argc, char **argv) {
57
58 int status = 0;
59
00252d8f 60 // line added to solve IO problems
61 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
62 "*",
63 "TStreamerInfo",
64 "RIO",
65 "TStreamerInfo()");
e44f571c 66
67 /* log start of process */
979b5a5f 68 printf("ITS SDD BASELINE+NOISE algorithm program started\n");
e44f571c 69
70
71 /* check that we got some arguments = list of files */
72 if (argc<2) {
73 printf("Wrong number of arguments\n");
74 return -1;
75 }
76
77
f2c71038 78 Int_t maxNEvents=18; // maximum number of events to be analyzed
979b5a5f 79 const Int_t kTotDDL=24;
80 const Int_t kModPerDDL=12;
81 const Int_t kSides=2;
82 AliITSOnlineSDDBase **base=new AliITSOnlineSDDBase*[kTotDDL*kModPerDDL*kSides];
83 AliITSOnlineSDDCMN **corr=new AliITSOnlineSDDCMN*[kTotDDL*kModPerDDL*kSides];
84 TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides];
e44f571c 85
86 Char_t hisnam[20];
979b5a5f 87 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
88 for(Int_t imod=0; imod<kModPerDDL;imod++){
89 for(Int_t isid=0;isid<kSides;isid++){
90 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
91 base[index]=new AliITSOnlineSDDBase(iddl,imod,isid);
92 sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid);
93 histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
94 }
e44f571c 95 }
96 }
97
98 /* report progress */
3083967f 99 daqDA_progressReport(8);
e44f571c 100 Int_t iev;
101 for(Int_t iStep=0;iStep<2;iStep++){
e44f571c 102 printf("Start Analysis Step %d\n",iStep);
103 iev=0;
104 if(iStep==1){
979b5a5f 105 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
106 for(Int_t imod=0; imod<kModPerDDL;imod++){
107 for(Int_t isid=0;isid<kSides;isid++){
108 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
109 corr[index]=new AliITSOnlineSDDCMN(iddl,imod,isid);
110 }
e44f571c 111 }
112 }
113 }
114
115 /* read the data files */
116 int n;
117 for (n=1;n<argc;n++) {
118
119 status=monitorSetDataSource( argv[n] );
120 if (status!=0) {
121 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
122 return -1;
123 }
124
125 /* report progress */
126 /* in this example, indexed on the number of files */
127 // Progress report inside the event loop as well?
3083967f 128 daqDA_progressReport(10+40*iStep*n/argc);
e44f571c 129
130 /* read the file */
131 for(;;) {
132 struct eventHeaderStruct *event;
133 eventTypeType eventT;
134
135 /* get next event */
136 status=monitorGetEventDynamic((void **)&event);
137 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
138 if (status!=0) {
139 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
140 return -1;
141 }
142
143 /* retry if got no event */
144 if (event==NULL) {
145 break;
146 }
147
148 iev++;
3083967f 149 if(iev>maxNEvents) break;
e44f571c 150
151 /* use event - here, just write event id to result file */
152 eventT=event->eventType;
153 switch (event->eventType){
154
155 /* START OF RUN */
156 case START_OF_RUN:
157 break;
158
159 /* END OF RUN */
160 case END_OF_RUN:
161 break;
162
3083967f 163 // case PHYSICS_EVENT: // comment this line for test raw data
164 // break; // comment this line for test raw data
165
e44f571c 166
167 case CALIBRATION_EVENT:
3083967f 168 break; // uncomment this line for test raw data
169 case PHYSICS_EVENT: // uncomment this line for test raw data
e44f571c 170 printf(" event number = %i \n",iev);
171 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
e44f571c 172
e44f571c 173
174 Int_t evtyp=0;
175 while(rawReader->ReadHeader()){
176 const UInt_t *subev = rawReader->GetSubEventAttributes();
177 if(subev[0]==0 && subev[1]==0 && subev[2]==0) evtyp=1;
178 }
179
180 rawReader->Reset();
979b5a5f 181 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
182 for(Int_t imod=0; imod<kModPerDDL;imod++){
183 for(Int_t isid=0;isid<kSides;isid++){
184 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
185 histo[index]->Reset();
186 }
e44f571c 187 }
188 }
189 AliITSRawStreamSDD s(rawReader);
e44f571c 190
191 while(s.Next()){
979b5a5f 192 Int_t iDDL=rawReader->GetDDLID();
193 Int_t iCarlos=s.GetCarlosId();
de075dae 194 if(s.IsCompletedModule()) continue;
195 if(s.IsCompletedDDL()) continue;
196 if(iDDL>=0 && iDDL<kTotDDL){
979b5a5f 197 Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s.GetChannel();
e44f571c 198 histo[index]->Fill(s.GetCoord2(),s.GetCoord1(),s.GetSignal());
199 }
200 }
201 delete rawReader;
979b5a5f 202 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
203 for(Int_t imod=0; imod<kModPerDDL;imod++){
204 for(Int_t isid=0;isid<kSides;isid++){
205 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
206 if(iStep==0) base[index]->AddEvent(histo[index]);
207 if(iStep==1) corr[index]->AddEvent(histo[index]);
208 }
e44f571c 209 }
210 }
211
212 /* free resources */
213 free(event);
214 }
215 }
e44f571c 216 }
979b5a5f 217
218 if(iStep==0){
219 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
220 for(Int_t imod=0; imod<kModPerDDL;imod++){
221 for(Int_t isid=0;isid<kSides;isid++){
222 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
223 base[index]->ValidateAnodes();
224 base[index]->WriteToASCII();
225 }
e44f571c 226 }
979b5a5f 227 }
228 }
e44f571c 229 }
230
231 /* write report */
232 printf("Run #%s, received %d calibration events\n",getenv("DATE_RUN_NUMBER"),iev);
233
234 /* report progress */
235 daqDA_progressReport(90);
236
237
238
3083967f 239 TFile *fh=new TFile("SDDbaseHistos.root","RECREATE");
979b5a5f 240 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
241 for(Int_t imod=0; imod<kModPerDDL;imod++){
242 for(Int_t isid=0;isid<kSides;isid++){
243 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
244 corr[index]->ValidateAnodes();
245 corr[index]->WriteToASCII();
246 corr[index]->WriteToROOT(fh);
247 }
e44f571c 248 }
249 }
250 fh->Close();
251
252
e44f571c 253 /* report progress */
254 daqDA_progressReport(100);
255
256
257
258 return status;
259}