]> git.uio.no Git - u/mrichter/AliRoot.git/blame - T0/T0Physda.cxx
new version of SSD DA and related classes (O. Borysov)
[u/mrichter/AliRoot.git] / T0 / T0Physda.cxx
CommitLineData
99194e07 1//extern "C"
2
3#include <daqDA.h>
4
5#include <event.h>
6#include <monitor.h>
7
8#include <Riostream.h>
9#include <stdio.h>
10#include <stdlib.h>
11
12//AliRoot
13#include <AliRawReaderDate.h>
14#include <AliRawReader.h>
15#include <AliT0RawReader.h>
16#include <AliCDBManager.h>
17
18//ROOT
19#include "TFile.h"
20#include "TKey.h"
21#include "TH2S.h"
22#include "TObject.h"
23#include "TBenchmark.h"
24#include "TRandom.h"
25
26#include "TCanvas.h"
27#include "TString.h"
28#include "TH1.h"
29#include "TF1.h"
30#include "TSpectrum.h"
31#include "TVirtualFitter.h"
32
33
34
35/* Main routine
36 Arguments:
37 1- monitoring data source
38*/
39int main(int argc, char **argv) {
40//int main(){
41 int status;
42
43
44 if (argc!=2) {
45 printf("Wrong number of arguments\n");
46 return -1;
47 }
48
49
50 /* define data source : this is argument 1 */
51 status=monitorSetDataSource( argv[1] );
52 if (status!=0) {
53 printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status));
54 return -1;
55 }
56
57
58 /* declare monitoring program */
59 status=monitorDeclareMp( __FILE__ );
60 if (status!=0) {
61 printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status));
62 return -1;
63 }
64
65
66 /* define wait event timeout - 1s max */
67 monitorSetNowait();
68 monitorSetNoWaitNetworkTimeout(1000);
69
70
71 /* log start of process */
72 printf("T0 monitoring program started\n");
73
74 // Allocation of histograms - start
75
76 TH1F *hCFD1_CFD[24];
77 TH1F *hCFD[24];
78 Char_t buf1[15], buf2[15],buf3[15],buf4[15];
79
80 for(Int_t ic=0; ic<24; ic++) {
81 if(ic<12) {
82 sprintf(buf1,"CFD1-CFD%i",ic+1);
83 hCFD1_CFD[ic] = new TH1F(buf1,"CFD-CFD",200000,-100000,100000);
84 sprintf(buf3,"CFD%i",ic+1);
85 hCFD[ic] = new TH1F(buf3,"CFD",100000,0,100000);
86 }
87 if(ic>11){
88 sprintf(buf2,"CFD13-CFD%i",ic+1);
89 hCFD1_CFD[ic] = new TH1F(buf2,"CFD-CFD",200000,-100000,100000);
90 sprintf(buf4,"CFD%i",ic+1);
91 hCFD[ic] = new TH1F(buf4,"CFD",100000,0,100000);
92 }
93 }
94
95 // Allocation of histograms - end
96
97 Int_t iev=0;
98 /* main loop (infinite) */
99 for(;;) {
100 struct eventHeaderStruct *event;
101 eventTypeType eventT;
102
103 /* check shutdown condition */
104 if (daqDA_checkShutdown()) {break;}
105
106 /* get next event (blocking call until timeout) */
107 status=monitorGetEventDynamic((void **)&event);
108 if (status==(int)MON_ERR_EOF) {
109 printf ("End of File detected\n");
110 break; /* end of monitoring file has been reached */
111 }
112
113 if (status!=0) {
114 printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status));
115 break;
116 }
117
118 /* retry if got no event */
119 if (event==NULL) {
120 continue;
121 }
122
123 iev++;
124
125 /* use event - here, just write event id to result file */
126 eventT=event->eventType;
127
128 switch (event->eventType){
129
130 case START_OF_RUN:
131 break;
132
133 case END_OF_RUN:
134 break;
135
136 case PHYSICS_EVENT:
137 printf(" event number = %i \n",iev);
138
139
140 // Initalize raw-data reading and decoding
141 AliRawReader *reader = new AliRawReaderDate((void*)event);
142
143 // Enable the following two lines in case of real-data
144 // reader->LoadEquipmentIdsMap("T0map.txt");
145 // reader->RequireHeader(kFALSE);
146 // reader->RequireHeader(kTRUE);
147 AliT0RawReader *start = new AliT0RawReader(reader, kTRUE);
148
149 // Read raw data
150 Int_t allData[105][5];
151 for(Int_t i0=0;i0<105;i0++)
152 for(Int_t j0=0;j0<5;j0++)
153 allData[i0][j0] = 0;
154
155
156 if(start->Next())
157 for (Int_t i=0; i<105; i++) {
158 for(Int_t iHit=0;iHit<5;iHit++){
159 allData[i][iHit]= start->GetData(i,iHit);
160 }
161 }
162 else
163 printf("No T0 data found!!\n");
164
165 // Fill the histograms
166
167 for (Int_t ik = 0; ik<24; ik+=2)
168 for (Int_t iHt=0; iHt<5; iHt++){
169 Int_t cc = ik/2;
170 if(allData[cc+1][iHt]!=0 ){
171 hCFD1_CFD[cc]->Fill(allData[cc+1][iHt]-allData[1][iHt]);
172 hCFD[cc]->Fill(allData[cc+13][iHt]);
173 }
174 }
175
176 for (Int_t ik = 24; ik<48; ik+=2)
177 for (Int_t iHt=0; iHt<5; iHt++){
178 Int_t cc = ik/2;
179 if(allData[cc+45][iHt]!=0 ){
180 hCFD1_CFD[cc]->Fill(allData[cc+45][iHt]-allData[57][iHt]);
181 hCFD[cc]->Fill(allData[cc+45][iHt]);
182 }
183 }
184
185 delete start;
186 start = 0x0;
187 reader->Reset();
188 // End of fill histograms
189
190 }
191
192
193
194 /* free resources */
195 free(event);
196
197 /* exit when last event received, no need to wait for TERM signal */
198 if (eventT==END_OF_RUN) {
199 printf("EOR event detected\n");
200 break;
201 }
202 }
203printf("After loop, before writing histos\n");
204 // write a file with the histograms
205 Char_t filehist[21];
206 sprintf(filehist,"daPhys.root");
207 TFile *hist = new TFile(filehist,"RECREATE");
208
209 for(Int_t j=0;j<24;j++){
210 hCFD1_CFD[j]->Write();
211 hCFD[j]->Write();
212 }
213 hist->Close();
214 delete hist;
215
216 return status;
217}
218
219