Stupid bug fix in new superlight mode (from Zurich airport)
[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) {
f510fd70 64 // main - Arguments: list of DATE raw data files
4c82df4c 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);
f2201323 119
4c82df4c 120 Int_t iev=0;
5065707f 121 Int_t ievInj=0;
f2201323 122 Int_t ievUsed=0;
123 Int_t nEvToBeSkipped=5;
124
4c82df4c 125 /* read the data files */
126 int n;
127 for (n=1;n<argc;n++) {
128
129 status=monitorSetDataSource( argv[n] );
130 if (status!=0) {
131 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
132 return -1;
133 }
134
135 /* report progress */
136 /* in this example, indexed on the number of files */
137 // Progress report inside the event loop as well?
138 daqDA_progressReport(10+80*n/argc);
139
140 /* read the file */
141 for(;;) {
142 struct eventHeaderStruct *event;
143 eventTypeType eventT;
144
145 /* get next event */
146 status=monitorGetEventDynamic((void **)&event);
147 if (status==MON_ERR_EOF) break; /* end of monitoring file has been reached */
148 if (status!=0) {
149 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
150 return -1;
151 }
4c82df4c 152 /* retry if got no event */
153 if (event==NULL) {
154 break;
155 }
5065707f 156 iev++;
4c82df4c 157
4c82df4c 158
159 /* use event - here, just write event id to result file */
160 eventT=event->eventType;
161 switch (event->eventType){
162
163 /* START OF RUN */
164 case START_OF_RUN:
165 break;
166
167 /* END OF RUN */
168 case END_OF_RUN:
169 break;
170
171 // case PHYSICS_EVENT: // comment this line for test raw data
172 // break; // comment this line for test raw data
173
174 case CALIBRATION_EVENT:
175 break; // uncomment this line for test raw data
176 case PHYSICS_EVENT: // uncomment this line for test raw data
f2201323 177 printf(" Event number = %i ",iev);
5065707f 178 ievInj++;
f2201323 179 if(ievInj<=nEvToBeSkipped){
180 printf(" -> SKIP\n");
181 break;
182 }
183 printf(" -> Analyze\n");
184 ievUsed++;
185
4c82df4c 186 AliRawReader *rawReader = new AliRawReaderDate((void*)event);
e5b2f7f2 187 timeSt=rawReader->GetTimestamp();
4c82df4c 188 rawReader->Reset();
040d0012 189 UChar_t cdhAttr=AliITSRawStreamSDD::ReadBlockAttributes(rawReader);
190 amSamplFreq=AliITSRawStreamSDD::ReadAMSamplFreqFromCDH(cdhAttr);
191 AliITSRawStream* s=AliITSRawStreamSDD::CreateRawStreamSDD(rawReader,cdhAttr);
192 if(!writtenoutput){
193 printf("Use %s raw stream, sampling frequency %d MHz\n",s->ClassName(),amSamplFreq);
194 writtenoutput=kTRUE;
195 }
979b5a5f 196 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
197 for(Int_t imod=0; imod<kModPerDDL;imod++){
198 for(Int_t isid=0;isid<kSides;isid++){
199 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
200 histo[index]->Reset();
201 }
4c82df4c 202 }
203 }
040d0012 204
a8cd2ab2 205 while(s->Next()){
979b5a5f 206 Int_t iDDL=rawReader->GetDDLID();
a8cd2ab2 207 Int_t iCarlos=s->GetCarlosId();
208 if(s->IsCompletedModule()) continue;
209 if(s->IsCompletedDDL()) continue;
de075dae 210 if(iDDL>=0 && iDDL<kTotDDL){
a8cd2ab2 211 Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel();
212 histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal());
979b5a5f 213 isFilled[index]=1;
4c82df4c 214 }
215 }
040d0012 216 delete s;
4c82df4c 217 delete rawReader;
040d0012 218
979b5a5f 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 if(isFilled[index]){
040d0012 224 if(amSamplFreq==20) injan[index]->Set20MHzConfig();
225 else injan[index]->Set40MHzConfig();
e5b2f7f2 226 injan[index]->AddEvent(histo[index]);
227 // injan[index]->WriteToASCII(iev,timeSt,nWrittenEv[index]);
979b5a5f 228 nWrittenEv[index]++;
229 }
230 }
4c82df4c 231 }
232 }
4c82df4c 233 /* free resources */
234 free(event);
235 }
f2201323 236 if(ievUsed>=maxNEvents) break;
4c82df4c 237 }
4c82df4c 238 }
456ec396 239
5065707f 240 /* write report */
e5b2f7f2 241 TDatime time;
242 TObjString timeinfo(Form("%02d%02d%02d%02d%02d%02d",time.GetYear()-2000,time.GetMonth(),time.GetDay(),time.GetHour(),time.GetMinute(),time.GetSecond()));
f2201323 243 printf("Run #%s, received %d calibration events, time %s\n",getenv("DATE_RUN_NUMBER"),ievUsed,timeinfo.GetString().Data());
e5b2f7f2 244
245 /* report progress */
246 daqDA_progressReport(90);
247 TObjArray* dspHistos=new TObjArray();
5065707f 248
e5b2f7f2 249
4c82df4c 250 Char_t filnam[100],command[120];
979b5a5f 251 for(Int_t iddl=0; iddl<kTotDDL;iddl++){
252 for(Int_t imod=0; imod<kModPerDDL;imod++){
253 for(Int_t isid=0;isid<kSides;isid++){
254 Int_t index=kSides*(kModPerDDL*iddl+imod)+isid;
255 if(nWrittenEv[index]>0){
e5b2f7f2 256 injan[index]->FitMeanDriftSpeedVsAnode();
257 injan[index]->WriteToASCII(0,timeSt,0);
7bbf1d41 258 injan[index]->WriteInjectorStatusToASCII();
e5b2f7f2 259 dspHistos->AddLast(injan[index]->GetMeanDriftSpeedVsPadHisto());
979b5a5f 260 sprintf(filnam,"SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid);
261 sprintf(command,"tar -rf SDDinj_LDC.tar %s",filnam);
262 gSystem->Exec(command);
263 }
264 }
265 }
4c82df4c 266 }
e5b2f7f2 267 status=daqDA_FES_storeFile("./SDDinj_LDC.tar","SDD_Injec");
4c82df4c 268
4c82df4c 269
e5b2f7f2 270#ifdef ALI_AMORE
271 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
9ce3c336 272 Int_t statusamore =0;
7f601ef8 273 statusamore += amoreDA.Send("TimeInfoInject",&timeinfo);
9ce3c336 274 statusamore += amoreDA.Send("DriftSpeed",dspHistos);
275 if ( statusamore )
e5b2f7f2 276 printf("Warning: Failed to write Arrays in the AMORE database\n");
277 else
278 printf("amoreDA.Send() OK\n");
279#else
280 printf("Warning: SDDINJ DA not compiled with AMORE support\n");
281#endif
282
283 TFile *fh=new TFile("SDDinjectHistos.root","RECREATE");
284 dspHistos->Write();
285 fh->Close();
4c82df4c 286
4c82df4c 287
288 /* report progress */
289 daqDA_progressReport(100);
290
291
292
293 return status;
294}