1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONTrackerOCDBDataMaker.h"
20 #include "AliCDBManager.h"
21 #include "AliCDBStorage.h"
22 #include "AliDCSValue.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"
36 #include <TObjArray.h>
37 #include <TObjString.h>
40 ///\class AliMUONTrackerOCDBDataMaker
42 /// Producer of AliMUONVTrackerData from OCDB data
44 ///\author Laurent Aphecetche, Subatech
47 ClassImp(AliMUONTrackerOCDBDataMaker)
50 //_____________________________________________________________________________
51 AliMUONTrackerOCDBDataMaker::AliMUONTrackerOCDBDataMaker(const char* ocdbPath,
54 : AliMUONVTrackerDataMaker(),
57 fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type))
60 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
62 AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
64 AliMUONVStore* store(0x0);
68 Bool_t isSingleEvent(kTRUE);
69 Int_t startOfValidity(0);
71 if ( stype == "PEDESTALS" )
73 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
74 fData = CreateDataPedestals(startOfValidity);
76 else if ( stype == "GAINS" )
78 AliMUONVStore* gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
79 fData = CreateDataGains(startOfValidity);
80 store = SplitQuality(*gains);
83 else if ( stype == "CAPACITANCES" )
85 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
86 fData = CreateDataCapacitances(startOfValidity);
88 else if ( stype == "HV" )
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);
97 AliCDBManager::Instance()->SetDefaultStorage(storage);
104 AliError("Could not create store");
113 //_____________________________________________________________________________
114 AliMUONTrackerOCDBDataMaker::~AliMUONTrackerOCDBDataMaker()
120 //_____________________________________________________________________________
122 AliMUONTrackerOCDBDataMaker::CreateDataCapacitances(Int_t runNumber)
124 /// Create data to hold capa values
126 AliMUONVTrackerData* data = new AliMUONTrackerData(Form("CAPA%d",runNumber),"Capacitances",2,kTRUE);
127 data->SetDimensionName(0,"Capa");
128 data->SetDimensionName(1,"Injection gain");
132 //_____________________________________________________________________________
134 AliMUONTrackerOCDBDataMaker::CreateDataGains(Int_t runNumber)
136 /// Create data to hold gains values
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");
148 //_____________________________________________________________________________
150 AliMUONTrackerOCDBDataMaker::CreateDataPedestals(Int_t runNumber)
152 /// Create data to hold pedestal values
154 AliMUONVTrackerData* data = new AliMUONTrackerData(Form("PED%d",runNumber),"Pedestals",2,kTRUE);
155 data->SetDimensionName(0,"Mean");
156 data->SetDimensionName(1,"Sigma");
160 //_____________________________________________________________________________
162 AliMUONTrackerOCDBDataMaker::CreateHVStore(TMap& m)
164 /// Create a store from hv values
166 AliMUONVStore* store = new AliMUON2DMap(kTRUE);
170 AliMpDCSNamer hvNamer("TRACKER");
172 while ( ( s = static_cast<TObjString*>(next()) ) )
174 TString name(s->String());
176 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
178 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
180 AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
181 detElemId,name.Data()));
186 Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
188 if ( hvIndex > 0 && detElemId >= 500 )
190 AliFatalClass("FIXME"); // there's now switch aliases which should be taken into account
193 if ( hvIndex == -2 ) // we should consider switch alias there...
195 nindex = hvNamer.NumberOfPCBs(detElemId);
199 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
201 for ( int i = 0 ; i < nindex; ++i )
203 Int_t index = hvIndex + i ;
205 const AliMpArrayI* manus = de->ManusForHV(index);
207 TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
208 TObjArray* a = static_cast<TObjArray*>(p->Value());
213 while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
215 hvValue += v->GetFloat();
218 if ( n ) hvValue /= n;
220 Int_t nofChannels(AliMpConstants::ManuNofChannels());
222 for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
224 Int_t manuId = manus->GetValue(k);
225 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
228 param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
231 for ( Int_t j = 0 ; j < nofChannels; ++j )
233 param->SetValueAsDouble(j,0,hvValue);
243 //_____________________________________________________________________________
245 AliMUONTrackerOCDBDataMaker::Merge(TCollection*)
248 AliError("Not implemented. Does it have sense ?");
252 //_____________________________________________________________________________
254 AliMUONTrackerOCDBDataMaker::SplitQuality(const AliMUONVStore& gains)
256 /// Create a new store, identical to source gain store, except that qual
257 /// dimension is "decompacted" in two separated values
259 AliMUONVStore* store = gains.Create();
261 TIter next(gains.CreateIterator());
262 AliMUONVCalibParam* param;
264 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
266 AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+1,
270 for ( Int_t i = 0; i < param->Size(); ++i )
272 for ( Int_t k = 0; k < param->Dimension(); ++k )
274 if ( k == 3 ) continue;
275 Int_t m = ( k < 3 ? k : k+1 ) ;
276 nd->SetValueAsDouble(i,m,param->ValueAsFloat(i,k));
278 Int_t qual = param->ValueAsInt(i,3);
280 Int_t q1 = (qual & 0xF0) >> 4; // linear fit quality
281 Int_t q2 = qual & 0xF; // parabolic fit quality
283 nd->SetValueAsInt(i,3,q1);
284 nd->SetValueAsInt(i,4,q2);