]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONTRKOCCda.cxx
- Channels (or pads) with bad addressing of manus or occupancy rate > 1 are not calib...
[u/mrichter/AliRoot.git] / MUON / MUONTRKOCCda.cxx
CommitLineData
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...)
9 Input Files:
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"
44#include "AliRawReader.h"
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"
53
54#ifdef ALI_AMORE
55#include <AmoreDA.h>
5431405e 56#include "TObjString.h"
57#include "TSystem.h"
58#include <sstream>
2825ba79 59#endif
60
61const char* OUTPUT_FILE = "mch.occupancy";
62const char* DAVERSION = "MUONTRKOCCda v1.0";
63
64//______________________________________________________________________________
65void Add(AliMUONVStore& destStore, const AliMUONVStore& srcStore)
66{
67 /// Add all elements from srcStore to destStore
68 /// Each element of srcStore is supposed to be an AliMUONCalibParamNI,
69 /// with ID0=busPatchId and ID1=manuId
70
71 TIter next(srcStore.CreateIterator());
72 AliMUONVCalibParam* source;
73
74 while ( ( source = static_cast<AliMUONVCalibParam*>(next()) ) )
75 {
76 AliMUONCalibParamNI* dest = static_cast<AliMUONCalibParamNI*>(destStore.FindObject(source->ID0(),source->ID1()));
77 if (!dest)
78 {
79 dest = static_cast<AliMUONCalibParamNI*>(source->Clone());
80 destStore.Add(dest);
81 }
82 else
83 {
84 for ( Int_t i = 0; i < source->Size(); ++i )
85 {
86 for ( Int_t j = 0; j < source->Dimension(); ++j )
87 {
88 dest->SetValueAsInt(i,j,dest->ValueAsInt(i,j)+source->ValueAsInt(i,j));
89 }
90 }
91 }
92 }
93}
94
95//______________________________________________________________________________
96void GenerateOutputFile(const AliMUONVStore& store, ostream& out,
97 Int_t runNumber, Int_t nevents)
98{
99 /// Write the channel hit count (grouped by manu) in the output file.
100
101 TIter next(store.CreateIterator());
102 AliMUONVCalibParam* manu;
103
104 out << "//===========================================================================" << endl;
105 out << "// Hit counter file calculated by " << __FILE__ << endl;
106 out << "//===========================================================================" << endl;
107 out << "//" << endl;
108 out << "// * Run Number : " << runNumber << endl;
109 out << "// * File Creation Date : " << TTimeStamp().AsString("l") << endl;
110 out << "//---------------------------------------------------------------------------" << endl;
111 out << "// BP MANU SUM_N NEVENTS" << endl;
112 out << "//---------------------------------------------------------------------------" << endl;
113
114 while ( ( manu = static_cast<AliMUONVCalibParam*>(next()) ) )
115 {
116 Int_t sum(0);
117// Int_t nevents(0);
118
119 for ( Int_t i = 0; i < manu->Size(); ++i )
120 {
121 sum += manu->ValueAsInt(i);
122 // nevents = TMath::Max(nevents,manu->ValueAsInt(i,1));
123 // nevents = TMath::Max(nevents,manu->ValueAsInt(i,1));
124 }
125
126 out << Form("%5d %5d %10d %10d",manu->ID0(),manu->ID1(),sum,nevents) << endl;
127 }
128}
129
130//______________________________________________________________________________
131int main(int argc, char **argv)
132{
133 /// Main method.
134 ///
135 /// We loop over all physics events.
136 /// For each event we store the channels that were hit for that event.
137 /// If the event is good, we then increment the list of channels hit for
138 /// the whole run.
139 /// We delete the store for a single event and move to next event.
140 ///
141 /// In the end we output an ASCII file with the necessary information
142 /// to compute the occupancy later on, i.e. the number of times channels
143 /// were seen per manu, and the number of events.
144 ///
145
146 TStopwatch timers;
147 timers.Start(kTRUE);
148
149 ios::sync_with_stdio();
150
151 cout << "Running " << DAVERSION << endl;
152
153 if ( argc < 2 )
154 {
155 cout << "Wrong number of arguments" << endl;
156 cout << "Usage : " << argv[0] << " datasource1 [datasource2] ..." << endl;
157 return -1;
158 }
159
5431405e 160#ifdef ALI_AMORE
161 amore::da::AmoreDA amoreDA(amore::da::AmoreDA::kSender);
162#endif
2825ba79 163 // needed for streamer application
164 gROOT->GetPluginManager()->AddHandler("TVirtualStreamerInfo",
165 "*",
166 "TStreamerInfo",
167 "RIO",
168 "TStreamerInfo()");
169
170 Int_t numberOfEvents(0);
171 Int_t numberOfPhysicsEvent(0);
172 Int_t numberOfBadEvents(0);
173 Int_t numberOfUsedEvents(0);
174
175 AliMUON2DMap oneEventData(kTRUE);
176 AliMUON2DMap accumulatedData(kTRUE);
177
178 UInt_t runNumber(0);
179
180 for ( Int_t i = 1; i < argc; ++i )
181 {
182 AliRawReader* rawReader = AliRawReader::Create(argv[i]);
183
184 while ( rawReader->NextEvent() )
185 {
186 /* check shutdown condition */
187 if (daqDA_checkShutdown()) break;
188
189 ++numberOfEvents;
190
191 if ( rawReader->GetType() == AliRawEventHeaderBase::kEndOfRun )
192 {
193 printf("EOR event detected\n");
194 break;
195 }
196
197 if ( rawReader->GetType() != AliRawEventHeaderBase::kPhysicsEvent ) continue;
198
199 ++numberOfPhysicsEvent;
200
201 if ( rawReader->GetRunNumber() != runNumber )
202 {
203 if ( runNumber != 0 )
204 {
205 cout << "Uh oh. That's bad... Changing of run number ???" << endl;
206 return -9999;
207 }
208 runNumber = rawReader->GetRunNumber();
209 }
210
211 AliMUONRawStreamTrackerHP stream(rawReader);
212
213 stream.DisableWarnings();
214 stream.EnabbleErrorLogger();
215
216 oneEventData.Clear();
217
218 Int_t buspatchId;
219 UShort_t manuId;
220 UChar_t manuChannel;
221 UShort_t adc;
222
223 stream.First();
224
225 while ( stream.Next(buspatchId,manuId,manuChannel,adc,kTRUE) )
226 {
227 AliMUONVCalibParam* one = static_cast<AliMUONVCalibParam*>(oneEventData.FindObject(buspatchId,manuId));
228
229 if (!one)
230 {
231 one = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),buspatchId,manuId);
232 oneEventData.Add(one);
233 }
234
235 one->SetValueAsInt(manuChannel,0,one->ValueAsInt(manuChannel,0)+1);
236 }
237
238 Bool_t badEvent = stream.HasPaddingError() || stream.HasGlitchError();
239
240 if ( !badEvent )
241 {
242 ++numberOfUsedEvents;
243 Add(accumulatedData,oneEventData);
244 }
245 else
246 {
247 ++numberOfBadEvents;
248 }
249 }
250
251 delete rawReader;
252 }
253
254
255 cout << Form("%12d events processed : %12d physics %d used ones %d bad ones",
256 numberOfEvents,numberOfPhysicsEvent,numberOfUsedEvents,numberOfBadEvents) << endl;
257
258 ofstream fout(OUTPUT_FILE);
259
260 GenerateOutputFile(accumulatedData,fout,runNumber,numberOfUsedEvents);
261
262 fout.close();
263
264#ifdef ALI_AMORE
265
266 // Send occupancy store (as a big string) to the AMORE DB
267
2825ba79 268 ostringstream str;
269
270 GenerateOutputFile(accumulatedData,str,runNumber,numberOfUsedEvents);
5431405e 271
2825ba79 272 TObjString occupancyAsString(str.str().c_str());
273
5431405e 274 Int_t status = amoreDA.Send("Occupancy",&occupancyAsString);
2825ba79 275 if ( status )
276 {
277 cerr << "ERROR : Failed to write occupancies in the AMORE database : " << status << endl;
278 }
279
280#endif
281
282 /* store the result file on FXS */
283 if (daqDA_FES_storeFile(OUTPUT_FILE,"OCCUPANCY")) return -9;
284
285 timers.Stop();
286 printf("\nExecution time : R:%7.2fs C:%7.2fs\n", timers.RealTime(), timers.CpuTime());
287
288 return 0;
289}