Line data Source code
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 "AliMUONCheckItem.h"
19 :
20 : #include "AliLog.h"
21 : #include "AliMpExMap.h"
22 : #include "AliMpExMapIterator.h"
23 : #include "Riostream.h"
24 :
25 : //-----------------------------------------------------------------------------
26 : /// \class AliMUONCheckItem
27 : ///
28 : /// A structure used to gather information at different levels (ch,manu,de,chamber)
29 : ///
30 : /// Used by AliMUON2DStoreValidator to present results in a concise way
31 : ///
32 : ///
33 : /// \author Laurent Aphecetche
34 : //-----------------------------------------------------------------------------
35 :
36 : using std::endl;
37 : using std::cout;
38 : /// \cond CLASSIMP
39 18 : ClassImp(AliMUONCheckItem)
40 : /// \endcond
41 :
42 : //_____________________________________________________________________________
43 : AliMUONCheckItem::AliMUONCheckItem(Int_t id, Int_t maxNumber, const char* name) :
44 0 : TNamed(name,name),
45 0 : fID(id),
46 0 : fDead(-1),
47 0 : fMaximum(maxNumber),
48 0 : fMissing(new AliMpExMap)
49 0 : {
50 : /// ctor. id is the number of that item, maxNumber is the maximum number
51 : /// of sub-item it can contains, and name is a label, e.g. de, chamber, manu.
52 : /// Note that name="manu" has a special influence on the IsDead() method.
53 :
54 0 : fMissing->SetSize(fMaximum);
55 0 : AliDebug(1,Form("ID %d maxNumber %d name %s",id,maxNumber,name));
56 0 : }
57 :
58 : //_____________________________________________________________________________
59 : AliMUONCheckItem::~AliMUONCheckItem()
60 0 : {
61 : /// dtor
62 0 : delete fMissing;
63 0 : }
64 :
65 : //_____________________________________________________________________________
66 : Bool_t AliMUONCheckItem::AddItem(Int_t id, TObject* item)
67 : {
68 : /// Add an item, if possible.
69 :
70 0 : if ( IsFull() )
71 : {
72 0 : AliError("I'm already full!");
73 0 : return kFALSE;
74 : }
75 :
76 0 : TObject* test = GetItem(id);
77 0 : if (test)
78 : {
79 0 : AliError(Form("id %d is already there !",id));
80 0 : return kFALSE;
81 : }
82 : else
83 : {
84 0 : fMissing->Add(id,item);
85 0 : fDead=-1;
86 : }
87 0 : return kTRUE;
88 0 : }
89 :
90 : //_____________________________________________________________________________
91 : void
92 : AliMUONCheckItem::ComputeDead() const
93 : {
94 : /// Decide whether this item is completely dead, which is determined by
95 : /// the fact that all its sub-items are dead, or for name="manu", by
96 : /// the fact that all channels are missing, i.e. IsFull()==kTRUE
97 :
98 0 : TString name(GetName());
99 0 : name.ToLower();
100 :
101 0 : if ( name.Contains("manu") )
102 : {
103 0 : if ( IsFull() )
104 : {
105 0 : fDead=1;
106 0 : }
107 : else
108 : {
109 0 : fDead=0;
110 : }
111 : }
112 : else
113 : {
114 0 : TIter next(CreateIterator());
115 : AliMUONCheckItem* item;
116 : Int_t ndead(0);
117 0 : fDead=0;
118 0 : while ( ( item = dynamic_cast<AliMUONCheckItem*>(next()) ) )
119 : {
120 0 : if ( item->IsDead() ) ++ndead;
121 : }
122 0 : if ( ndead == fMaximum ) fDead = 1;
123 0 : }
124 0 : }
125 :
126 : //_____________________________________________________________________________
127 : TIterator*
128 : AliMUONCheckItem::CreateIterator() const
129 : {
130 : /// Create iterator on this item
131 0 : return fMissing->CreateIterator();
132 : }
133 :
134 : //_____________________________________________________________________________
135 : TObject*
136 : AliMUONCheckItem::GetItem(Int_t id) const
137 : {
138 : /// Return item of a given id
139 0 : return fMissing->GetValue(id);
140 : }
141 :
142 : //_____________________________________________________________________________
143 : Bool_t
144 : AliMUONCheckItem::IsDead() const
145 : {
146 : /// Return (and compute it first if not done already) dead status
147 0 : if ( fDead == -1 )
148 : {
149 0 : ComputeDead();
150 0 : }
151 0 : return (fDead==1);
152 : }
153 :
154 : //_____________________________________________________________________________
155 : Bool_t
156 : AliMUONCheckItem::IsFull() const
157 : {
158 : /// Whether we have as many sub-items as possible
159 0 : return (fMissing->GetSize() == fMaximum);
160 : }
161 :
162 : //_____________________________________________________________________________
163 : void
164 : AliMUONCheckItem::Print(Option_t* opt) const
165 : {
166 : /// output to screen
167 0 : cout << Form("<AliMUONCheckItem> %s ID %d has %d items over %d max. Dead %d",
168 0 : GetName(),fID,fMissing->GetSize(),fMaximum,IsDead()) << endl;
169 0 : TString sopt(opt);
170 0 : sopt.ToLower();
171 0 : if (sopt.Contains("all") )
172 : {
173 : TObject* object(0x0);
174 :
175 0 : TIter next(CreateIterator());
176 :
177 0 : while ( ( object = next() ) )
178 : {
179 0 : object->Print(opt);
180 : }
181 0 : }
182 0 : }
|