]>
Commit | Line | Data |
---|---|---|
ca913045 | 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 "AliMUONTrackerConditionDataMaker.h" | |
19 | ||
20 | ///\class AliMUONTrackerConditionDataMaker | |
21 | /// | |
22 | /// Producer of AliMUONVTrackerData from OCDB or Ascii file condition data | |
23 | /// | |
24 | /// \author Laurent Aphecetche, Subatech | |
25 | ||
26 | ///\cond CLASSIMP | |
27 | ClassImp(AliMUONTrackerConditionDataMaker) | |
28 | ///\endcond | |
29 | ||
30 | #include "AliCDBManager.h" | |
31 | #include "AliCDBStorage.h" | |
32 | #include "AliDCSValue.h" | |
33 | #include "AliLog.h" | |
34 | #include "AliMpManuIterator.h" | |
35 | #include "AliMUON2DMap.h" | |
36 | #include "AliMUONCalibParamND.h" | |
37 | #include "AliMUONCalibParamNF.h" | |
38 | #include "AliMUONCalibParamNI.h" | |
39 | #include "AliMUONCalibrationData.h" | |
40 | #include "AliMUONDigitCalibrator.h" | |
41 | #include "AliMUONPadStatusMaker.h" | |
42 | #include "AliMUONPadStatusMapMaker.h" | |
43 | #include "AliMUONTrackerData.h" | |
44 | #include "AliMUONTrackerIO.h" | |
45 | #include "AliMpArrayI.h" | |
46 | #include "AliMpConstants.h" | |
47 | #include "AliMpDCSNamer.h" | |
48 | #include "AliMpDDLStore.h" | |
49 | #include "AliMpDEManager.h" | |
50 | #include "AliMpDetElement.h" | |
51 | #include "TClass.h" | |
52 | #include "TMap.h" | |
53 | #include "TObjString.h" | |
54 | #include "Riostream.h" | |
55 | #include "TString.h" | |
56 | #include <sstream> | |
7c4bd38a | 57 | #include "TSystem.h" |
ca913045 | 58 | |
59 | //_____________________________________________________________________________ | |
60 | AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(Int_t runNumber, const char* ocdbPath, const char* type): | |
61 | AliMUONVTrackerDataMaker(), | |
62 | fData(0x0), | |
63 | fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type)) | |
64 | { | |
65 | /// ctor from OCDB | |
66 | ||
67 | AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage(); | |
68 | ||
69 | AliCDBManager::Instance()->SetDefaultStorage(ocdbPath); | |
70 | ||
71 | Int_t startOfValidity; | |
72 | AliMUONVStore* store = CreateStore(runNumber,ocdbPath,type,startOfValidity); | |
b5b2b1cc | 73 | AliDebug(1,Form("runNumber=%d ocdbPath=%s type=%s startOfValidity=%d store=%p", |
74 | runNumber,ocdbPath,type,startOfValidity,store)); | |
ca913045 | 75 | if ( store ) |
76 | { | |
77 | fData = CreateData(type,*store,startOfValidity); | |
78 | } | |
79 | ||
80 | delete store; | |
81 | ||
82 | AliCDBManager::Instance()->SetDefaultStorage(storage); | |
83 | } | |
84 | ||
85 | //_____________________________________________________________________________ | |
86 | AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* filename, const char* type): | |
87 | AliMUONVTrackerDataMaker(), | |
88 | fData(0x0), | |
89 | fSource(Form("%s-%s",filename,type)) | |
90 | { | |
91 | /// ctor from an ASCII file | |
92 | ||
93 | TString sFilename(gSystem->ExpandPathName(filename)); | |
94 | ||
95 | std::ifstream in(sFilename.Data()); | |
96 | if (in.good()) | |
97 | { | |
98 | std::ostringstream stream; | |
99 | char line[1024]; | |
100 | while ( in.getline(line,1024) ) | |
101 | { | |
102 | stream << line << "\n"; | |
103 | } | |
104 | ||
105 | in.close(); | |
106 | ||
107 | Int_t dummy; | |
108 | ||
109 | AliMUONVStore* store = CreateStore(-1,stream.str().c_str(),type,dummy); | |
110 | ||
111 | if ( store ) | |
112 | { | |
113 | fData = CreateData(type,*store,dummy); | |
114 | } | |
115 | delete store; | |
116 | } | |
117 | } | |
118 | ||
119 | //_____________________________________________________________________________ | |
120 | AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* data, const char* type, Bool_t) : | |
121 | AliMUONVTrackerDataMaker(), | |
122 | fData(0x0), | |
123 | fSource(Form("direct-%s",type)) | |
124 | { | |
125 | /// ctor from a string containing the ASCII data | |
126 | /// the last parameter is there just to distinguish this ctor from the previous one | |
127 | ||
128 | Int_t dummy; | |
129 | ||
130 | AliMUONVStore* store = CreateStore(-1,data,type,dummy); | |
131 | ||
132 | if ( store ) | |
133 | { | |
134 | fData = CreateData(type,*store,dummy); | |
135 | } | |
136 | delete store; | |
137 | ||
138 | } | |
139 | ||
140 | //_____________________________________________________________________________ | |
141 | AliMUONTrackerConditionDataMaker::~AliMUONTrackerConditionDataMaker() | |
142 | { | |
143 | /// dtor | |
144 | delete fData; | |
145 | } | |
146 | ||
147 | ||
148 | //_____________________________________________________________________________ | |
149 | AliMUONVTrackerData* | |
150 | AliMUONTrackerConditionDataMaker::CreateData(const char* type, AliMUONVStore& store, Int_t startOfValidity) | |
151 | { | |
152 | /// Create the data source | |
153 | AliMUONVTrackerData* data(0x0); | |
154 | ||
155 | TString stype(type); | |
156 | stype.ToUpper(); | |
157 | ||
158 | if ( stype == "CAPACITANCES" ) | |
159 | { | |
160 | data = new AliMUONTrackerData(Form("CAPA%d",startOfValidity),"Capacitances",2,kTRUE); | |
161 | data->SetDimensionName(0,"Capa"); | |
162 | data->SetDimensionName(1,"Injection gain"); | |
163 | } | |
164 | else if ( stype == "CONFIG" ) | |
165 | { | |
166 | data = new AliMUONTrackerData(Form("CONFIG%d",startOfValidity),"Configuration",1); | |
167 | data->SetDimensionName(0,"there"); | |
168 | data->DisableChannelLevel(); | |
169 | } | |
170 | else if ( stype == "GAINS" ) | |
171 | { | |
172 | data = new AliMUONTrackerData(Form("GAIN%d",startOfValidity),"Gains",7,kTRUE); | |
173 | data->SetDimensionName(0,"gain"); | |
174 | data->SetDimensionName(1,"a1"); | |
175 | data->SetDimensionName(2,"a2"); | |
176 | data->SetDimensionName(3,"thres"); | |
177 | data->SetDimensionName(4,"qual1"); | |
178 | data->SetDimensionName(5,"qual2"); | |
179 | data->SetDimensionName(6,"sat"); | |
180 | } | |
181 | else if ( stype == "HV" ) | |
182 | { | |
183 | data = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1); //,!isSingleEvent); | |
184 | data->SetDimensionName(0,"HV"); | |
185 | } | |
186 | else if ( stype == "OCCUPANCY" ) | |
187 | { | |
188 | data = new AliMUONTrackerData(Form("OCC%d",startOfValidity),"OccupancyMap",store); | |
189 | data->SetDimensionName(0,"One"); | |
190 | return data; // important to return now to avoid the data->Add(store) later on... | |
191 | } | |
192 | else if ( stype == "PEDESTALS" ) | |
193 | { | |
194 | data = new AliMUONTrackerData(Form("PED%d",startOfValidity),"Pedestals",2,kTRUE); | |
195 | data->SetDimensionName(0,"Mean"); | |
196 | data->SetDimensionName(1,"Sigma"); | |
197 | } | |
198 | else if ( stype == "STATUS" ) | |
199 | { | |
200 | data = new AliMUONTrackerData(Form("STATUS%d",startOfValidity),"Status",1,kTRUE); | |
201 | data->SetDimensionName(0,"Bits"); | |
202 | } | |
203 | else if ( stype == "STATUSMAP" ) | |
204 | { | |
205 | data = new AliMUONTrackerData(Form("STATUSMAP%d",startOfValidity),"Status map",2,kTRUE); | |
206 | data->SetDimensionName(0,"Bits"); | |
207 | data->SetDimensionName(1,"Dead"); | |
208 | } | |
209 | ||
210 | if (!data) | |
211 | { | |
212 | AliErrorClass(Form("Could not create data for type=%s",type)); | |
213 | return 0x0; | |
214 | } | |
215 | ||
216 | data->Add(store); | |
217 | ||
218 | return data; | |
219 | } | |
220 | ||
221 | //_____________________________________________________________________________ | |
222 | AliMUONVStore* | |
223 | AliMUONTrackerConditionDataMaker::CreateHVStore(TMap& m) | |
224 | { | |
225 | /// Create a store from hv values | |
226 | ||
227 | AliMUONVStore* store = new AliMUON2DMap(kTRUE); | |
228 | ||
229 | TIter next(&m); | |
230 | TObjString* s; | |
231 | AliMpDCSNamer hvNamer("TRACKER"); | |
232 | ||
233 | while ( ( s = static_cast<TObjString*>(next()) ) ) | |
234 | { | |
235 | TString name(s->String()); | |
236 | ||
237 | Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data()); | |
238 | ||
df7fd1ff | 239 | Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data()); |
240 | ||
241 | if ( hvIndex >= 0 && detElemId < 0 ) | |
ca913045 | 242 | { |
243 | // skip switches | |
244 | continue; | |
245 | } | |
ca913045 | 246 | |
247 | if ( !AliMpDEManager::IsValidDetElemId(detElemId) ) | |
248 | { | |
249 | AliErrorClass(Form("Got an invalid DE = %d from alias = %s", | |
250 | detElemId,name.Data())); | |
251 | continue; | |
252 | } | |
df7fd1ff | 253 | |
ca913045 | 254 | Int_t nPCBs = hvNamer.NumberOfPCBs(detElemId); |
b5b2b1cc | 255 | Int_t indexMin = nPCBs ? 0 : hvIndex; |
256 | Int_t indexMax = nPCBs ? nPCBs : hvIndex+1; | |
ca913045 | 257 | |
258 | AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId); | |
259 | ||
b5b2b1cc | 260 | for ( int i = indexMin ; i < indexMax; ++i ) |
ca913045 | 261 | { |
262 | Float_t switchValue(1.0); | |
263 | ||
264 | if ( nPCBs ) | |
265 | { | |
266 | TString switchName(hvNamer.DCSSwitchName(detElemId,i)); | |
267 | ||
268 | TPair* p = static_cast<TPair*>(m.FindObject(switchName.Data())); | |
269 | TObjArray* a = static_cast<TObjArray*>(p->Value()); | |
270 | ||
271 | switchValue = AliMUONPadStatusMaker::SwitchValue(*a); | |
272 | } | |
273 | ||
274 | const AliMpArrayI* manus = de->ManusForHV(i); | |
275 | ||
276 | if (!manus) continue; | |
277 | ||
278 | TPair* p = static_cast<TPair*>(m.FindObject(name.Data())); | |
279 | TObjArray* a = static_cast<TObjArray*>(p->Value()); | |
280 | TIter n2(a); | |
281 | AliDCSValue* v; | |
282 | Float_t hvValue(0); | |
283 | Int_t n(0); | |
284 | while ( ( v = static_cast<AliDCSValue*>(n2()) ) ) | |
285 | { | |
286 | hvValue += v->GetFloat(); | |
287 | ++n; | |
288 | } | |
289 | hvValue *= switchValue; | |
290 | ||
291 | if ( n ) hvValue /= n; | |
292 | ||
293 | Int_t nofChannels(AliMpConstants::ManuNofChannels()); | |
294 | ||
295 | for ( Int_t k = 0 ; k < manus->GetSize(); ++k ) | |
296 | { | |
297 | Int_t manuId = manus->GetValue(k); | |
298 | AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId)); | |
299 | if ( ! param ) | |
300 | { | |
301 | param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0); | |
302 | store->Add(param); | |
303 | } | |
304 | for ( Int_t j = 0 ; j < nofChannels; ++j ) | |
305 | { | |
306 | param->SetValueAsDouble(j,0,hvValue); | |
307 | } | |
308 | } | |
309 | } | |
310 | } | |
311 | ||
312 | return store; | |
313 | ||
314 | } | |
315 | ||
316 | //_____________________________________________________________________________ | |
317 | AliMUONVStore* | |
318 | AliMUONTrackerConditionDataMaker::CreateStatusStore(Int_t runNumber) | |
319 | { | |
320 | /// Get the status store | |
321 | ||
322 | AliMUONDigitCalibrator calibrator(runNumber); | |
323 | ||
324 | AliMUONVStore* sm = new AliMUON2DMap(kTRUE); | |
325 | ||
326 | AliMpManuIterator it; | |
327 | Int_t detElemId, manuId; | |
328 | ||
329 | while (it.Next(detElemId,manuId)) | |
330 | { | |
331 | AliMUONVCalibParam* np = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId); | |
332 | for ( Int_t i = 0; i < np->Size(); ++i ) | |
333 | { | |
334 | Int_t value = calibrator.PadStatus(detElemId,manuId,i); | |
335 | np->SetValueAsInt(i,0,value); // "raw" value of the status | |
336 | } | |
337 | sm->Add(np); | |
338 | } | |
339 | ||
340 | return sm; | |
341 | } | |
342 | ||
343 | //_____________________________________________________________________________ | |
344 | AliMUONVStore* | |
345 | AliMUONTrackerConditionDataMaker::CreateStatusMapStore(Int_t runNumber) | |
346 | { | |
347 | /// Get the status map, and polish it a bit for representation purposes | |
348 | ||
349 | AliMUONDigitCalibrator calibrator(runNumber); | |
350 | ||
351 | AliMUONVStore* sm = new AliMUON2DMap(kTRUE); | |
352 | ||
353 | AliMpManuIterator it; | |
354 | Int_t detElemId, manuId; | |
355 | ||
356 | while (it.Next(detElemId,manuId)) | |
357 | { | |
358 | AliMUONVCalibParam* np = new AliMUONCalibParamNI(2,AliMpConstants::ManuNofChannels(),detElemId,manuId); | |
359 | for ( Int_t i = 0; i < np->Size(); ++i ) | |
360 | { | |
361 | Int_t value = calibrator.StatusMap(detElemId,manuId,i); | |
362 | Int_t channelIsDead = ( value & AliMUONPadStatusMapMaker::SelfDeadMask() ); | |
363 | np->SetValueAsInt(i,0,value); // "raw" value of the status map | |
364 | np->SetValueAsInt(i,1,channelIsDead); // simple 0 or 1 for this channel | |
365 | } | |
366 | sm->Add(np); | |
367 | } | |
368 | ||
369 | return sm; | |
370 | } | |
371 | ||
372 | //_____________________________________________________________________________ | |
373 | AliMUONVStore* | |
374 | AliMUONTrackerConditionDataMaker::CreateStore(Int_t runNumber, | |
375 | const char* source, | |
376 | const char* type, | |
377 | Int_t& startOfValidity) | |
378 | { | |
379 | /// Create the store by reading it from OCDB or from an ASCII file | |
380 | ||
381 | TString stype(type); | |
382 | stype.ToUpper(); | |
383 | ||
384 | AliMUONVStore* store(0x0); | |
385 | ||
386 | startOfValidity = 0; | |
387 | ||
388 | Bool_t ocdb = (runNumber>=0); | |
389 | ||
390 | if ( stype == "CAPACITANCES" ) | |
391 | { | |
392 | if ( ocdb ) | |
393 | { | |
394 | store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity); | |
395 | } | |
396 | else | |
397 | { | |
398 | store = new AliMUON2DMap(20000); | |
399 | AliMUONTrackerIO::DecodeCapacitances(source,*store); | |
400 | } | |
401 | } | |
402 | else if ( stype == "CONFIG" ) | |
403 | { | |
404 | AliMUONVStore* tmp(0x0); | |
405 | if ( ocdb ) | |
406 | { | |
407 | tmp = AliMUONCalibrationData::CreateConfig(runNumber,&startOfValidity); | |
408 | } | |
409 | else | |
410 | { | |
411 | tmp = new AliMUON2DMap(kTRUE); | |
412 | Bool_t changed(kFALSE); | |
413 | AliMUONTrackerIO::DecodeConfig(source,*tmp,changed); | |
414 | } | |
415 | if ( tmp ) | |
416 | { | |
417 | store = ExpandConfig(*tmp); | |
418 | } | |
419 | delete tmp; | |
420 | } | |
421 | else if ( stype == "GAINS" ) | |
422 | { | |
423 | AliMUONVStore* gains(0x0); | |
424 | if ( ocdb ) | |
425 | { | |
426 | gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity); | |
427 | } | |
428 | else | |
429 | { | |
430 | gains = new AliMUON2DMap(kTRUE); | |
431 | TString comment; | |
432 | AliMUONTrackerIO::DecodeGains(source,*gains,comment); | |
433 | } | |
434 | store = PatchGainStore(*gains); | |
435 | delete gains; | |
436 | } | |
437 | else if ( stype == "OCCUPANCY" ) | |
438 | { | |
439 | if ( ocdb ) | |
440 | { | |
441 | store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity); | |
442 | } | |
443 | else | |
444 | { | |
445 | store = new AliMUON2DMap(kTRUE); | |
446 | AliMUONTrackerIO::DecodeOccupancy(source,*store); | |
447 | } | |
448 | } | |
449 | else if ( stype == "PEDESTALS" ) | |
450 | { | |
451 | if ( ocdb ) | |
452 | { | |
453 | store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity); | |
454 | } | |
455 | else | |
456 | { | |
457 | store = new AliMUON2DMap(kTRUE); | |
458 | AliMUONTrackerIO::DecodePedestals(source,*store); | |
459 | } | |
460 | } | |
461 | ||
462 | /// Below are source that can only be accessed from OCDB | |
463 | if (!store && !ocdb) | |
464 | { | |
465 | return 0x0; | |
466 | } | |
467 | ||
468 | if ( stype == "HV" ) | |
469 | { | |
470 | TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity); | |
471 | store = CreateHVStore(*m); | |
472 | delete m; | |
473 | } | |
474 | else if ( stype == "STATUS" ) | |
475 | { | |
476 | store = CreateStatusStore(runNumber); | |
477 | } | |
478 | else if ( stype == "STATUSMAP" ) | |
479 | { | |
480 | store = CreateStatusMapStore(runNumber); | |
481 | } | |
482 | ||
483 | return store; | |
484 | } | |
485 | ||
486 | //_____________________________________________________________________________ | |
487 | AliMUONVStore* | |
488 | AliMUONTrackerConditionDataMaker::ExpandConfig(const AliMUONVStore& manuConfig) | |
489 | { | |
490 | /// Convert the config from manu level to channel level (just to | |
491 | /// be able to add it correctly to the trackerdata...) | |
492 | ||
493 | AliMUONVStore* store = manuConfig.Create(); | |
494 | ||
495 | TIter next(manuConfig.CreateIterator()); | |
496 | AliMUONVCalibParam* p; | |
497 | ||
498 | while ( ( p = static_cast<AliMUONVCalibParam*>(next()) ) ) | |
499 | { | |
500 | AliMUONVCalibParam* c = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),p->ID0(),p->ID1(),0.0); | |
501 | ||
502 | AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(p->ID0()); | |
503 | ||
504 | for ( Int_t i = 0; i < c->Size(); ++i ) | |
505 | { | |
506 | if ( de->IsExistingChannel(p->ID1(),i) ) | |
507 | { | |
508 | c->SetValueAsFloat(i,0,1.0); | |
509 | } | |
510 | } | |
511 | ||
512 | store->Add(c); | |
513 | } | |
514 | return store; | |
515 | } | |
516 | ||
517 | //_____________________________________________________________________________ | |
518 | Long64_t | |
519 | AliMUONTrackerConditionDataMaker::Merge(TCollection*) | |
520 | { | |
521 | /// Merge | |
522 | AliError("Not implemented. Does it have sense ?"); | |
523 | return 0; | |
524 | } | |
525 | ||
526 | //_____________________________________________________________________________ | |
527 | AliMUONVStore* | |
528 | AliMUONTrackerConditionDataMaker::PatchGainStore(const AliMUONVStore& gains) | |
529 | { | |
530 | /// Polish the gain store : | |
531 | /// a) adding a dimension, computed from a1, and called gain = 1/a1/0.2 | |
532 | /// where 0.2 is internal capa in pF, and gain is then in mV/fC | |
533 | /// b) splitting the quality in two | |
534 | ||
535 | AliMUONVStore* store = gains.Create(); | |
536 | ||
537 | TIter next(gains.CreateIterator()); | |
538 | AliMUONVCalibParam* param; | |
539 | ||
540 | while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) ) | |
541 | { | |
542 | AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+2, | |
543 | param->Size(), | |
544 | param->ID0(), | |
545 | param->ID1()); | |
546 | for ( Int_t i = 0; i < param->Size(); ++i ) | |
547 | { | |
548 | ||
549 | Int_t qual = param->ValueAsInt(i,3); | |
550 | Int_t q1 = (qual & 0xF0) >> 4; // linear fit quality | |
551 | Int_t q2 = qual & 0xF; // parabolic fit quality | |
552 | Double_t gain = 0.0; | |
553 | ||
554 | if ( param->ValueAsFloat(i,0) > 1E-9 ) gain = 1.0/param->ValueAsFloat(i,0)/0.2; | |
555 | ||
556 | nd->SetValueAsDouble(i,0,gain); // gain | |
557 | nd->SetValueAsDouble(i,1,param->ValueAsFloat(i,0)); // a1 | |
558 | nd->SetValueAsDouble(i,2,param->ValueAsFloat(i,1)); // a2 | |
559 | nd->SetValueAsInt(i,3,param->ValueAsInt(i,2)); // thres | |
560 | nd->SetValueAsInt(i,4,q1); // qual1 | |
561 | nd->SetValueAsInt(i,5,q2); // qual2 | |
562 | nd->SetValueAsInt(i,6,param->ValueAsInt(i,4)); // sat | |
563 | } | |
564 | store->Add(nd); | |
565 | } | |
566 | ||
567 | return store; | |
568 | } | |
569 |