]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUON2DStoreValidator.cxx
New raw-reader class which deals with events taken from shared memory via the DATE...
[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 "AliMUONCheckItem.h"
22 #include "AliMUONCheckItemIterator.h"
23 #include "AliMUONVCalibParam.h"
24 #include "AliMUONVStore.h"
25 #include "AliMpConstants.h"
26 #include "AliMpDDLStore.h"
27 #include "AliMpDEManager.h"
28 #include "AliMpDetElement.h"
29 #include "AliMpManuIterator.h"
30 #include <Riostream.h>
31 #include <TList.h>
32 #include <TObjArray.h>
33 #include <TObjString.h>
34
35 //-----------------------------------------------------------------------------
36 /// \class AliMUON2DStoreValidator
37 ///
38 /// Determine which channels, manus, DEs, stations are missing
39 /// from a VStore, which must be 2D, and the 2 dimensions must be
40 /// (detElemId,manuId).
41 /// This is mainly to be used during (shuttle) preprocessing
42 /// to insure that what we'll put in the CDB is as complete as possible,
43 /// and to detect possible problem.
44 ///
45 /// We made an effort to present the result of the validation in the most
46 /// concise way (i.e. if all channels of a DE are missing, we do not list 
47 /// them, we just write "DE dead" ;-) )
48 /// 
49 /// The list of missing things is kept in a structure of objects defined as :
50 /// 
51 /// fMissing = TObjArray[0..N tracking chambers]
52 ///
53 /// fMissing[iChamber] = AliMUONCheckItem which contains n AliMUONCheckItem, 
54 /// where n is the number of DE for that chamber
55 ///
56 /// fMissing[iChamber]->GetItem(de) = AliMUONCheckItem which contains m
57 /// AliMUONCheckItem where m is the number of Manu for that DE
58 ///
59 /// fMissing[iChamber]->GetItem(de)->GetItem(manu) = AliMUONCheckItem which 
60 /// contains k TObjString = Form("%d",manuChannel)
61 ///
62 /// \author Laurent Aphecetche
63 //-----------------------------------------------------------------------------
64
65 /// \cond CLASSIMP
66 ClassImp(AliMUON2DStoreValidator)
67 /// \endcond
68
69 //_____________________________________________________________________________
70 AliMUON2DStoreValidator::AliMUON2DStoreValidator() 
71 : TObject(),
72   fChambers(0x0),
73   fStatus(0x0)
74 {
75     /// ctor
76 }
77
78 //_____________________________________________________________________________
79 AliMUON2DStoreValidator::~AliMUON2DStoreValidator()
80 {
81   /// dtor
82   delete fChambers;
83   delete fStatus;
84 }
85
86 //_____________________________________________________________________________
87 AliMUONCheckItem* 
88 AliMUON2DStoreValidator::GetChamber(Int_t chamberID)
89 {
90   /// Return (and create if not present) the given chamber
91   /// chamberID in 0..NCh()
92   
93   if ( chamberID < 0 || chamberID >= AliMpConstants::NofTrackingChambers() )
94   {
95     AliFatal(Form("Invalid chamber number %d",chamberID));
96     return 0x0;
97   }
98   
99   if (!fChambers) 
100   {
101     fChambers = new TObjArray(AliMpConstants::NofTrackingChambers());
102   }
103     
104   AliMUONCheckItem* chamber = 
105     static_cast<AliMUONCheckItem*>(fChambers->At(chamberID));
106   
107   if (!chamber)
108   {
109     chamber = new AliMUONCheckItem(chamberID,
110                                    AliMpDEManager::GetNofDEInChamber(chamberID),
111                                    "Chamber");
112     fChambers->AddAt(chamber,chamberID);
113   }
114   return chamber;
115 }
116
117 //_____________________________________________________________________________
118 AliMUONCheckItem* 
119 AliMUON2DStoreValidator::GetDE(Int_t detElemId)
120 {
121   /// Return (and create if not present) a given detection element
122   
123   Int_t chamberID = AliMpDEManager::GetChamberId(detElemId);
124   AliMUONCheckItem* chamber = GetChamber(chamberID);  
125   AliMUONCheckItem* de = 
126     static_cast<AliMUONCheckItem*>(chamber->GetItem(detElemId));
127   if (!de)
128   {
129     AliDebug(3,Form("Did not find DE %4d into chamber %d, will create it",
130                     detElemId,chamberID));
131     de = new AliMUONCheckItem(detElemId,
132                               AliMpDDLStore::Instance()->GetDetElement(detElemId)->NofManus(),
133                               "Detection Element");
134     Bool_t ok = chamber->AddItem(detElemId,de);
135     if (!ok)
136     {
137       AliError(Form("Could not add DE %4d into chamber %2d",detElemId,chamberID));
138     }
139   }
140   return de;
141 }
142
143 //_____________________________________________________________________________
144 AliMUONCheckItem* 
145 AliMUON2DStoreValidator::GetManu(Int_t detElemId, Int_t manuId)
146 {
147   /// Return (and create) a given manu
148   
149   AliMUONCheckItem* de = GetDE(detElemId);
150   AliMUONCheckItem* manu = static_cast<AliMUONCheckItem*>(de->GetItem(manuId));
151   if (!manu)
152   {
153     manu = new AliMUONCheckItem(manuId,AliMpDDLStore::Instance()->GetDetElement(detElemId)->NofChannelsInManu(manuId),"Manu");
154     Bool_t ok = de->AddItem(manuId,manu);
155     if (!ok)
156     {
157       AliError(Form("Could not add manu %4d into DE %4d",manuId,detElemId));
158     }
159     
160   }
161   return manu;
162 }
163
164 //_____________________________________________________________________________
165 void
166 AliMUON2DStoreValidator::AddMissingChannel(Int_t detElemId, 
167                                            Int_t manuId, Int_t manuChannel)
168 {
169   /// Add one missing channel to the list of missing things
170   
171   AliDebug(3,Form("DE %4d Manu %4d Channel %2d is missing",
172                   detElemId,manuId,manuChannel));
173
174   AliMUONCheckItem* manu = GetManu(detElemId,manuId);
175   Bool_t ok = manu->AddItem(manuChannel,new TObjString(Form("%2d",manuChannel)));
176   if (!ok)
177   {
178     AliError(Form("Could not add channel %2d to manuId %4d in DE %4d",
179                     manuChannel,manuId,detElemId));
180   }
181 }
182
183 //_____________________________________________________________________________
184 void
185 AliMUON2DStoreValidator::AddMissingManu(Int_t detElemId, Int_t manuId)
186 {
187   /// Add one missing manu to the list of missing things
188   
189   AliDebug(3,Form("DE %4d Manu %4d is completely missing",
190                   detElemId,manuId));
191
192   Int_t n(AliMpDDLStore::Instance()->GetDetElement(detElemId)->NofChannelsInManu(manuId));
193
194   for ( Int_t i = 0; i < n; ++i )
195   {
196     AddMissingChannel(detElemId,manuId,i);
197   }
198 }
199
200 //_____________________________________________________________________________
201 void
202 AliMUON2DStoreValidator::ReportManu(TList& lines, AliMUONCheckItem& manu)
203 {  
204   /// Report list of missing channels from this manu
205   
206   TObjString* channel(0x0);
207   AliMUONCheckItemIterator it(manu);
208   
209   it.First();
210   
211   while ( ( channel = static_cast<TObjString*>(it.Next()) ) )
212   {
213     lines.Add(new TObjString(Form("\t\t\tChannel %s is missing or dead",
214                                   channel->GetString().Data())));
215   }
216   
217 }
218
219 //_____________________________________________________________________________
220 void
221 AliMUON2DStoreValidator::ReportDE(TList& lines, AliMUONCheckItem& de)
222 {  
223   /// Report list of missing manus from this de
224   AliMUONCheckItem* manu(0x0);
225   AliMUONCheckItemIterator it(de);
226   
227   lines.Add(new TObjString(Form("DE %5d",de.GetID())));
228   
229   it.First();
230   
231   while ( ( manu = static_cast<AliMUONCheckItem*>(it.Next()) ) )
232   {
233     if ( manu->IsDead() )
234     {
235       lines.Add(new TObjString(Form("\t\tManu %4d is missing or dead",manu->GetID())));
236     }
237     else
238     {
239       ReportManu(lines,*manu);
240     }
241   }
242 }
243
244 //_____________________________________________________________________________
245 void
246 AliMUON2DStoreValidator::ReportChamber(TList& lines, AliMUONCheckItem& chamber)
247 {  
248   /// Report list of missing de from this chamber
249   
250   AliMUONCheckItem* de(0x0);
251   AliMUONCheckItemIterator it(chamber);
252   
253   it.First();
254   
255   while ( ( de = static_cast<AliMUONCheckItem*>(it.Next()) ) )
256   {
257     if ( de->IsDead() )
258     {
259       lines.Add(new TObjString(Form("\tDE %4d is missing or dead",de->GetID())));
260     }
261     else
262     {
263       ReportDE(lines,*de);
264     }
265   }
266 }
267
268 //_____________________________________________________________________________
269 void
270 AliMUON2DStoreValidator::Report(TList& lines) const
271
272   /// 
273   if (fChambers) 
274   {
275     Report(lines,*fChambers); 
276   }
277 }
278
279 //_____________________________________________________________________________
280 void
281 AliMUON2DStoreValidator::Report(TList& lines, const TObjArray& chambers)
282 {
283   /// Reports what is missing, trying to be as concise as possible.
284   
285   for ( Int_t iChamber = 0; iChamber <= chambers.GetLast(); ++iChamber )
286   {
287     AliMUONCheckItem* chamber = static_cast<AliMUONCheckItem*>(chambers.At(iChamber));
288     if ( chamber )
289     {
290       if ( chamber->IsDead() )
291       {
292         lines.Add(new TObjString(Form("Chamber %2d is missing or dead",iChamber)));
293       }
294       else
295       {
296         ReportChamber(lines,*chamber);
297       }
298     }
299   }
300 }
301
302 //_____________________________________________________________________________
303 TObjArray* 
304 AliMUON2DStoreValidator::Validate(const AliMUONVStore& store)
305 {                                  
306   /// Validate the store. Check only the presence of all manus (i.e.
307   /// check nothing about the values themselves)
308   
309   Bool_t (*kCheck)(const AliMUONVCalibParam&,Int_t) = 0x0;
310   return Validate(store,kCheck);
311 }
312
313 //_____________________________________________________________________________
314 TObjArray* 
315 AliMUON2DStoreValidator::Validate(const AliMUONVStore& store,
316                                   Bool_t (*check)(const AliMUONVCalibParam&,Int_t))
317 {
318   /// Validate the store. 
319   /// The check method is used to decide if a store content value
320   /// is valid or not.
321   
322   delete fChambers;
323   fChambers = 0x0;
324   
325   // Now checks if some full manus are missing
326
327   AliMpManuIterator it;
328
329   Int_t detElemId;
330   Int_t manuId;
331   
332   while ( it.Next(detElemId,manuId) )
333   {
334     AliMUONVCalibParam* test = 
335       static_cast<AliMUONVCalibParam*>(store.FindObject(detElemId,manuId));
336     if (!test)
337     {
338       // completely missing manu
339       AddMissingManu(detElemId,manuId);
340     }
341     else
342     {
343       if (!check) continue;
344       
345       AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
346       
347       // manu is there, check all its channels
348       for ( Int_t manuChannel = 0 ; manuChannel < test->Size(); ++manuChannel )
349       {
350         if ( de->IsConnectedChannel(manuId,manuChannel) &&
351              !check(*test,manuChannel) )             
352         {
353           AddMissingChannel(detElemId,manuId,manuChannel);
354         }
355       }
356     }
357   }
358   return fChambers;
359   
360 }
361
362
363 //_____________________________________________________________________________
364 TObjArray* 
365 AliMUON2DStoreValidator::Validate(const AliMUONVStore& store,
366                                   Float_t invalidFloatValue)
367 {
368   /// Validate the store. 
369   /// The invalidFloatValue is used to decide if a store content value
370   /// is valid or not.
371   
372   delete fChambers;
373   fChambers = 0x0;
374   
375   // Now checks if some full manus are missing
376
377   AliMpManuIterator it;
378   Int_t detElemId;
379   Int_t manuId;
380   
381   while ( it.Next(detElemId,manuId) )
382   {
383     AliMUONVCalibParam* test = 
384       static_cast<AliMUONVCalibParam*>(store.FindObject(detElemId,manuId));
385     if (!test)
386     {
387       // completely missing manu
388       AddMissingManu(detElemId,manuId);
389     }
390     else
391     {
392       // manu is there, check all its channels
393       AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
394       
395       for ( Int_t manuChannel = 0 ; manuChannel < test->Size(); ++manuChannel )
396       {
397         if ( de->IsConnectedChannel(manuId,manuChannel) &&
398              ( test->ValueAsFloat(manuChannel,0) == invalidFloatValue ||
399                test->ValueAsFloat(manuChannel,1) == invalidFloatValue ) )             
400         {
401           AddMissingChannel(detElemId,manuId,manuChannel);
402         }
403       }
404     }
405   }
406   return fChambers;
407 }
408
409