]>
Commit | Line | Data |
---|---|---|
62adef6c | 1 | /* |
2 | contact: Boris.Polishchuk@cern.ch | |
3 | link: see comments in the $ALICE_ROOT/PHOS/AliPHOSRcuDA1.cxx | |
4 | reference run: /castor/cern.ch/alice/phos/2007/10/04/18/07000008249001.1000.root | |
82127abf | 5 | run type: PHYSICS |
62adef6c | 6 | DA type: MON |
7 | number of events needed: 1000 | |
8 | input files: RCU0.data RCU1.data RCU2.data RCU3.data | |
9 | Output files: PHOS_Module2_Calib.root | |
82127abf | 10 | Trigger types used: PHYSICS |
62adef6c | 11 | */ |
12 | ||
13 | ||
14 | #include "event.h" | |
15 | #include "monitor.h" | |
16 | extern "C" { | |
17 | #include "daqDA.h" | |
18 | } | |
19 | ||
20 | #include <stdio.h> | |
21 | #include <stdlib.h> | |
22 | ||
23 | #include <TSystem.h> | |
c59c9912 | 24 | #include <TROOT.h> |
25 | #include <TPluginManager.h> | |
62adef6c | 26 | |
27 | #include "AliRawReader.h" | |
28 | #include "AliRawReaderDate.h" | |
29 | #include "AliPHOSRcuDA1.h" | |
8083e819 | 30 | #include "AliPHOSRawFitterv0.h" |
62adef6c | 31 | #include "AliCaloAltroMapping.h" |
8083e819 | 32 | #include "AliCaloRawStreamV3.h" |
62adef6c | 33 | |
34 | ||
35 | /* Main routine | |
36 | Arguments: | |
37 | 1- monitoring data source | |
38 | */ | |
39 | int main(int argc, char **argv) { | |
40 | ||
c59c9912 | 41 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", |
42 | "*", | |
43 | "TStreamerInfo", | |
44 | "RIO", | |
45 | "TStreamerInfo()"); | |
46 | ||
62adef6c | 47 | int status; |
48 | ||
49 | if (argc!=2) { | |
50 | printf("Wrong number of arguments\n"); | |
51 | return -1; | |
52 | } | |
c59c9912 | 53 | |
54 | /* Retrieve mapping files from DAQ DB */ | |
55 | const char* mapFiles[4] = {"RCU0.data","RCU1.data","RCU2.data","RCU3.data"}; | |
56 | ||
57 | for(Int_t iFile=0; iFile<4; iFile++) { | |
58 | int failed = daqDA_DB_getFile(mapFiles[iFile], mapFiles[iFile]); | |
59 | if(failed) { | |
60 | printf("Cannot retrieve file %s from DAQ DB. Exit.\n",mapFiles[iFile]); | |
61 | return -1; | |
62 | } | |
63 | } | |
62adef6c | 64 | |
65 | /* Open mapping files */ | |
66 | AliAltroMapping *mapping[4]; | |
67 | TString path = "./"; | |
68 | path += "RCU"; | |
69 | TString path2; | |
70 | for(Int_t i = 0; i < 4; i++) { | |
71 | path2 = path; | |
72 | path2 += i; | |
73 | path2 += ".data"; | |
74 | mapping[i] = new AliCaloAltroMapping(path2.Data()); | |
75 | } | |
76 | ||
62adef6c | 77 | /* define data source : this is argument 1 */ |
78 | status=monitorSetDataSource( argv[1] ); | |
79 | if (status!=0) { | |
80 | printf("monitorSetDataSource() failed : %s\n",monitorDecodeError(status)); | |
81 | return -1; | |
82 | } | |
83 | ||
84 | ||
85 | /* declare monitoring program */ | |
86 | status=monitorDeclareMp( __FILE__ ); | |
87 | if (status!=0) { | |
88 | printf("monitorDeclareMp() failed : %s\n",monitorDecodeError(status)); | |
89 | return -1; | |
90 | } | |
91 | ||
92 | ||
93 | /* define wait event timeout - 1s max */ | |
94 | monitorSetNowait(); | |
95 | monitorSetNoWaitNetworkTimeout(1000); | |
96 | ||
97 | /* init some counters */ | |
98 | int nevents_physics=0; | |
99 | int nevents_total=0; | |
100 | ||
101 | AliRawReader *rawReader = NULL; | |
102 | ||
103 | AliPHOSRcuDA1 da1(2,-1); // DA1 (Calibration DA) for module2 | |
104 | ||
105 | Float_t e[64][56][2]; | |
106 | Float_t t[64][56][2]; | |
107 | ||
8083e819 | 108 | Int_t gain = -1; |
109 | Int_t cellX = -1; | |
110 | Int_t cellZ = -1; | |
111 | Int_t nBunches = 0; | |
112 | Int_t sigStart, sigLength; | |
62adef6c | 113 | |
114 | /* main loop (infinite) */ | |
115 | for(;;) { | |
116 | struct eventHeaderStruct *event; | |
117 | eventTypeType eventT; | |
118 | ||
119 | /* check shutdown condition */ | |
120 | if (daqDA_checkShutdown()) {break;} | |
121 | ||
122 | /* get next event (blocking call until timeout) */ | |
123 | status=monitorGetEventDynamic((void **)&event); | |
124 | if (status==MON_ERR_EOF) { | |
125 | printf ("End of File detected\n"); | |
126 | break; /* end of monitoring file has been reached */ | |
127 | } | |
128 | ||
129 | if (status!=0) { | |
130 | printf("monitorGetEventDynamic() failed : %s\n",monitorDecodeError(status)); | |
131 | break; | |
132 | } | |
133 | ||
134 | /* retry if got no event */ | |
135 | if (event==NULL) { | |
136 | continue; | |
137 | } | |
138 | ||
139 | ||
140 | /* use event - here, just write event id to result file */ | |
141 | eventT=event->eventType; | |
142 | ||
143 | if (eventT==PHYSICS_EVENT) { | |
144 | ||
145 | for(Int_t iX=0; iX<64; iX++) { | |
146 | for(Int_t iZ=0; iZ<56; iZ++) { | |
147 | for(Int_t iGain=0; iGain<2; iGain++) { | |
148 | e[iX][iZ][iGain] = 0.; | |
149 | t[iX][iZ][iGain] = 0.; | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | rawReader = new AliRawReaderDate((void*)event); | |
8083e819 | 155 | AliCaloRawStreamV3 stream(rawReader,"PHOS",mapping); |
156 | AliPHOSRawFitterv0 fitter(); | |
157 | fitter.SubtractPedestals(kTRUE); // assume that data is non-ZS | |
62adef6c | 158 | |
8083e819 | 159 | while (stream.NextDDL()) { |
160 | while (stream.NextChannel()) { | |
161 | ||
162 | cellX = stream.GetCellX(); | |
163 | cellZ = stream.GetCellZ(); | |
164 | caloFlag = stream.GetCaloFlag(); // 0=LG, 1=HG, 2=TRU | |
165 | ||
166 | // In case of oscillating signals with ZS, a channel can have several bunches | |
167 | nBunches = 0; | |
168 | while (stream.NextBunch()) { | |
169 | nBunches++; | |
170 | if (nBunches > 1) continue; | |
171 | sigStart = fRawStream.GetStartTimeBin(); | |
172 | sigLength = fRawStream.GetBunchLength(); | |
173 | fitter.SetSamples(fRawStream->GetSignals(),sigStart,sigLength); | |
174 | } // End of NextBunch() | |
175 | ||
176 | fitter.SetNBunches(nBunches); | |
177 | fitter.SetChannelGeo(module,cellX,cellZ,caloFlag); | |
178 | fitter.Eval(); | |
179 | ||
180 | if (nBunches>1 || caloFlag!=0 || caloFlag!=1 || fitter.GetSignalQuality()>1) continue; | |
181 | ||
182 | e[cellX][cellZ][caloFlag] = fitter.GetEnergy(); | |
183 | t[cellX][cellZ][caloFlag] = fitter.GetTime(); | |
184 | } | |
62adef6c | 185 | } |
186 | ||
187 | da1.FillHistograms(e,t); | |
8083e819 | 188 | //da1.UpdateHistoFile(); |
62adef6c | 189 | |
190 | delete rawReader; | |
191 | nevents_physics++; | |
192 | } | |
193 | ||
194 | nevents_total++; | |
195 | ||
196 | /* free resources */ | |
197 | free(event); | |
198 | ||
199 | /* exit when last event received, no need to wait for TERM signal */ | |
200 | if (eventT==END_OF_RUN) { | |
201 | printf("EOR event detected\n"); | |
202 | break; | |
203 | } | |
204 | } | |
205 | ||
206 | for(Int_t i = 0; i < 4; i++) delete mapping[i]; | |
207 | ||
c59c9912 | 208 | /* Be sure that all histograms are saved */ |
209 | ||
210 | da1.UpdateHistoFile(); | |
211 | da1.SetWriteToFile(kFALSE); | |
212 | ||
213 | /* Store output files to the File Exchange Server */ | |
214 | char localfile[128]; | |
215 | ||
216 | for(Int_t iMod=0; iMod<5; iMod++) { | |
217 | sprintf(localfile,"PHOS_Module%d_Calib.root",iMod); | |
604fe52e | 218 | daqDA_FES_storeFile(localfile,"AMPLITUDES"); |
c59c9912 | 219 | } |
220 | ||
62adef6c | 221 | return status; |
222 | } |