Changes to the interface (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUON2DStoreValidator.cxx
CommitLineData
ea199e33 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
17
18#include "AliMUON2DStoreValidator.h"
19
20#include "AliLog.h"
21#include "AliMUONCalibParam1I.h"
22#include "AliMpIntPair.h"
23#include "AliMpManuList.h"
24#include "AliMUONV2DStore.h"
25#include "TList.h"
26#include "TObjArray.h"
27#include "AliMUONCheckItem.h"
28#include "AliMUONCheckItemIterator.h"
29#include "AliMpDEManager.h"
30#include "TObjString.h"
31#include "AliMUONConstants.h"
32#include "Riostream.h"
33
34/// \class AliMUON2DStoreValidator
35///
36/// Determine which channels, manus, DEs, stations are missing
37/// from a 2DStore. This is mainly to be used during (shuttle) preprocessing
38/// to insure that what we'll put in the CDB is as complete as possible,
39/// and to detect possible problem.
40///
41/// We made an effort to present the result of the validation in the most
42/// concise way (i.e. if all channels of a DE are missing, we do not list
43/// them, we just write "DE dead" ;-) )
44///
45/// The list of missing things is kept in a structure of objects defined as :
46///
47/// fMissing = TObjArray[0..N tracking chambers]
48/// fMissing[iChamber] = AliMUONCheckItem which contains n AliMUONCheckItem,
49/// where n is the number of DE for that chamber
50/// fMissing[iChamber]->GetItem(de) = AliMUONCheckItem which contains m
51/// AliMUONCheckItem where m is the number of Manu for that DE
52/// fMissing[iChamber]->GetItem(de)->GetItem(manu) = AliMUONCheckItem which
53/// contains k TObjString = Form("%d",manuChannel)
54///
55/// \author Laurent Aphecetche
56
57/// \cond CLASSIMP
58ClassImp(AliMUON2DStoreValidator)
59/// \endcond
60
61//_____________________________________________________________________________
62AliMUON2DStoreValidator::AliMUON2DStoreValidator()
63: TObject(),
64 fManuList(0x0),
9b955acc 65 fChambers(0x0),
66 fStatus(0x0)
ea199e33 67{
68 /// ctor
69}
70
71//_____________________________________________________________________________
72AliMUON2DStoreValidator::~AliMUON2DStoreValidator()
73{
74 /// dtor
75 delete fManuList;
76 delete fChambers;
9b955acc 77 delete fStatus;
ea199e33 78}
79
80//_____________________________________________________________________________
81AliMUONCheckItem*
82AliMUON2DStoreValidator::GetChamber(Int_t chamberID)
83{
84 /// Return (and create if not present) the given chamber
85 /// chamberID in 0..NCh()
86
87 if ( chamberID < 0 || chamberID >= AliMUONConstants::NCh() )
88 {
89 AliFatal(Form("Invalid chamber number %d",chamberID));
90 return 0x0;
91 }
92
93 if (!fChambers)
94 {
95 fChambers = new TObjArray(AliMUONConstants::NCh());
96 }
97
98 AliMUONCheckItem* chamber =
99 static_cast<AliMUONCheckItem*>(fChambers->At(chamberID));
100
101 if (!chamber)
102 {
103 chamber = new AliMUONCheckItem(chamberID,
104 AliMpDEManager::GetNofDEInChamber(chamberID),
105 "Chamber");
106 fChambers->AddAt(chamber,chamberID);
107 }
108 return chamber;
109}
110
111//_____________________________________________________________________________
112AliMUONCheckItem*
113AliMUON2DStoreValidator::GetDE(Int_t detElemId)
114{
115 /// Return (and create if not present) a given detection element
116
117 Int_t chamberID = AliMpDEManager::GetChamberId(detElemId);
118 AliMUONCheckItem* chamber = GetChamber(chamberID);
119 AliMUONCheckItem* de =
120 static_cast<AliMUONCheckItem*>(chamber->GetItem(detElemId));
121 if (!de)
122 {
123 AliDebug(3,Form("Did not find DE %4d into chamber %d, will create it",
124 detElemId,chamberID));
125 de = new AliMUONCheckItem(detElemId,
126 AliMpManuList::NumberOfManus(detElemId),
127 "Detection Element");
128 Bool_t ok = chamber->AddItem(detElemId,de);
129 if (!ok)
130 {
131 AliError(Form("Could not add DE %4d into chamber %2d",detElemId,chamberID));
132 }
133 }
134 return de;
135}
136
137//_____________________________________________________________________________
138AliMUONCheckItem*
139AliMUON2DStoreValidator::GetManu(Int_t detElemId, Int_t manuId)
140{
141 /// Return (and create) a given manu
142
143 AliMUONCheckItem* de = GetDE(detElemId);
144 AliMUONCheckItem* manu = static_cast<AliMUONCheckItem*>(de->GetItem(manuId));
145 if (!manu)
146 {
147 manu = new AliMUONCheckItem(manuId,AliMpManuList::NumberOfChannels(detElemId,manuId),"Manu");
148 Bool_t ok = de->AddItem(manuId,manu);
149 if (!ok)
150 {
151 AliError(Form("Could not add manu %4d into DE %4d",manuId,detElemId));
152 }
153
154 }
155 return manu;
156}
157
158//_____________________________________________________________________________
159void
160AliMUON2DStoreValidator::AddMissingChannel(Int_t detElemId,
161 Int_t manuId, Int_t manuChannel)
162{
163 /// Add one missing channel to the list of missing things
164
165 AliDebug(3,Form("DE %4d Manu %4d Channel %2d is missing",
166 detElemId,manuId,manuChannel));
167
168 AliMUONCheckItem* manu = GetManu(detElemId,manuId);
169 Bool_t ok = manu->AddItem(manuChannel,new TObjString(Form("%2d",manuChannel)));
170 if (!ok)
171 {
172 AliError(Form("Could not add channel %2d to manuId %4d in DE %4d",
173 manuChannel,manuId,detElemId));
174 }
175}
176
177//_____________________________________________________________________________
178void
179AliMUON2DStoreValidator::AddMissingManu(Int_t detElemId, Int_t manuId)
180{
181 /// Add one missing manu to the list of missing things
182
183 AliDebug(3,Form("DE %4d Manu %4d is completely missing",
184 detElemId,manuId));
185
186 Int_t n(AliMpManuList::NumberOfChannels(detElemId,manuId));
187
188 for ( Int_t i = 0; i < n; ++i )
189 {
190 AddMissingChannel(detElemId,manuId,i);
191 }
192}
193
194//_____________________________________________________________________________
195void
9b955acc 196AliMUON2DStoreValidator::ReportManu(TList& lines, AliMUONCheckItem& manu)
ea199e33 197{
198 /// Report list of missing channels from this manu
199
200 TObjString* channel(0x0);
201 AliMUONCheckItemIterator it(manu);
202
203 it.First();
204
205 while ( ( channel = static_cast<TObjString*>(it.Next()) ) )
206 {
9b955acc 207 lines.Add(new TObjString(Form("\t\t\tChannel %s is missing or dead",
208 channel->GetString().Data())));
ea199e33 209 }
210
211}
212
213//_____________________________________________________________________________
214void
9b955acc 215AliMUON2DStoreValidator::ReportDE(TList& lines, AliMUONCheckItem& de)
ea199e33 216{
217 /// Report list of missing manus from this de
218 AliMUONCheckItem* manu(0x0);
219 AliMUONCheckItemIterator it(de);
220
9b955acc 221 lines.Add(new TObjString(Form("DE %5d",de.GetID())));
ea199e33 222
223 it.First();
224
225 while ( ( manu = static_cast<AliMUONCheckItem*>(it.Next()) ) )
226 {
227 if ( manu->IsDead() )
228 {
9b955acc 229 lines.Add(new TObjString(Form("\t\tManu %4d is missing or dead",manu->GetID())));
ea199e33 230 }
231 else
232 {
9b955acc 233 ReportManu(lines,*manu);
ea199e33 234 }
235 }
236}
237
238//_____________________________________________________________________________
239void
9b955acc 240AliMUON2DStoreValidator::ReportChamber(TList& lines, AliMUONCheckItem& chamber)
ea199e33 241{
242 /// Report list of missing de from this chamber
243
244 AliMUONCheckItem* de(0x0);
245 AliMUONCheckItemIterator it(chamber);
246
247 it.First();
248
249 while ( ( de = static_cast<AliMUONCheckItem*>(it.Next()) ) )
250 {
251 if ( de->IsDead() )
252 {
9b955acc 253 lines.Add(new TObjString(Form("\tDE %4d is missing or dead",de->GetID())));
ea199e33 254 }
255 else
256 {
9b955acc 257 ReportDE(lines,*de);
ea199e33 258 }
259 }
260}
261
262//_____________________________________________________________________________
263void
9b955acc 264AliMUON2DStoreValidator::Report(TList& lines) const
265{
266 ///
267 if (fChambers)
268 {
269 Report(lines,*fChambers);
270 }
271}
272
273//_____________________________________________________________________________
274void
275AliMUON2DStoreValidator::Report(TList& lines, const TObjArray& chambers)
ea199e33 276{
277 /// Reports what is missing, trying to be as concise as possible.
278
279 for ( Int_t iChamber = 0; iChamber <= chambers.GetLast(); ++iChamber )
280 {
281 AliMUONCheckItem* chamber = static_cast<AliMUONCheckItem*>(chambers.At(iChamber));
282 if ( chamber )
283 {
284 if ( chamber->IsDead() )
285 {
9b955acc 286 lines.Add(new TObjString(Form("Chamber %2d is missing or dead",iChamber)));
ea199e33 287 }
288 else
289 {
9b955acc 290 ReportChamber(lines,*chamber);
291 }
292 }
293 }
294}
295
296//_____________________________________________________________________________
297TObjArray*
298AliMUON2DStoreValidator::Validate(const AliMUONV2DStore& store,
299 Bool_t (*check)(const AliMUONVCalibParam&,Int_t))
300{
301 /// Validate the store.
302 /// The check method is used to decide if a store content value
303 /// is valid or not.
304
305 delete fChambers;
306 fChambers = 0x0;
307
308 if (!fManuList) fManuList = AliMpManuList::ManuList();
309
310 // Now checks if some full manus are missing
311 TIter next(fManuList);
312 AliMpIntPair* p;
313
314 while ( ( p = (AliMpIntPair*)next() ) )
315 {
316 Int_t detElemId = p->GetFirst();
317 Int_t manuId = p->GetSecond();
318 AliMUONVCalibParam* test =
319 static_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
320 if (!test)
321 {
322 // completely missing manu
323 AddMissingManu(detElemId,manuId);
324 }
325 else
326 {
327 if (!check) continue;
328 // manu is there, check all its channels
329 for ( Int_t manuChannel = 0 ; manuChannel < test->Size(); ++manuChannel )
330 {
331 if ( AliMpManuList::DoesChannelExist(detElemId,manuId,manuChannel) &&
332 !check(*test,manuChannel) )
333 {
334 AddMissingChannel(detElemId,manuId,manuChannel);
335 }
ea199e33 336 }
337 }
338 }
9b955acc 339 return fChambers;
340
ea199e33 341}
342
9b955acc 343
ea199e33 344//_____________________________________________________________________________
345TObjArray*
346AliMUON2DStoreValidator::Validate(const AliMUONV2DStore& store,
347 Float_t invalidFloatValue)
348{
349 /// Validate the store.
350 /// The invalidFloatValue is used to decide if a store content value
351 /// is valid or not.
352
353 delete fChambers;
354 fChambers = 0x0;
355
356 if (!fManuList) fManuList = AliMpManuList::ManuList();
357
358 // Now checks if some full manus are missing
359 TIter next(fManuList);
360 AliMpIntPair* p;
361
362 while ( ( p = (AliMpIntPair*)next() ) )
363 {
364 Int_t detElemId = p->GetFirst();
365 Int_t manuId = p->GetSecond();
366 AliMUONVCalibParam* test =
367 static_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
368 if (!test)
369 {
370 // completely missing manu
371 AddMissingManu(detElemId,manuId);
372 }
373 else
374 {
375 // manu is there, check all its channels
376 for ( Int_t manuChannel = 0 ; manuChannel < test->Size(); ++manuChannel )
377 {
378 if ( AliMpManuList::DoesChannelExist(detElemId,manuId,manuChannel) &&
379 ( test->ValueAsFloat(manuChannel,0) == invalidFloatValue ||
380 test->ValueAsFloat(manuChannel,1) == invalidFloatValue ) )
381 {
382 AddMissingChannel(detElemId,manuId,manuChannel);
383 }
384 }
385 }
386 }
387 return fChambers;
388}
389
390