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