]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/ITSSDDGAINda.cxx
AliITSHandleDaSSD requires DATE
[u/mrichter/AliRoot.git] / ITS / ITSSDDGAINda.cxx
CommitLineData
00252d8f 1/*
2- Contact: - prino@to.infn.it
4a9f3efb 3- Link: - alien:///alice/data/2009/LHC09c_SDD/000079095/raw/09000079095024.10.root
1ccdd571 4- Run Type: - PULSER_RUN
00252d8f 5- DA Type: - LDC
e5b2f7f2 6- Number of events needed: >15
4a9f3efb 7- Input Files: - SDDbase_step1_ddl*c*_sid*.data (output of previous PEDESTAL run)
979b5a5f 8- Output Files: - SDDbase_ddl*c*_sid*.data
00252d8f 9- Trigger types used:
10*/
11
3083967f 12//////////////////////////////////////////////////////////////////////////////
13// Detector Algorithm for analysis of SDD test pulse runs. //
14// //
15// Produces ASCII and ROOT output files with: //
16// 1. anode quality bit //
17// 1. Baseline values //
18// 2. Raw noise //
19// 3. Common mode coefficients //
20// 4. Noise corrected for common mode //
21// 5. Gain //
22// Files are written to FXS //
23// //
24// Author: F. Prino (prino@to.infn.it) //
25// //
26//////////////////////////////////////////////////////////////////////////////
27
28
29
30extern "C" {
31#include "daqDA.h"
32}
33
34#include "event.h"
35#include "monitor.h"
36
37#include <stdio.h>
38#include <stdlib.h>
39
40// ROOT includes
41#include <TFile.h>
42#include <TH1F.h>
43#include <TH2F.h>
44#include <TSystem.h>
00252d8f 45#include <TROOT.h>
46#include <TPluginManager.h>
e5b2f7f2 47#include <TObjArray.h>
48#include <TObjString.h>
49#include <TDatime.h>
3083967f 50
51// AliRoot includes
52#include "AliRawReaderDate.h"
53#include "AliITSOnlineSDDTP.h"
54#include "AliITSRawStreamSDD.h"
a8cd2ab2 55#include "AliITSRawStreamSDDCompressed.h"
e5b2f7f2 56
57#ifdef ALI_AMORE
58#include <AmoreDA.h>
59#endif
3083967f 60/* Main routine
61 Arguments: list of DATE raw data files
62*/
63int main(int argc, char **argv) {
f510fd70 64 // main - Arguments: list of DATE raw data files
3083967f 65 int status = 0;
66
00252d8f 67 // line added to solve IO problems
68 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
69 "*",
70 "TStreamerInfo",
71 "RIO",
72 "TStreamerInfo()");
3083967f 73
74 /* log start of process */
979b5a5f 75 printf("ITS SDD TEST-PULSE algorithm program started\n");
3083967f 76
77
78 /* check that we got some arguments = list of files */
79 if (argc<2) {
80 printf("Wrong number of arguments\n");
81 return -1;
82 }
83
84
1ccdd571 85 Int_t maxNEvents=15; // maximum number of events to be analyzed
979b5a5f 86 const Int_t kTotDDL=24;
87 const Int_t kModPerDDL=12;
88 const Int_t kSides=2;
040d0012 89 UInt_t amSamplFreq=40;
90 UChar_t cdhAttr=0;
91
5065707f 92 gSystem->Exec("rm -f SDDbase_LDC.tar");
979b5a5f 93
94 AliITSOnlineSDDTP **tpan=new AliITSOnlineSDDTP*[kTotDDL*kModPerDDL*kSides];
95 TH2F **histo=new TH2F*[kTotDDL*kModPerDDL*kSides];
96 Bool_t isFilled[kTotDDL*kModPerDDL*kSides];
040d0012 97 Bool_t writtenoutput=kFALSE;
3083967f 98 Char_t hisnam[20];
979b5a5f 99 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
100 for(Int_t imod=0; imod<kModPerDDL;imod++){
101 for(Int_t isid=0;isid<kSides;isid++){
102 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
103 tpan[index]=new AliITSOnlineSDDTP(iddl,imod,isid,100.);
104 sprintf(hisnam,"h%02dc%02ds%d",iddl,imod,isid);
105 histo[index]=new TH2F(hisnam,"",256,-0.5,255.5,256,-0.5,255.5);
106 isFilled[index]=0;
107 }
3083967f 108 }
109 }
110
111 /* report progress */
112 daqDA_progressReport(10);
f2201323 113
114 Int_t iev=0;
115 Int_t ievPul=0;
116 Int_t ievUsed=0;
117 Int_t nEvToBeSkipped=5;
118
3083967f 119 /* read the data files */
120 int n;
121 for (n=1;n<argc;n++) {
122
123 status=monitorSetDataSource( argv[n] );
124 if (status!=0) {
125 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
126 return -1;
127 }
128
129 /* report progress */
130 /* in this example, indexed on the number of files */
131 // Progress report inside the event loop as well?
132 daqDA_progressReport(10+80*n/argc);
133
134 /* read the file */
135 for(;;) {
136 struct eventHeaderStruct *event;
137 eventTypeType eventT;
138
139 /* get next event */
140 status=monitorGetEventDynamic((void **)&event);
141 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
142 if (status!=0) {
143 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
144 return -1;
145 }
146
147 /* retry if got no event */
148 if (event==NULL) {
149 break;
150 }
151
152 iev++;
3083967f 153
154 /* use event - here, just write event id to result file */
155 eventT=event->eventType;
156 switch (event->eventType){
157
158 /* START OF RUN */
159 case START_OF_RUN:
160 break;
161
162 /* END OF RUN */
163 case END_OF_RUN:
164 break;
165
166 // case PHYSICS_EVENT: // comment this line for test raw data
167 // break; // comment this line for test raw data
168
169 case CALIBRATION_EVENT:
170 break; // uncomment this line for test raw data
171 case PHYSICS_EVENT: // uncomment this line for test raw data
f2201323 172 printf(" Event number = %i ",iev);
173 ievPul++;
174 if(ievPul<=nEvToBeSkipped){
175 printf(" -> SKIP\n");
176 break;
177 }
178 printf(" -> Analyze\n");
179 ievUsed++;
180
3083967f 181 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
040d0012 182 rawReader->Reset();
183 cdhAttr=AliITSRawStreamSDD::ReadBlockAttributes(rawReader);
184 amSamplFreq=AliITSRawStreamSDD::ReadAMSamplFreqFromCDH(cdhAttr);
185 AliITSRawStream* s=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader,cdhAttr);
186 if(!writtenoutput){
187 printf("Use %s raw stream, sampling frequency %d MHz\n",s->ClassName(),amSamplFreq);
188 writtenoutput=kTRUE;
3083967f 189 }
190
979b5a5f 191 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
192 for(Int_t imod=0; imod<kModPerDDL;imod++){
193 for(Int_t isid=0;isid<kSides;isid++){
194 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
195 histo[index]->Reset();
196 }
3083967f 197 }
198 }
040d0012 199
a8cd2ab2 200 while(s->Next()){
979b5a5f 201 Int_t iDDL=rawReader->GetDDLID();
a8cd2ab2 202 Int_t iCarlos=s->GetCarlosId();
203 if(s->IsCompletedModule()) continue;
204 if(s->IsCompletedDDL()) continue;
de075dae 205 if(iDDL>=0 && iDDL<kTotDDL){
a8cd2ab2 206 Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel();
207 histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal());
1ccdd571 208 isFilled[index]=1;
3083967f 209 }
210 }
040d0012 211 delete s;
3083967f 212 delete rawReader;
979b5a5f 213 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
214 for(Int_t imod=0; imod<kModPerDDL;imod++){
215 for(Int_t isid=0;isid<kSides;isid++){
216 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
040d0012 217 if(amSamplFreq==20) tpan[index]->SetLastGoodTB(126);
218 else tpan[index]->SetLastGoodTB(254);
979b5a5f 219 if(isFilled[index]) tpan[index]->AddEvent(histo[index]);
220 }
3083967f 221 }
222 }
223
224 /* free resources */
225 free(event);
226 }
f2201323 227 if(ievUsed>=maxNEvents) break;
228 }
3083967f 229 }
230
e5b2f7f2 231 /* write report */
232 TDatime time;
233 TObjString timeinfo(Form("%02d%02d%02d%02d%02d%02d",time.GetYear()-2000,time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()));
f2201323 234 printf("Run #%s, received %d calibration events, time %s\n",getenv("DATE_RUN_NUMBER"),ievUsed,timeinfo.GetString().Data());
e5b2f7f2 235
236 /* report progress */
237 daqDA_progressReport(90);
238
239 TObjArray* gainHistos=new TObjArray();
240 TObjArray* statusHistos=new TObjArray();
241
3083967f 242 Char_t filnam[100],command[120];
979b5a5f 243 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
244 for(Int_t imod=0; imod<kModPerDDL;imod++){
245 for(Int_t isid=0;isid<kSides;isid++){
246 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
247 if(isFilled[index]){
248 tpan[index]->ValidateAnodes();
249 tpan[index]->WriteToASCII();
e5b2f7f2 250 gainHistos->AddLast(tpan[index]->GetGainAnodeHisto());
251 statusHistos->AddLast(tpan[index]->GetStatusAnodeHisto());
979b5a5f 252 sprintf(filnam,"SDDbase_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
253 sprintf(command,"tar -rf SDDbase_LDC.tar %s",filnam);
254 gSystem->Exec(command);
255 }
1ccdd571 256 }
3083967f 257 }
258 }
e5b2f7f2 259
3083967f 260
040d0012 261 FILE *conffil=fopen("fee.conf","w");
262 fprintf(conffil,"%d\n",amSamplFreq);
263 fprintf(conffil,"%02X\n",cdhAttr);
264 fclose(conffil);
265 gSystem->Exec("tar -rf SDDbase_LDC.tar fee.conf");
e5b2f7f2 266 status=daqDA_FES_storeFile("./SDDbase_LDC.tar","SDD_Calib");
040d0012 267
268
e5b2f7f2 269#ifdef ALI_AMORE
270 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
9ce3c336 271 Int_t statusamore =0;
7f601ef8 272 statusamore += amoreDA.Send("TimeInfoPulser",&timeinfo);
9ce3c336 273 statusamore += amoreDA.Send("Gain",gainHistos);
9ce3c336 274 if ( statusamore )
e5b2f7f2 275 printf("Warning: Failed to write Arrays in the AMORE database\n");
276 else
277 printf("amoreDA.Send() OK\n");
278#else
279 printf("Warning: SDDGAIN DA not compiled with AMORE support\n");
280#endif
281
282
283 TFile *fh=new TFile("SDDgainHistos.root","RECREATE");
284 gainHistos->Write();
285 statusHistos->Write();
3083967f 286 fh->Close();
287
288
3083967f 289 /* report progress */
290 daqDA_progressReport(100);
291
292
293
294 return status;
295}