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