]>
Commit | Line | Data |
---|---|---|
2825ba79 | 1 | /* |
2 | MCH DA for online occupancy | |
3 | ||
4 | Contact: Laurent Aphecetche <laurent.aphecetche@subatech.in2p3.fr>, Jean-Luc Charvet <jean-luc.charvet@cea.fr>, Alberto Baldisseri <alberto.baldisseri@cea.fr> | |
5 | Link: | |
6 | Run Type: PHYSICS STANDALONE | |
7 | DA Type: MON | |
8 | Number of events needed: all (or at least as much as possible...) | |
be9b25ed | 9 | Input Files: 09000094301009.10.raw |
2825ba79 | 10 | Output Files: mch.occupancy, to be exported to the DAQ FXS |
11 | Trigger types used: PHYSICS_EVENT | |
12 | */ | |
13 | ||
14 | /************************************************************************** | |
15 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
16 | * * | |
17 | * Author: The ALICE Off-line Project. * | |
18 | * Contributors are mentioned in the code where appropriate. * | |
19 | * * | |
20 | * Permission to use, copy, modify and distribute this software and its * | |
21 | * documentation strictly for non-commercial purposes is hereby granted * | |
22 | * without fee, provided that the above copyright notice appears in all * | |
23 | * copies and that both the copyright notice and this permission notice * | |
24 | * appear in the supporting documentation. The authors make no claims * | |
25 | * about the suitability of this software for any purpose. It is * | |
26 | * provided "as is" without express or implied warranty. * | |
27 | **************************************************************************/ | |
28 | ||
29 | /// | |
30 | /// MUON TRACKER DA to compute the hit count at manu level. | |
31 | /// | |
32 | /// In the end, this DA produces an ASCII file containing | |
33 | /// the hit count of all the manus (that were seen in the data flow) | |
34 | /// of the MUON Tracker (and the number of seen events, so we can | |
35 | /// later on compute the occupancy) | |
36 | /// | |
37 | /// $Id$ | |
38 | ||
39 | #include "AliMUON2DMap.h" | |
40 | #include "AliMUONCalibParamNI.h" | |
41 | #include "AliMUONRawStreamTrackerHP.h" | |
42 | #include "AliMpConstants.h" | |
43 | #include "AliRawEventHeaderBase.h" | |
134d9649 | 44 | #include "AliRawReaderDate.h" |
2825ba79 | 45 | #include "Riostream.h" |
46 | #include "TPluginManager.h" | |
47 | #include "TROOT.h" | |
48 | #include "TString.h" | |
49 | #include "TTimeStamp.h" | |
50 | #include "TStopwatch.h" | |
51 | #include "daqDA.h" | |
52 | #include "event.h" | |
134d9649 | 53 | #include "monitor.h" |
2825ba79 | 54 | |
55 | #ifdef ALI_AMORE | |
56 | #include <AmoreDA.h> | |
5431405e | 57 | #include "TObjString.h" |
58 | #include "TSystem.h" | |
59 | #include <sstream> | |
2825ba79 | 60 | #endif |
61 | ||
62 | const char* OUTPUT_FILE = "mch.occupancy"; | |
be9b25ed | 63 | const char* DAVERSION = "MUONTRKOCCda v1.2 ($Id$)"; |
2825ba79 | 64 | |
65 | //______________________________________________________________________________ | |
66 | void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore) | |
67 | { | |
68 | /// Add all elements from srcStore to destStore | |
69 | /// Each element of srcStore is supposed to be an AliMUONCalibParamNI, | |
70 | /// with ID0=busPatchId and ID1=manuId | |
71 | ||
72 | TIter next(srcStore.CreateIterator()); | |
73 | AliMUONVCalibParam* source; | |
74 | ||
75 | while ( ( source = static_cast<AliMUONVCalibParam*>(next()) ) ) | |
76 | { | |
77 | AliMUONCalibParamNI* dest = static_cast<AliMUONCalibParamNI*>(destStore.FindObject(source->ID0(),source->ID1())); | |
78 | if (!dest) | |
79 | { | |
80 | dest = static_cast<AliMUONCalibParamNI*>(source->Clone()); | |
81 | destStore.Add(dest); | |
82 | } | |
83 | else | |
84 | { | |
85 | for ( Int_t i = 0; i < source->Size(); ++i ) | |
86 | { | |
87 | for ( Int_t j = 0; j < source->Dimension(); ++j ) | |
88 | { | |
be9b25ed | 89 | dest->SetValueAsIntFast(i,j,dest->ValueAsIntFast(i,j)+source->ValueAsIntFast(i,j)); |
2825ba79 | 90 | } |
91 | } | |
92 | } | |
93 | } | |
94 | } | |
95 | ||
96 | //______________________________________________________________________________ | |
97 | void GenerateOutputFile(const AliMUONVStore& store, ostream& out, | |
98 | Int_t runNumber, Int_t nevents) | |
99 | { | |
100 | /// Write the channel hit count (grouped by manu) in the output file. | |
101 | ||
102 | TIter next(store.CreateIterator()); | |
103 | AliMUONVCalibParam* manu; | |
104 | ||
105 | out << "//===========================================================================" << endl; | |
106 | out << "// Hit counter file calculated by " << __FILE__ << endl; | |
107 | out << "//===========================================================================" << endl; | |
108 | out << "//" << endl; | |
109 | out << "// * Run Number : " << runNumber << endl; | |
110 | out << "// * File Creation Date : " << TTimeStamp().AsString("l") << endl; | |
111 | out << "//---------------------------------------------------------------------------" << endl; | |
112 | out << "// BP MANU SUM_N NEVENTS" << endl; | |
113 | out << "//---------------------------------------------------------------------------" << endl; | |
114 | ||
115 | while ( ( manu = static_cast<AliMUONVCalibParam*>(next()) ) ) | |
116 | { | |
117 | Int_t sum(0); | |
118 | // Int_t nevents(0); | |
119 | ||
120 | for ( Int_t i = 0; i < manu->Size(); ++i ) | |
121 | { | |
122 | sum += manu->ValueAsInt(i); | |
123 | // nevents = TMath::Max(nevents,manu->ValueAsInt(i,1)); | |
124 | // nevents = TMath::Max(nevents,manu->ValueAsInt(i,1)); | |
125 | } | |
126 | ||
127 | out << Form("%5d %5d %10d %10d",manu->ID0(),manu->ID1(),sum,nevents) << endl; | |
128 | } | |
129 | } | |
130 | ||
131 | //______________________________________________________________________________ | |
132 | int main(int argc, char **argv) | |
133 | { | |
134 | /// Main method. | |
135 | /// | |
136 | /// We loop over all physics events. | |
137 | /// For each event we store the channels that were hit for that event. | |
138 | /// If the event is good, we then increment the list of channels hit for | |
139 | /// the whole run. | |
140 | /// We delete the store for a single event and move to next event. | |
141 | /// | |
142 | /// In the end we output an ASCII file with the necessary information | |
143 | /// to compute the occupancy later on, i.e. the number of times channels | |
144 | /// were seen per manu, and the number of events. | |
145 | /// | |
146 | ||
147 | TStopwatch timers; | |
148 | timers.Start(kTRUE); | |
149 | ||
150 | ios::sync_with_stdio(); | |
151 | ||
152 | cout << "Running " << DAVERSION << endl; | |
153 | ||
154 | if ( argc < 2 ) | |
155 | { | |
156 | cout << "Wrong number of arguments" << endl; | |
157 | cout << "Usage : " << argv[0] << " datasource1 [datasource2] ..." << endl; | |
158 | return -1; | |
159 | } | |
160 | ||
161 | // needed for streamer application | |
162 | gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo", | |
163 | "*", | |
164 | "TStreamerInfo", | |
165 | "RIO", | |
166 | "TStreamerInfo()"); | |
167 | ||
168 | Int_t numberOfEvents(0); | |
169 | Int_t numberOfPhysicsEvent(0); | |
170 | Int_t numberOfBadEvents(0); | |
171 | Int_t numberOfUsedEvents(0); | |
172 | ||
173 | AliMUON2DMap oneEventData(kTRUE); | |
174 | AliMUON2DMap accumulatedData(kTRUE); | |
175 | ||
176 | UInt_t runNumber(0); | |
177 | ||
178 | for ( Int_t i = 1; i < argc; ++i ) | |
179 | { | |
134d9649 | 180 | int status; |
181 | AliRawReaderDate* rawReader(0x0); | |
182 | ||
183 | // define data source : | |
033da0c5 | 184 | status=monitorSetDataSource(argv[i]); |
134d9649 | 185 | if (status!=0) |
186 | { | |
187 | printf("MCH Occupancy DA ERROR: monitorSetDataSource() failed: %s\n", monitorDecodeError(status)); | |
188 | return -1; | |
189 | } | |
190 | ||
191 | // Declare monitoring program | |
192 | status=monitorDeclareMp("MUON_TRK_OCC"); | |
193 | if (status!=0) | |
194 | { | |
195 | printf("MCH Occupancy DA ERROR: monitorDeclareMp() failed: %s\n", monitorDecodeError(status)); | |
196 | return -1; | |
197 | } | |
198 | // Define wait event timeout - 1s max | |
199 | monitorSetNowait(); | |
200 | monitorSetNoWaitNetworkTimeout(1000); | |
201 | ||
202 | for(;;) | |
2825ba79 | 203 | { |
63108d64 | 204 | struct eventHeaderStruct *event(0x0); |
134d9649 | 205 | eventTypeType eventT; |
206 | ||
207 | status=monitorGetEventDynamic((void **)&event); | |
208 | if (status!=0) | |
209 | { | |
be9b25ed | 210 | printf("MCH Occupancy DA ERROR: %s\n", monitorDecodeError(status)); |
211 | delete event; | |
212 | break; | |
134d9649 | 213 | } |
214 | ||
2825ba79 | 215 | /* check shutdown condition */ |
be9b25ed | 216 | if (daqDA_checkShutdown()) |
2825ba79 | 217 | { |
be9b25ed | 218 | delete event; |
219 | break; | |
2825ba79 | 220 | } |
be9b25ed | 221 | |
134d9649 | 222 | /* retry if got no event */ |
223 | if (event==NULL) continue; | |
224 | ||
225 | ++numberOfEvents; | |
226 | ||
227 | eventT=event->eventType; | |
be9b25ed | 228 | if ((eventT == END_OF_RUN)||(eventT == END_OF_RUN_FILES)) |
229 | { | |
230 | delete event; | |
231 | break; | |
232 | } | |
233 | if (eventT != PHYSICS_EVENT) | |
234 | { | |
235 | delete event; | |
236 | continue; | |
237 | } | |
134d9649 | 238 | |
2825ba79 | 239 | ++numberOfPhysicsEvent; |
240 | ||
134d9649 | 241 | rawReader = new AliRawReaderDate((void*)event); |
242 | ||
2825ba79 | 243 | if ( rawReader->GetRunNumber() != runNumber ) |
244 | { | |
245 | if ( runNumber != 0 ) | |
246 | { | |
247 | cout << "Uh oh. That's bad... Changing of run number ???" << endl; | |
be9b25ed | 248 | delete event; |
249 | delete rawReader; | |
2825ba79 | 250 | return -9999; |
251 | } | |
252 | runNumber = rawReader->GetRunNumber(); | |
253 | } | |
254 | ||
255 | AliMUONRawStreamTrackerHP stream(rawReader); | |
256 | ||
257 | stream.DisableWarnings(); | |
2825ba79 | 258 | |
259 | oneEventData.Clear(); | |
260 | ||
261 | Int_t buspatchId; | |
262 | UShort_t manuId; | |
263 | UChar_t manuChannel; | |
264 | UShort_t adc; | |
265 | ||
266 | stream.First(); | |
134d9649 | 267 | |
2825ba79 | 268 | while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) ) |
269 | { | |
270 | AliMUONVCalibParam* one = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(buspatchId,manuId)); | |
271 | ||
272 | if (!one) | |
273 | { | |
274 | one = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),buspatchId,manuId); | |
275 | oneEventData.Add(one); | |
276 | } | |
277 | ||
278 | one->SetValueAsInt(manuChannel,0,one->ValueAsInt(manuChannel,0)+1); | |
279 | } | |
280 | ||
281 | Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError(); | |
282 | ||
283 | if ( !badEvent ) | |
284 | { | |
285 | ++numberOfUsedEvents; | |
286 | Add(accumulatedData,oneEventData); | |
287 | } | |
288 | else | |
289 | { | |
290 | ++numberOfBadEvents; | |
291 | } | |
be9b25ed | 292 | |
be9b25ed | 293 | delete event; |
294 | ||
295 | delete rawReader; | |
296 | } | |
2825ba79 | 297 | } |
298 | ||
299 | ||
300 | cout << Form("%12d events processed : %12d physics %d used ones %d bad ones", | |
301 | numberOfEvents,numberOfPhysicsEvent,numberOfUsedEvents,numberOfBadEvents) << endl; | |
302 | ||
303 | ofstream fout(OUTPUT_FILE); | |
304 | ||
305 | GenerateOutputFile(accumulatedData,fout,runNumber,numberOfUsedEvents); | |
306 | ||
307 | fout.close(); | |
308 | ||
309 | #ifdef ALI_AMORE | |
310 | ||
311 | // Send occupancy store (as a big string) to the AMORE DB | |
134d9649 | 312 | amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender); |
2825ba79 | 313 | |
2825ba79 | 314 | ostringstream str; |
315 | ||
316 | GenerateOutputFile(accumulatedData,str,runNumber,numberOfUsedEvents); | |
5431405e | 317 | |
2825ba79 | 318 | TObjString occupancyAsString(str.str().c_str()); |
319 | ||
5431405e | 320 | Int_t status = amoreDA.Send("Occupancy",&occupancyAsString); |
2825ba79 | 321 | if ( status ) |
322 | { | |
323 | cerr << "ERROR : Failed to write occupancies in the AMORE database : " << status << endl; | |
324 | } | |
325 | ||
326 | #endif | |
327 | ||
328 | /* store the result file on FXS */ | |
329 | if (daqDA_FES_storeFile(OUTPUT_FILE,"OCCUPANCY")) return -9; | |
330 | ||
331 | timers.Stop(); | |
332 | printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime()); | |
333 | ||
334 | return 0; | |
335 | } |