]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerOCDBDataMaker.cxx
Must for the init of the mapping for Amore case
[u/mrichter/AliRoot.git] / MUON / AliMUONTrackerOCDBDataMaker.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 "AliMUONTrackerOCDBDataMaker.h"
19
20 #include "AliCDBManager.h"
21 #include "AliCDBStorage.h"
22 #include "AliDCSValue.h"
23 #include "AliLog.h"
24 #include "AliMUON2DMap.h"
25 #include "AliMUONCalibParamND.h"
26 #include "AliMUONCalibParamNI.h"
27 #include "AliMUONCalibrationData.h"
28 #include "AliMUONDigitCalibrator.h"
29 #include "AliMUONPadStatusMapMaker.h"
30 #include "AliMUONTrackerData.h"
31 #include "AliMUONVStore.h"
32 #include "AliMpConstants.h"
33 #include "AliMpDDLStore.h"
34 #include "AliMpDetElement.h"
35 #include "AliMpDEManager.h"
36 #include "AliMpDCSNamer.h"
37 #include "AliMpManuIterator.h"
38 #include "Riostream.h"
39 #include <TClass.h>
40 #include <TMap.h>
41 #include <TObjArray.h>
42 #include <TObjString.h>
43 #include <TString.h>
44
45 ///\class AliMUONTrackerOCDBDataMaker
46 ///
47 /// Producer of AliMUONVTrackerData from OCDB data
48 ///
49 ///\author Laurent Aphecetche, Subatech
50
51 ///\cond CLASSIMP
52 ClassImp(AliMUONTrackerOCDBDataMaker)
53 ///\endcond
54
55 //_____________________________________________________________________________
56 AliMUONTrackerOCDBDataMaker::AliMUONTrackerOCDBDataMaker(const char* ocdbPath,
57                                                            Int_t runNumber,
58                                                            const char* type)
59 : AliMUONVTrackerDataMaker(),
60   fIsValid(kTRUE),
61   fData(0x0),
62   fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type))
63 {
64         /// Ctor
65         AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
66         
67         AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
68         
69         AliMUONVStore* store(0x0);
70         
71         TString stype(type);
72         stype.ToUpper();
73         Bool_t isSingleEvent(kTRUE);
74         Int_t startOfValidity(0);
75         
76         if ( stype == "PEDESTALS" )
77         {
78                 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
79                 fData = CreateDataPedestals(startOfValidity);
80         }
81   else if ( stype == "CONFIG" ) 
82   {
83     store = AliMUONCalibrationData::CreateConfig(runNumber,&startOfValidity);
84     fData = new AliMUONTrackerData(Form("CONFIG%d",startOfValidity),"Configuration",1);
85     fData->SetDimensionName(0,"there");
86     fData->DisableChannelLevel();
87   }
88         else if ( stype == "OCCUPANCY" )
89         {
90                 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
91     
92     if (store)
93     {
94       fData = new AliMUONTrackerData(Form("OCC%d",runNumber),"OccupancyMap",*store);
95       fData->SetDimensionName(0,"One");
96       fData->SetDimensionName(1,"Zero");
97     }
98         }
99         else if ( stype == "GAINS" ) 
100         {
101     AliMUONVStore* gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
102     store = PatchGainStore(*gains);
103     delete gains;
104                 fData = CreateDataGains(startOfValidity);
105         }
106         else if ( stype == "CAPACITANCES" )
107         {
108                 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
109                 fData = CreateDataCapacitances(startOfValidity);
110         }
111         else if ( stype == "HV" )
112         {
113                 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
114                 fData = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1,!isSingleEvent);
115                 fData->SetDimensionName(0,"HV");
116                 store = CreateHVStore(*m);
117                 delete m;
118         }
119   else if ( stype == "STATUSMAP" )
120   {
121     fData = new AliMUONTrackerData(Form("STATUSMAP%d",runNumber),"Status map",2,kTRUE);
122     fData->SetDimensionName(0,"Bits");
123     fData->SetDimensionName(1,"Dead");
124     store = CreateStatusMapStore(runNumber);
125   }
126   else if ( stype == "STATUS" )
127   {
128     fData = new AliMUONTrackerData(Form("STATUS%d",runNumber),"Status",1,kTRUE);
129     fData->SetDimensionName(0,"Bits");
130     store = CreateStatusStore(runNumber);
131   }
132
133         AliCDBManager::Instance()->SetDefaultStorage(storage);
134         
135         if (!store)
136         {
137                 fIsValid = kFALSE;
138                 delete fData;
139                 fData = 0x0;
140                 AliError("Could not create store");
141                 return;
142         }
143         
144   if ( stype != "OCCUPANCY" )
145   {
146     fData->Add(*store);
147         }
148   
149         delete store;
150 }
151
152 //_____________________________________________________________________________
153 AliMUONTrackerOCDBDataMaker::~AliMUONTrackerOCDBDataMaker()
154 {
155   /// dtor
156   delete fData;
157 }
158
159 //_____________________________________________________________________________
160 AliMUONVTrackerData*
161 AliMUONTrackerOCDBDataMaker::CreateDataCapacitances(Int_t runNumber)
162 {
163   /// Create data to hold capa values
164   
165   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("CAPA%d",runNumber),"Capacitances",2,kTRUE);
166   data->SetDimensionName(0,"Capa");
167   data->SetDimensionName(1,"Injection gain");
168   return data;
169 }
170
171 //_____________________________________________________________________________
172 AliMUONVTrackerData*
173 AliMUONTrackerOCDBDataMaker::CreateDataGains(Int_t runNumber)
174 {
175   /// Create data to hold gains values
176   
177   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("GAIN%d",runNumber),"Gains",7,kTRUE);
178   data->SetDimensionName(0,"gain");
179   data->SetDimensionName(1,"a1");
180   data->SetDimensionName(2,"a2");
181   data->SetDimensionName(3,"thres");
182   data->SetDimensionName(4,"qual1");
183   data->SetDimensionName(5,"qual2");
184   data->SetDimensionName(6,"sat");
185   return data;
186 }
187
188 //_____________________________________________________________________________
189 AliMUONVStore*
190 AliMUONTrackerOCDBDataMaker::PatchGainStore(AliMUONVStore& gains)
191 {
192   /// Polish the gain store : 
193   /// a) adding a dimension, computed from a1, and called gain = 1/a1/0.2 
194   ///     where 0.2 is internal capa in pF, and gain is then in mV/fC
195   /// b) splitting the quality in two
196   
197   AliMUONVStore* store = gains.Create();
198   
199   TIter next(gains.CreateIterator());
200   AliMUONVCalibParam* param;
201   
202   while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) ) 
203   {
204     AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+2,
205                                                      param->Size(),
206                                                      param->ID0(),
207                                                      param->ID1());
208     for ( Int_t i = 0; i < param->Size(); ++i ) 
209     {
210
211       Int_t qual = param->ValueAsInt(i,3);
212                         Int_t q1 = (qual & 0xF0) >> 4;  // linear fit quality
213                         Int_t q2 = qual & 0xF;          // parabolic fit quality
214                         Double_t gain = 0.0;
215       
216       if ( param->ValueAsFloat(i,0) > 1E-9 ) gain = 1.0/param->ValueAsFloat(i,0)/0.2;
217                         
218       nd->SetValueAsDouble(i,0,gain); // gain
219       nd->SetValueAsDouble(i,1,param->ValueAsFloat(i,0)); // a1
220       nd->SetValueAsDouble(i,2,param->ValueAsFloat(i,1)); // a2
221       nd->SetValueAsInt(i,3,param->ValueAsInt(i,2)); // thres
222       nd->SetValueAsInt(i,4,q1); // qual1
223       nd->SetValueAsInt(i,5,q2); // qual2
224       nd->SetValueAsInt(i,6,param->ValueAsInt(i,4)); // sat
225     }
226     store->Add(nd);
227   }
228   
229   return store;
230 }
231
232 //_____________________________________________________________________________
233 AliMUONVTrackerData*
234 AliMUONTrackerOCDBDataMaker::CreateDataPedestals(Int_t runNumber)
235 {
236   /// Create data to hold pedestal values
237   
238   AliMUONVTrackerData* data  = new AliMUONTrackerData(Form("PED%d",runNumber),"Pedestals",2,kTRUE);
239   data->SetDimensionName(0,"Mean");
240   data->SetDimensionName(1,"Sigma");
241   return data;
242 }
243
244 //_____________________________________________________________________________
245 AliMUONVStore*
246 AliMUONTrackerOCDBDataMaker::CreateStatusStore(Int_t runNumber)
247 {
248   /// Get the status store
249   
250   AliMUONDigitCalibrator calibrator(runNumber);
251   
252   AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
253   
254   AliMpManuIterator it;
255   Int_t detElemId, manuId;
256   
257   while (it.Next(detElemId,manuId))
258   {
259     AliMUONVCalibParam* np = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId);
260     for ( Int_t i = 0; i < np->Size(); ++i ) 
261     {
262       Int_t value = calibrator.PadStatus(detElemId,manuId,i);
263       np->SetValueAsInt(i,0,value); // "raw" value of the status
264     }
265     sm->Add(np);
266   }
267   
268   return sm;
269 }
270
271 //_____________________________________________________________________________
272 AliMUONVStore*
273 AliMUONTrackerOCDBDataMaker::CreateStatusMapStore(Int_t runNumber)
274 {
275   /// Get the status map, and polish it a bit for representation purposes
276
277   AliMUONDigitCalibrator calibrator(runNumber);
278   
279   AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
280   
281   AliMpManuIterator it;
282   Int_t detElemId, manuId;
283   
284   while (it.Next(detElemId,manuId))
285   {
286     AliMUONVCalibParam* np = new AliMUONCalibParamNI(2,AliMpConstants::ManuNofChannels(),detElemId,manuId);
287     for ( Int_t i = 0; i < np->Size(); ++i ) 
288     {
289       Int_t value = calibrator.StatusMap(detElemId,manuId,i);
290       Int_t channelIsDead = ( value & AliMUONPadStatusMapMaker::SelfDeadMask() );
291       np->SetValueAsInt(i,0,value); // "raw" value of the status map
292       np->SetValueAsInt(i,1,channelIsDead); // simple 0 or 1 for this channel
293     }
294     sm->Add(np);
295   }
296   
297   return sm;
298 }
299
300 //_____________________________________________________________________________
301 AliMUONVStore*
302 AliMUONTrackerOCDBDataMaker::CreateHVStore(TMap& m)
303 {
304   /// Create a store from hv values
305   
306   AliMUONVStore* store = new AliMUON2DMap(kTRUE);
307   
308   TIter next(&m);
309   TObjString* s;
310   AliMpDCSNamer hvNamer("TRACKER");
311   
312   while ( ( s = static_cast<TObjString*>(next()) ) )
313   {
314     TString name(s->String());
315
316     Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
317     
318     if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
319     {
320       AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
321                          detElemId,name.Data()));
322       continue;
323     }
324     
325     Int_t nindex = 1;
326     Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
327     
328     if ( hvIndex > 0 && detElemId >= 500 ) 
329     {
330       AliFatalClass("FIXME"); // there's now switch aliases which should be taken into account
331     }
332
333     if ( hvIndex == -2 ) // we should consider switch alias there...
334     {
335       nindex = hvNamer.NumberOfPCBs(detElemId);
336       hvIndex = 0;
337     }
338
339     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
340
341     for ( int i = 0 ; i < nindex; ++i )
342     {
343       Int_t index = hvIndex + i ;
344       
345       const AliMpArrayI* manus = de->ManusForHV(index);
346       
347       TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
348       TObjArray* a = static_cast<TObjArray*>(p->Value());
349       TIter n2(a);
350       AliDCSValue* v;
351       Float_t hvValue(0);
352       Int_t n(0);
353       while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
354       {
355         hvValue += v->GetFloat();  
356         ++n;
357       }
358       if ( n ) hvValue /= n;
359       
360       Int_t nofChannels(AliMpConstants::ManuNofChannels());
361       
362       for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
363       {
364         Int_t manuId = manus->GetValue(k);
365         AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
366         if ( ! param ) 
367         {
368           param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
369           store->Add(param);
370         }
371         for ( Int_t j = 0 ; j < nofChannels; ++j )
372         {
373           param->SetValueAsDouble(j,0,hvValue);
374         }
375       }
376     }
377   }
378   
379   return store;
380   
381 }
382
383 //_____________________________________________________________________________
384 Long64_t 
385 AliMUONTrackerOCDBDataMaker::Merge(TCollection*)
386 {
387   /// Merge
388   AliError("Not implemented. Does it have sense ?");
389   return 0;
390 }