]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | - Contact: - prino@to.infn.it | |
3 | - Link: - | |
4 | - Run Type: - INJECTOR | |
5 | - DA Type: - LDC | |
6 | - Number of events needed: >20 | |
7 | - Input Files: - | |
8 | - Output Files: - SDDinj_ddl*c*_sid*.data | |
9 | - Trigger types used: | |
10 | */ | |
11 | ||
12 | ||
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 | ||
28 | extern "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> | |
43 | #include <TROOT.h> | |
44 | #include <TPluginManager.h> | |
45 | #include <TObjArray.h> | |
46 | #include <TObjString.h> | |
47 | #include <TDatime.h> | |
48 | ||
49 | ||
50 | // AliRoot includes | |
51 | #include "AliRawReaderDate.h" | |
52 | #include "AliITSOnlineSDDInjectors.h" | |
53 | #include "AliITSRawStreamSDD.h" | |
54 | #include "AliITSRawStreamSDDCompressed.h" | |
55 | ||
56 | #ifdef ALI_AMORE | |
57 | #include <AmoreDA.h> | |
58 | #endif | |
59 | ||
60 | /* Main routine | |
61 | Arguments: list of DATE raw data files | |
62 | */ | |
63 | int main(int argc, char **argv) { | |
64 | ||
65 | int status = 0; | |
66 | ||
67 | ||
68 | // line added to solve IO problems | |
69 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
70 | "*", | |
71 | "TStreamerInfo", | |
72 | "RIO", | |
73 | "TStreamerInfo()"); | |
74 | ||
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 | ||
86 | Int_t maxNEvents=20; // maximum number of events to be analyzed | |
87 | const Int_t kTotDDL=24; | |
88 | const Int_t kModPerDDL=12; | |
89 | const Int_t kSides=2; | |
90 | Int_t amSamplFreq=40; | |
91 | ||
92 | gSystem->Exec("rm -f SDDinj_ddl*.data"); | |
93 | gSystem->Exec("rm -f SDDinj_LDC.tar"); | |
94 | ||
95 | ||
96 | ||
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]; | |
101 | Bool_t writtenoutput=kFALSE; | |
102 | UInt_t timeSt=0; | |
103 | Char_t hisnam[20]; | |
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 | } | |
114 | } | |
115 | } | |
116 | ||
117 | /* report progress */ | |
118 | daqDA_progressReport(10); | |
119 | Int_t iev=0; | |
120 | Int_t ievInj=0; | |
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 | } | |
148 | /* retry if got no event */ | |
149 | if (event==NULL) { | |
150 | break; | |
151 | } | |
152 | iev++; | |
153 | ||
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); | |
174 | ievInj++; | |
175 | AliRawReader *rawReader = new AliRawReaderDate((void*)event); | |
176 | timeSt=rawReader->GetTimestamp(); | |
177 | rawReader->Reset(); | |
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 | } | |
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 | } | |
191 | } | |
192 | } | |
193 | ||
194 | while(s->Next()){ | |
195 | Int_t iDDL=rawReader->GetDDLID(); | |
196 | Int_t iCarlos=s->GetCarlosId(); | |
197 | if(s->IsCompletedModule()) continue; | |
198 | if(s->IsCompletedDDL()) continue; | |
199 | if(iDDL>=0 && iDDL<kTotDDL){ | |
200 | Int_t index=kSides*(kModPerDDL*iDDL+iCarlos)+s->GetChannel(); | |
201 | histo[index]->Fill(s->GetCoord2(),s->GetCoord1(),s->GetSignal()); | |
202 | isFilled[index]=1; | |
203 | } | |
204 | } | |
205 | delete s; | |
206 | delete rawReader; | |
207 | ||
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]){ | |
213 | if(amSamplFreq==20) injan[index]->Set20MHzConfig(); | |
214 | else injan[index]->Set40MHzConfig(); | |
215 | injan[index]->AddEvent(histo[index]); | |
216 | // injan[index]->WriteToASCII(iev,timeSt,nWrittenEv[index]); | |
217 | nWrittenEv[index]++; | |
218 | } | |
219 | } | |
220 | } | |
221 | } | |
222 | /* free resources */ | |
223 | free(event); | |
224 | } | |
225 | if(ievInj>=maxNEvents) break; | |
226 | } | |
227 | } | |
228 | ||
229 | /* write report */ | |
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(); | |
237 | ||
238 | ||
239 | Char_t filnam[100],command[120]; | |
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){ | |
245 | injan[index]->FitMeanDriftSpeedVsAnode(); | |
246 | injan[index]->WriteToASCII(0,timeSt,0); | |
247 | dspHistos->AddLast(injan[index]->GetMeanDriftSpeedVsPadHisto()); | |
248 | sprintf(filnam,"SDDinj_ddl%02dc%02d_sid%d.data",iddl,imod,isid); | |
249 | sprintf(command,"tar -rf SDDinj_LDC.tar %s",filnam); | |
250 | gSystem->Exec(command); | |
251 | } | |
252 | } | |
253 | } | |
254 | } | |
255 | status=daqDA_FES_storeFile("./SDDinj_LDC.tar","SDD_Injec"); | |
256 | ||
257 | ||
258 | #ifdef ALI_AMORE | |
259 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); | |
260 | Int_t statusamore =0; | |
261 | statusamore += amoreDA.Send("TimeInfoInject",&timeinfo); | |
262 | statusamore += amoreDA.Send("DriftSpeed",dspHistos); | |
263 | if ( statusamore ) | |
264 | printf("Warning: Failed to write Arrays in the AMORE database\n"); | |
265 | else | |
266 | printf("amoreDA.Send() OK\n"); | |
267 | #else | |
268 | printf("Warning: SDDINJ DA not compiled with AMORE support\n"); | |
269 | #endif | |
270 | ||
271 | TFile *fh=new TFile("SDDinjectHistos.root","RECREATE"); | |
272 | dspHistos->Write(); | |
273 | fh->Close(); | |
274 | ||
275 | ||
276 | /* report progress */ | |
277 | daqDA_progressReport(100); | |
278 | ||
279 | ||
280 | ||
281 | return status; | |
282 | } |