]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DStoreValidator.cxx
Add comments for Doxygen
[u/mrichter/AliRoot.git] / MUON / AliMUON2DStoreValidator.cxx
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
58 ClassImp(AliMUON2DStoreValidator)
59 /// \endcond
60
61 //_____________________________________________________________________________
62 AliMUON2DStoreValidator::AliMUON2DStoreValidator() 
63 : TObject(),
64   fManuList(0x0),
65   fChambers(0x0),
66   fStatus(0x0)
67 {
68     /// ctor
69 }
70
71 //_____________________________________________________________________________
72 AliMUON2DStoreValidator::~AliMUON2DStoreValidator()
73 {
74   /// dtor
75   delete fManuList;
76   delete fChambers;
77   delete fStatus;
78 }
79
80 //_____________________________________________________________________________
81 AliMUONCheckItem* 
82 AliMUON2DStoreValidator::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 //_____________________________________________________________________________
112 AliMUONCheckItem* 
113 AliMUON2DStoreValidator::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 //_____________________________________________________________________________
138 AliMUONCheckItem* 
139 AliMUON2DStoreValidator::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 //_____________________________________________________________________________
159 void
160 AliMUON2DStoreValidator::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 //_____________________________________________________________________________
178 void
179 AliMUON2DStoreValidator::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 //_____________________________________________________________________________
195 void
196 AliMUON2DStoreValidator::ReportManu(TList& lines, AliMUONCheckItem& manu)
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   {
207     lines.Add(new TObjString(Form("\t\t\tChannel %s is missing or dead",
208                                   channel->GetString().Data())));
209   }
210   
211 }
212
213 //_____________________________________________________________________________
214 void
215 AliMUON2DStoreValidator::ReportDE(TList& lines, AliMUONCheckItem& de)
216 {  
217   /// Report list of missing manus from this de
218   AliMUONCheckItem* manu(0x0);
219   AliMUONCheckItemIterator it(de);
220   
221   lines.Add(new TObjString(Form("DE %5d",de.GetID())));
222   
223   it.First();
224   
225   while ( ( manu = static_cast<AliMUONCheckItem*>(it.Next()) ) )
226   {
227     if ( manu->IsDead() )
228     {
229       lines.Add(new TObjString(Form("\t\tManu %4d is missing or dead",manu->GetID())));
230     }
231     else
232     {
233       ReportManu(lines,*manu);
234     }
235   }
236 }
237
238 //_____________________________________________________________________________
239 void
240 AliMUON2DStoreValidator::ReportChamber(TList& lines, AliMUONCheckItem& chamber)
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     {
253       lines.Add(new TObjString(Form("\tDE %4d is missing or dead",de->GetID())));
254     }
255     else
256     {
257       ReportDE(lines,*de);
258     }
259   }
260 }
261
262 //_____________________________________________________________________________
263 void
264 AliMUON2DStoreValidator::Report(TList& lines) const
265
266   /// 
267   if (fChambers) 
268   {
269     Report(lines,*fChambers); 
270   }
271 }
272
273 //_____________________________________________________________________________
274 void
275 AliMUON2DStoreValidator::Report(TList& lines, const TObjArray& chambers)
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       {
286         lines.Add(new TObjString(Form("Chamber %2d is missing or dead",iChamber)));
287       }
288       else
289       {
290         ReportChamber(lines,*chamber);
291       }
292     }
293   }
294 }
295
296 //_____________________________________________________________________________
297 TObjArray* 
298 AliMUON2DStoreValidator::Validate(const AliMUONV2DStore& store)
299 {                                  
300   /// Validate the store. Check only the presence of all manus (i.e.
301   /// check nothing about the values themselves)
302   
303   Bool_t (*kCheck)(const AliMUONVCalibParam&,Int_t) = 0x0;
304   return Validate(store,kCheck);
305 }
306
307 //_____________________________________________________________________________
308 TObjArray* 
309 AliMUON2DStoreValidator::Validate(const AliMUONV2DStore& store,
310                                   Bool_t (*check)(const AliMUONVCalibParam&,Int_t))
311 {
312   /// Validate the store. 
313   /// The check method is used to decide if a store content value
314   /// is valid or not.
315   
316   delete fChambers;
317   fChambers = 0x0;
318   
319   if (!fManuList) fManuList = AliMpManuList::ManuList();
320   
321   // Now checks if some full manus are missing
322   TIter next(fManuList);
323   AliMpIntPair* p;
324   
325   while ( ( p = (AliMpIntPair*)next() ) )
326   {
327     Int_t detElemId = p->GetFirst();
328     Int_t manuId = p->GetSecond();
329     AliMUONVCalibParam* test = 
330       static_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
331     if (!test)
332     {
333       // completely missing manu
334       AddMissingManu(detElemId,manuId);
335     }
336     else
337     {
338       if (!check) continue;
339       // manu is there, check all its channels
340       for ( Int_t manuChannel = 0 ; manuChannel < test->Size(); ++manuChannel )
341       {
342         if ( AliMpManuList::DoesChannelExist(detElemId,manuId,manuChannel) &&
343              !check(*test,manuChannel) )             
344         {
345           AddMissingChannel(detElemId,manuId,manuChannel);
346         }
347       }
348     }
349   }
350   return fChambers;
351   
352 }
353
354
355 //_____________________________________________________________________________
356 TObjArray* 
357 AliMUON2DStoreValidator::Validate(const AliMUONV2DStore& store,
358                                   Float_t invalidFloatValue)
359 {
360   /// Validate the store. 
361   /// The invalidFloatValue is used to decide if a store content value
362   /// is valid or not.
363   
364   delete fChambers;
365   fChambers = 0x0;
366   
367   if (!fManuList) fManuList = AliMpManuList::ManuList();
368
369   // Now checks if some full manus are missing
370   TIter next(fManuList);
371   AliMpIntPair* p;
372
373   while ( ( p = (AliMpIntPair*)next() ) )
374   {
375     Int_t detElemId = p->GetFirst();
376     Int_t manuId = p->GetSecond();
377     AliMUONVCalibParam* test = 
378       static_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
379     if (!test)
380     {
381       // completely missing manu
382       AddMissingManu(detElemId,manuId);
383     }
384     else
385     {
386       // manu is there, check all its channels
387       for ( Int_t manuChannel = 0 ; manuChannel < test->Size(); ++manuChannel )
388       {
389         if ( AliMpManuList::DoesChannelExist(detElemId,manuId,manuChannel) &&
390              ( test->ValueAsFloat(manuChannel,0) == invalidFloatValue ||
391                test->ValueAsFloat(manuChannel,1) == invalidFloatValue ) )             
392         {
393           AddMissingChannel(detElemId,manuId,manuChannel);
394         }
395       }
396     }
397   }
398   return fChambers;
399 }
400
401