]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTrackerOCDBDataMaker.cxx
Fixing compiler warnings
[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 "AliMUONCalibrationData.h"
27 #include "AliMUONTrackerData.h"
28 #include "AliMUONVStore.h"
29 #include "AliMpConstants.h"
30 #include "AliMpDDLStore.h"
31 #include "AliMpDetElement.h"
32 #include "AliMpDEManager.h"
33 #include "AliMpDCSNamer.h"
34 #include <TClass.h>
35 #include <TMap.h>
36 #include <TObjArray.h>
37 #include <TObjString.h>
38 #include <TString.h>
39
40 ///\class AliMUONTrackerOCDBDataMaker
41 ///
42 /// Producer of AliMUONVTrackerData from OCDB data
43 ///
44 ///\author Laurent Aphecetche, Subatech
45
46 ///\cond CLASSIMP
47 ClassImp(AliMUONTrackerOCDBDataMaker)
48 ///\endcond
49
50 //_____________________________________________________________________________
51 AliMUONTrackerOCDBDataMaker::AliMUONTrackerOCDBDataMaker(const char* ocdbPath,
52                                                            Int_t runNumber,
53                                                            const char* type)
54 : AliMUONVTrackerDataMaker(),
55   fIsValid(kTRUE),
56   fData(0x0),
57   fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type))
58 {
59         /// Ctor
60         AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
61         
62         AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
63         
64         AliMUONVStore* store(0x0);
65         
66         TString stype(type);
67         stype.ToUpper();
68         Bool_t isSingleEvent(kTRUE);
69         Int_t startOfValidity(0);
70         
71         if ( stype == "PEDESTALS" )
72         {
73                 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
74                 fData = CreateDataPedestals(startOfValidity);
75         }
76         else if ( stype == "OCCUPANCY" )
77         {
78                 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
79     
80     if (store)
81     {
82       fData = new AliMUONTrackerData(Form("OCC%d",runNumber),"OccupancyMap",*store);
83       fData->SetDimensionName(0,"One");
84       fData->SetDimensionName(1,"Zero");
85     }
86         }
87         else if ( stype == "GAINS" ) 
88         {
89                 AliMUONVStore* gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
90                 fData = CreateDataGains(startOfValidity);
91                 store = SplitQuality(*gains);
92                 delete gains;
93         }
94         else if ( stype == "CAPACITANCES" )
95         {
96                 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
97                 fData = CreateDataCapacitances(startOfValidity);
98         }
99         else if ( stype == "HV" )
100         {
101                 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
102                 fData = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1,!isSingleEvent);
103                 fData->SetDimensionName(0,"HV");
104                 store = CreateHVStore(*m);
105                 delete m;
106         }
107         
108         AliCDBManager::Instance()->SetDefaultStorage(storage);
109         
110         if (!store)
111         {
112                 fIsValid = kFALSE;
113                 delete fData;
114                 fData = 0x0;
115                 AliError("Could not create store");
116                 return;
117         }
118         
119   if ( stype != "OCCUPANCY" )
120   {
121     fData->Add(*store);
122         }
123   
124         delete store;
125 }
126
127 //_____________________________________________________________________________
128 AliMUONTrackerOCDBDataMaker::~AliMUONTrackerOCDBDataMaker()
129 {
130   /// dtor
131   delete fData;
132 }
133
134 //_____________________________________________________________________________
135 AliMUONVTrackerData*
136 AliMUONTrackerOCDBDataMaker::CreateDataCapacitances(Int_t runNumber)
137 {
138   /// Create data to hold capa values
139   
140   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("CAPA%d",runNumber),"Capacitances",2,kTRUE);
141   data->SetDimensionName(0,"Capa");
142   data->SetDimensionName(1,"Injection gain");
143   return data;
144 }
145
146 //_____________________________________________________________________________
147 AliMUONVTrackerData*
148 AliMUONTrackerOCDBDataMaker::CreateDataGains(Int_t runNumber)
149 {
150   /// Create data to hold gains values
151   
152   AliMUONVTrackerData* data = new AliMUONTrackerData(Form("GAIN%d",runNumber),"Gains",6,kTRUE);
153   data->SetDimensionName(0,"a1");
154   data->SetDimensionName(1,"a2");
155   data->SetDimensionName(2,"thres");
156   data->SetDimensionName(3,"qual1");
157   data->SetDimensionName(4,"qual2");
158   data->SetDimensionName(5,"sat");
159   return data;
160 }
161
162 //_____________________________________________________________________________
163 AliMUONVTrackerData*
164 AliMUONTrackerOCDBDataMaker::CreateDataPedestals(Int_t runNumber)
165 {
166   /// Create data to hold pedestal values
167   
168   AliMUONVTrackerData* data  = new AliMUONTrackerData(Form("PED%d",runNumber),"Pedestals",2,kTRUE);
169   data->SetDimensionName(0,"Mean");
170   data->SetDimensionName(1,"Sigma");
171   return data;
172 }
173
174 //_____________________________________________________________________________
175 AliMUONVStore*
176 AliMUONTrackerOCDBDataMaker::CreateHVStore(TMap& m)
177 {
178   /// Create a store from hv values
179   
180   AliMUONVStore* store = new AliMUON2DMap(kTRUE);
181   
182   TIter next(&m);
183   TObjString* s;
184   AliMpDCSNamer hvNamer("TRACKER");
185   
186   while ( ( s = static_cast<TObjString*>(next()) ) )
187   {
188     TString name(s->String());
189
190     Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
191     
192     if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
193     {
194       AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
195                          detElemId,name.Data()));
196       continue;
197     }
198     
199     Int_t nindex = 1;
200     Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
201     
202     if ( hvIndex > 0 && detElemId >= 500 ) 
203     {
204       AliFatalClass("FIXME"); // there's now switch aliases which should be taken into account
205     }
206
207     if ( hvIndex == -2 ) // we should consider switch alias there...
208     {
209       nindex = hvNamer.NumberOfPCBs(detElemId);
210       hvIndex = 0;
211     }
212
213     AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
214
215     for ( int i = 0 ; i < nindex; ++i )
216     {
217       Int_t index = hvIndex + i ;
218       
219       const AliMpArrayI* manus = de->ManusForHV(index);
220       
221       TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
222       TObjArray* a = static_cast<TObjArray*>(p->Value());
223       TIter n2(a);
224       AliDCSValue* v;
225       Float_t hvValue(0);
226       Int_t n(0);
227       while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
228       {
229         hvValue += v->GetFloat();  
230         ++n;
231       }
232       if ( n ) hvValue /= n;
233       
234       Int_t nofChannels(AliMpConstants::ManuNofChannels());
235       
236       for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
237       {
238         Int_t manuId = manus->GetValue(k);
239         AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
240         if ( ! param ) 
241         {
242           param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
243           store->Add(param);
244         }
245         for ( Int_t j = 0 ; j < nofChannels; ++j )
246         {
247           param->SetValueAsDouble(j,0,hvValue);
248         }
249       }
250     }
251   }
252   
253   return store;
254   
255 }
256
257 //_____________________________________________________________________________
258 Long64_t 
259 AliMUONTrackerOCDBDataMaker::Merge(TCollection*)
260 {
261   /// Merge
262   AliError("Not implemented. Does it have sense ?");
263   return 0;
264 }
265
266 //_____________________________________________________________________________
267 AliMUONVStore*
268 AliMUONTrackerOCDBDataMaker::SplitQuality(const AliMUONVStore& gains)
269 {
270   /// Create a new store, identical to source gain store, except that qual 
271   /// dimension is "decompacted" in two separated values
272   
273   AliMUONVStore* store = gains.Create();
274   
275   TIter next(gains.CreateIterator());
276   AliMUONVCalibParam* param;
277   
278   while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) ) 
279   {
280     AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+1,
281                                                       param->Size(),
282                                                       param->ID0(),
283                                                       param->ID1());
284     for ( Int_t i = 0; i < param->Size(); ++i ) 
285     {
286       for ( Int_t k = 0; k < param->Dimension(); ++k ) 
287       {
288         if ( k == 3 ) continue;
289         Int_t m = ( k < 3 ? k : k+1 ) ;
290         nd->SetValueAsDouble(i,m,param->ValueAsFloat(i,k));
291       }
292       Int_t qual = param->ValueAsInt(i,3);
293                         
294                         Int_t q1 = (qual & 0xF0) >> 4;  // linear fit quality
295                         Int_t q2 = qual & 0xF;          // parabolic fit quality
296                         
297       nd->SetValueAsInt(i,3,q1);
298       nd->SetValueAsInt(i,4,q2);
299     }
300     store->Add(nd);
301   }
302   return store;
303 }