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 "AliMUONTrackerConditionDataMaker.h"
20 ///\class AliMUONTrackerConditionDataMaker
22 /// Producer of AliMUONVTrackerData from OCDB or Ascii file condition data
24 /// \author Laurent Aphecetche, Subatech
27 ClassImp(AliMUONTrackerConditionDataMaker)
30 #include "AliCDBManager.h"
31 #include "AliCDBStorage.h"
32 #include "AliDCSValue.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"
53 #include "TObjString.h"
54 #include "Riostream.h"
59 //_____________________________________________________________________________
60 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker():
61 AliMUONVTrackerDataMaker(),
66 /// default ctor to be able to stream
69 //_____________________________________________________________________________
70 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(Int_t runNumber, const char* ocdbPath, const char* type):
71 AliMUONVTrackerDataMaker(),
73 fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type)),
78 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
80 AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
82 Int_t startOfValidity;
83 AliMUONVStore* store = CreateStore(runNumber,ocdbPath,type,startOfValidity);
84 AliDebug(1,Form("runNumber=%d ocdbPath=%s type=%s startOfValidity=%d store=%p",
85 runNumber,ocdbPath,type,startOfValidity,store));
88 fData = CreateData(type,*store,startOfValidity);
93 AliCDBManager::Instance()->SetDefaultStorage(storage);
96 //_____________________________________________________________________________
97 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* filename, const char* type):
98 AliMUONVTrackerDataMaker(),
100 fSource(Form("%s-%s",filename,type)),
101 fIsOwnerOfData(kTRUE)
103 /// ctor from an ASCII file
105 TString sFilename(gSystem->ExpandPathName(filename));
107 std::ifstream in(sFilename.Data());
110 std::ostringstream stream;
112 while ( in.getline(line,1024) )
114 stream << line << "\n";
121 AliMUONVStore* store = CreateStore(-1,stream.str().c_str(),type,dummy);
125 fData = CreateData(type,*store,dummy);
131 //_____________________________________________________________________________
132 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* data, const char* type, Bool_t) :
133 AliMUONVTrackerDataMaker(),
135 fSource(Form("direct-%s",type)),
136 fIsOwnerOfData(kTRUE)
139 /// ctor from a string containing the ASCII data
140 /// the last parameter is there just to distinguish this ctor from the previous one
144 AliMUONVStore* store = CreateStore(-1,data,type,dummy);
148 fData = CreateData(type,*store,dummy);
154 //_____________________________________________________________________________
155 AliMUONTrackerConditionDataMaker::~AliMUONTrackerConditionDataMaker()
158 if ( fIsOwnerOfData ) delete fData;
162 //_____________________________________________________________________________
164 AliMUONTrackerConditionDataMaker::CreateData(const char* type, AliMUONVStore& store, Int_t startOfValidity)
166 /// Create the data source
167 AliMUONVTrackerData* data(0x0);
172 if ( stype == "CAPACITANCES" )
174 data = new AliMUONTrackerData(Form("CAPA%d",startOfValidity),"Capacitances",2,kTRUE);
175 data->SetDimensionName(0,"Capa");
176 data->SetDimensionName(1,"Injection gain");
178 else if ( stype == "CONFIG" )
180 data = new AliMUONTrackerData(Form("CONFIG%d",startOfValidity),"Configuration",1);
181 data->SetDimensionName(0,"there");
182 data->DisableChannelLevel();
184 else if ( stype == "GAINS" )
186 data = new AliMUONTrackerData(Form("GAIN%d",startOfValidity),"Gains",7,kTRUE);
187 data->SetDimensionName(0,"gain");
188 data->SetDimensionName(1,"a1");
189 data->SetDimensionName(2,"a2");
190 data->SetDimensionName(3,"thres");
191 data->SetDimensionName(4,"qual1");
192 data->SetDimensionName(5,"qual2");
193 data->SetDimensionName(6,"sat");
195 else if ( stype == "HV" )
197 data = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1); //,!isSingleEvent);
198 data->SetDimensionName(0,"HV");
200 else if ( stype == "OCCUPANCY" )
202 data = new AliMUONTrackerData(Form("OCC%d",startOfValidity),"OccupancyMap",store);
203 data->SetDimensionName(0,"One");
204 return data; // important to return now to avoid the data->Add(store) later on...
206 else if ( stype == "PEDESTALS" )
208 data = new AliMUONTrackerData(Form("PED%d",startOfValidity),"Pedestals",2,kTRUE);
209 data->SetDimensionName(0,"Mean");
210 data->SetDimensionName(1,"Sigma");
212 else if ( stype == "STATUS" )
214 data = new AliMUONTrackerData(Form("STATUS%d",startOfValidity),"Status",1,kTRUE);
215 data->SetDimensionName(0,"Bits");
217 else if ( stype == "STATUSMAP" )
219 data = new AliMUONTrackerData(Form("STATUSMAP%d",startOfValidity),"Status map",2,kTRUE);
220 data->SetDimensionName(0,"Bits");
221 data->SetDimensionName(1,"Dead");
226 AliErrorClass(Form("Could not create data for type=%s",type));
235 //_____________________________________________________________________________
237 AliMUONTrackerConditionDataMaker::CreateHVStore(TMap& m)
239 /// Create a store from hv values
241 AliMUONVStore* store = new AliMUON2DMap(kTRUE);
245 AliMpDCSNamer hvNamer("TRACKER");
247 while ( ( s = static_cast<TObjString*>(next()) ) )
249 TString name(s->String());
251 Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
253 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
255 if ( hvIndex >= 0 && detElemId < 0 )
261 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
263 AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
264 detElemId,name.Data()));
268 Int_t nPCBs = hvNamer.NumberOfPCBs(detElemId);
269 Int_t indexMin = nPCBs ? 0 : hvIndex;
270 Int_t indexMax = nPCBs ? nPCBs : hvIndex+1;
272 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
274 for ( int i = indexMin ; i < indexMax; ++i )
276 Float_t switchValue(1.0);
280 TString switchName(hvNamer.DCSSwitchName(detElemId,i));
282 TPair* p = static_cast<TPair*>(m.FindObject(switchName.Data()));
283 TObjArray* a = static_cast<TObjArray*>(p->Value());
285 switchValue = AliMUONPadStatusMaker::SwitchValue(*a);
288 const AliMpArrayI* manus = de->ManusForHV(i);
290 if (!manus) continue;
292 TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
293 TObjArray* a = static_cast<TObjArray*>(p->Value());
298 while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
300 hvValue += v->GetFloat();
303 hvValue *= switchValue;
305 if ( n ) hvValue /= n;
307 Int_t nofChannels(AliMpConstants::ManuNofChannels());
309 for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
311 Int_t manuId = manus->GetValue(k);
312 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
315 param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
318 for ( Int_t j = 0 ; j < nofChannels; ++j )
320 param->SetValueAsDouble(j,0,hvValue);
330 //_____________________________________________________________________________
332 AliMUONTrackerConditionDataMaker::CreateStatusStore(Int_t runNumber)
334 /// Get the status store
336 AliMUONDigitCalibrator calibrator(runNumber);
338 AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
340 AliMpManuIterator it;
341 Int_t detElemId, manuId;
343 while (it.Next(detElemId,manuId))
345 AliMUONVCalibParam* np = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId);
346 for ( Int_t i = 0; i < np->Size(); ++i )
348 Int_t value = calibrator.PadStatus(detElemId,manuId,i);
349 np->SetValueAsInt(i,0,value); // "raw" value of the status
357 //_____________________________________________________________________________
359 AliMUONTrackerConditionDataMaker::CreateStatusMapStore(Int_t runNumber)
361 /// Get the status map, and polish it a bit for representation purposes
363 AliMUONDigitCalibrator calibrator(runNumber);
365 AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
367 AliMpManuIterator it;
368 Int_t detElemId, manuId;
370 while (it.Next(detElemId,manuId))
372 AliMUONVCalibParam* np = new AliMUONCalibParamNI(2,AliMpConstants::ManuNofChannels(),detElemId,manuId);
373 for ( Int_t i = 0; i < np->Size(); ++i )
375 Int_t value = calibrator.StatusMap(detElemId,manuId,i);
376 Int_t channelIsDead = ( value & AliMUONPadStatusMapMaker::SelfDeadMask() );
377 np->SetValueAsInt(i,0,value); // "raw" value of the status map
378 np->SetValueAsInt(i,1,channelIsDead); // simple 0 or 1 for this channel
386 //_____________________________________________________________________________
388 AliMUONTrackerConditionDataMaker::CreateStore(Int_t runNumber,
391 Int_t& startOfValidity)
393 /// Create the store by reading it from OCDB or from an ASCII file
398 AliMUONVStore* store(0x0);
402 Bool_t ocdb = (runNumber>=0);
404 if ( stype == "CAPACITANCES" )
408 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
412 store = new AliMUON2DMap(20000);
413 AliMUONTrackerIO::DecodeCapacitances(source,*store);
416 else if ( stype == "CONFIG" )
418 AliMUONVStore* tmp(0x0);
421 tmp = AliMUONCalibrationData::CreateConfig(runNumber,&startOfValidity);
425 tmp = new AliMUON2DMap(kTRUE);
426 AliMUONTrackerIO::DecodeConfig(source,*tmp);
430 store = ExpandConfig(*tmp);
434 else if ( stype == "GAINS" )
436 AliMUONVStore* gains(0x0);
439 gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
443 gains = new AliMUON2DMap(kTRUE);
445 AliMUONTrackerIO::DecodeGains(source,*gains,comment);
447 store = PatchGainStore(*gains);
450 else if ( stype == "OCCUPANCY" )
454 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
458 store = new AliMUON2DMap(kTRUE);
459 AliMUONTrackerIO::DecodeOccupancy(source,*store);
462 else if ( stype == "PEDESTALS" )
466 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
470 store = new AliMUON2DMap(kTRUE);
471 AliMUONTrackerIO::DecodePedestals(source,*store);
475 /// Below are source that can only be accessed from OCDB
483 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
484 store = CreateHVStore(*m);
487 else if ( stype == "STATUS" )
489 store = CreateStatusStore(runNumber);
491 else if ( stype == "STATUSMAP" )
493 store = CreateStatusMapStore(runNumber);
499 //_____________________________________________________________________________
501 AliMUONTrackerConditionDataMaker::ExpandConfig(const AliMUONVStore& manuConfig)
503 /// Convert the config from manu level to channel level (just to
504 /// be able to add it correctly to the trackerdata...)
506 AliMUONVStore* store = manuConfig.Create();
508 TIter next(manuConfig.CreateIterator());
509 AliMUONVCalibParam* p;
511 while ( ( p = static_cast<AliMUONVCalibParam*>(next()) ) )
513 AliMUONVCalibParam* c = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),p->ID0(),p->ID1(),0.0);
515 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(p->ID0());
517 for ( Int_t i = 0; i < c->Size(); ++i )
519 if ( de->IsExistingChannel(p->ID1(),i) )
521 c->SetValueAsFloat(i,0,1.0);
530 //_____________________________________________________________________________
532 AliMUONTrackerConditionDataMaker::Merge(TCollection*)
535 AliError("Not implemented. Does it have sense ?");
539 //_____________________________________________________________________________
541 AliMUONTrackerConditionDataMaker::PatchGainStore(const AliMUONVStore& gains)
543 /// Polish the gain store :
544 /// a) adding a dimension, computed from a1, and called gain = 1/a1/0.2
545 /// where 0.2 is internal capa in pF, and gain is then in mV/fC
546 /// b) splitting the quality in two
548 AliMUONVStore* store = gains.Create();
550 TIter next(gains.CreateIterator());
551 AliMUONVCalibParam* param;
553 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
555 AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+2,
559 for ( Int_t i = 0; i < param->Size(); ++i )
562 Int_t qual = param->ValueAsInt(i,3);
563 Int_t q1 = (qual & 0xF0) >> 4; // linear fit quality
564 Int_t q2 = qual & 0xF; // parabolic fit quality
567 if ( param->ValueAsFloat(i,0) > 1E-9 ) gain = 1.0/param->ValueAsFloat(i,0)/0.2;
569 nd->SetValueAsDouble(i,0,gain); // gain
570 nd->SetValueAsDouble(i,1,param->ValueAsFloat(i,0)); // a1
571 nd->SetValueAsDouble(i,2,param->ValueAsFloat(i,1)); // a2
572 nd->SetValueAsInt(i,3,param->ValueAsInt(i,2)); // thres
573 nd->SetValueAsInt(i,4,q1); // qual1
574 nd->SetValueAsInt(i,5,q2); // qual2
575 nd->SetValueAsInt(i,6,param->ValueAsInt(i,4)); // sat