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