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