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"
58 //_____________________________________________________________________________
59 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(Int_t runNumber, const char* ocdbPath, const char* type):
60 AliMUONVTrackerDataMaker(),
62 fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type))
66 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
68 AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
70 Int_t startOfValidity;
71 AliMUONVStore* store = CreateStore(runNumber,ocdbPath,type,startOfValidity);
72 AliInfo(Form("runNumber=%d ocdbPath=%s type=%s startOfValidity=%d store=%p",
73 runNumber,ocdbPath,type,startOfValidity,store));
76 fData = CreateData(type,*store,startOfValidity);
81 AliCDBManager::Instance()->SetDefaultStorage(storage);
84 //_____________________________________________________________________________
85 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* filename, const char* type):
86 AliMUONVTrackerDataMaker(),
88 fSource(Form("%s-%s",filename,type))
90 /// ctor from an ASCII file
92 TString sFilename(gSystem->ExpandPathName(filename));
94 std::ifstream in(sFilename.Data());
97 std::ostringstream stream;
99 while ( in.getline(line,1024) )
101 stream << line << "\n";
108 AliMUONVStore* store = CreateStore(-1,stream.str().c_str(),type,dummy);
112 fData = CreateData(type,*store,dummy);
118 //_____________________________________________________________________________
119 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* data, const char* type, Bool_t) :
120 AliMUONVTrackerDataMaker(),
122 fSource(Form("direct-%s",type))
124 /// ctor from a string containing the ASCII data
125 /// the last parameter is there just to distinguish this ctor from the previous one
129 AliMUONVStore* store = CreateStore(-1,data,type,dummy);
133 fData = CreateData(type,*store,dummy);
139 //_____________________________________________________________________________
140 AliMUONTrackerConditionDataMaker::~AliMUONTrackerConditionDataMaker()
147 //_____________________________________________________________________________
149 AliMUONTrackerConditionDataMaker::CreateData(const char* type, AliMUONVStore& store, Int_t startOfValidity)
151 /// Create the data source
152 AliMUONVTrackerData* data(0x0);
157 if ( stype == "CAPACITANCES" )
159 data = new AliMUONTrackerData(Form("CAPA%d",startOfValidity),"Capacitances",2,kTRUE);
160 data->SetDimensionName(0,"Capa");
161 data->SetDimensionName(1,"Injection gain");
163 else if ( stype == "CONFIG" )
165 data = new AliMUONTrackerData(Form("CONFIG%d",startOfValidity),"Configuration",1);
166 data->SetDimensionName(0,"there");
167 data->DisableChannelLevel();
169 else if ( stype == "GAINS" )
171 data = new AliMUONTrackerData(Form("GAIN%d",startOfValidity),"Gains",7,kTRUE);
172 data->SetDimensionName(0,"gain");
173 data->SetDimensionName(1,"a1");
174 data->SetDimensionName(2,"a2");
175 data->SetDimensionName(3,"thres");
176 data->SetDimensionName(4,"qual1");
177 data->SetDimensionName(5,"qual2");
178 data->SetDimensionName(6,"sat");
180 else if ( stype == "HV" )
182 data = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1); //,!isSingleEvent);
183 data->SetDimensionName(0,"HV");
185 else if ( stype == "OCCUPANCY" )
187 data = new AliMUONTrackerData(Form("OCC%d",startOfValidity),"OccupancyMap",store);
188 data->SetDimensionName(0,"One");
189 return data; // important to return now to avoid the data->Add(store) later on...
191 else if ( stype == "PEDESTALS" )
193 data = new AliMUONTrackerData(Form("PED%d",startOfValidity),"Pedestals",2,kTRUE);
194 data->SetDimensionName(0,"Mean");
195 data->SetDimensionName(1,"Sigma");
197 else if ( stype == "STATUS" )
199 data = new AliMUONTrackerData(Form("STATUS%d",startOfValidity),"Status",1,kTRUE);
200 data->SetDimensionName(0,"Bits");
202 else if ( stype == "STATUSMAP" )
204 data = new AliMUONTrackerData(Form("STATUSMAP%d",startOfValidity),"Status map",2,kTRUE);
205 data->SetDimensionName(0,"Bits");
206 data->SetDimensionName(1,"Dead");
211 AliErrorClass(Form("Could not create data for type=%s",type));
220 //_____________________________________________________________________________
222 AliMUONTrackerConditionDataMaker::CreateHVStore(TMap& m)
224 /// Create a store from hv values
226 AliMUONVStore* store = new AliMUON2DMap(kTRUE);
230 AliMpDCSNamer hvNamer("TRACKER");
232 while ( ( s = static_cast<TObjString*>(next()) ) )
234 TString name(s->String());
236 Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
244 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
246 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
248 AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
249 detElemId,name.Data()));
253 Int_t nPCBs = hvNamer.NumberOfPCBs(detElemId);
254 Int_t nindex = nPCBs ? nPCBs : 1;
256 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
258 for ( int i = 0 ; i < nindex; ++i )
260 Float_t switchValue(1.0);
264 TString switchName(hvNamer.DCSSwitchName(detElemId,i));
266 TPair* p = static_cast<TPair*>(m.FindObject(switchName.Data()));
267 TObjArray* a = static_cast<TObjArray*>(p->Value());
269 switchValue = AliMUONPadStatusMaker::SwitchValue(*a);
272 const AliMpArrayI* manus = de->ManusForHV(i);
274 if (!manus) continue;
276 TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
277 TObjArray* a = static_cast<TObjArray*>(p->Value());
282 while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
284 hvValue += v->GetFloat();
287 hvValue *= switchValue;
289 if ( n ) hvValue /= n;
291 Int_t nofChannels(AliMpConstants::ManuNofChannels());
293 for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
295 Int_t manuId = manus->GetValue(k);
296 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
299 param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
302 for ( Int_t j = 0 ; j < nofChannels; ++j )
304 param->SetValueAsDouble(j,0,hvValue);
314 //_____________________________________________________________________________
316 AliMUONTrackerConditionDataMaker::CreateStatusStore(Int_t runNumber)
318 /// Get the status store
320 AliMUONDigitCalibrator calibrator(runNumber);
322 AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
324 AliMpManuIterator it;
325 Int_t detElemId, manuId;
327 while (it.Next(detElemId,manuId))
329 AliMUONVCalibParam* np = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId);
330 for ( Int_t i = 0; i < np->Size(); ++i )
332 Int_t value = calibrator.PadStatus(detElemId,manuId,i);
333 np->SetValueAsInt(i,0,value); // "raw" value of the status
341 //_____________________________________________________________________________
343 AliMUONTrackerConditionDataMaker::CreateStatusMapStore(Int_t runNumber)
345 /// Get the status map, and polish it a bit for representation purposes
347 AliMUONDigitCalibrator calibrator(runNumber);
349 AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
351 AliMpManuIterator it;
352 Int_t detElemId, manuId;
354 while (it.Next(detElemId,manuId))
356 AliMUONVCalibParam* np = new AliMUONCalibParamNI(2,AliMpConstants::ManuNofChannels(),detElemId,manuId);
357 for ( Int_t i = 0; i < np->Size(); ++i )
359 Int_t value = calibrator.StatusMap(detElemId,manuId,i);
360 Int_t channelIsDead = ( value & AliMUONPadStatusMapMaker::SelfDeadMask() );
361 np->SetValueAsInt(i,0,value); // "raw" value of the status map
362 np->SetValueAsInt(i,1,channelIsDead); // simple 0 or 1 for this channel
370 //_____________________________________________________________________________
372 AliMUONTrackerConditionDataMaker::CreateStore(Int_t runNumber,
375 Int_t& startOfValidity)
377 /// Create the store by reading it from OCDB or from an ASCII file
382 AliMUONVStore* store(0x0);
386 Bool_t ocdb = (runNumber>=0);
388 if ( stype == "CAPACITANCES" )
392 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
396 store = new AliMUON2DMap(20000);
397 AliMUONTrackerIO::DecodeCapacitances(source,*store);
400 else if ( stype == "CONFIG" )
402 AliMUONVStore* tmp(0x0);
405 tmp = AliMUONCalibrationData::CreateConfig(runNumber,&startOfValidity);
409 tmp = new AliMUON2DMap(kTRUE);
410 Bool_t changed(kFALSE);
411 AliMUONTrackerIO::DecodeConfig(source,*tmp,changed);
415 store = ExpandConfig(*tmp);
419 else if ( stype == "GAINS" )
421 AliMUONVStore* gains(0x0);
424 gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
428 gains = new AliMUON2DMap(kTRUE);
430 AliMUONTrackerIO::DecodeGains(source,*gains,comment);
432 store = PatchGainStore(*gains);
435 else if ( stype == "OCCUPANCY" )
439 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
443 store = new AliMUON2DMap(kTRUE);
444 AliMUONTrackerIO::DecodeOccupancy(source,*store);
447 else if ( stype == "PEDESTALS" )
451 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
455 store = new AliMUON2DMap(kTRUE);
456 AliMUONTrackerIO::DecodePedestals(source,*store);
460 /// Below are source that can only be accessed from OCDB
468 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
469 store = CreateHVStore(*m);
472 else if ( stype == "STATUS" )
474 store = CreateStatusStore(runNumber);
476 else if ( stype == "STATUSMAP" )
478 store = CreateStatusMapStore(runNumber);
484 //_____________________________________________________________________________
486 AliMUONTrackerConditionDataMaker::ExpandConfig(const AliMUONVStore& manuConfig)
488 /// Convert the config from manu level to channel level (just to
489 /// be able to add it correctly to the trackerdata...)
491 AliMUONVStore* store = manuConfig.Create();
493 TIter next(manuConfig.CreateIterator());
494 AliMUONVCalibParam* p;
496 while ( ( p = static_cast<AliMUONVCalibParam*>(next()) ) )
498 AliMUONVCalibParam* c = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),p->ID0(),p->ID1(),0.0);
500 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(p->ID0());
502 for ( Int_t i = 0; i < c->Size(); ++i )
504 if ( de->IsExistingChannel(p->ID1(),i) )
506 c->SetValueAsFloat(i,0,1.0);
515 //_____________________________________________________________________________
517 AliMUONTrackerConditionDataMaker::Merge(TCollection*)
520 AliError("Not implemented. Does it have sense ?");
524 //_____________________________________________________________________________
526 AliMUONTrackerConditionDataMaker::PatchGainStore(const AliMUONVStore& gains)
528 /// Polish the gain store :
529 /// a) adding a dimension, computed from a1, and called gain = 1/a1/0.2
530 /// where 0.2 is internal capa in pF, and gain is then in mV/fC
531 /// b) splitting the quality in two
533 AliMUONVStore* store = gains.Create();
535 TIter next(gains.CreateIterator());
536 AliMUONVCalibParam* param;
538 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
540 AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+2,
544 for ( Int_t i = 0; i < param->Size(); ++i )
547 Int_t qual = param->ValueAsInt(i,3);
548 Int_t q1 = (qual & 0xF0) >> 4; // linear fit quality
549 Int_t q2 = qual & 0xF; // parabolic fit quality
552 if ( param->ValueAsFloat(i,0) > 1E-9 ) gain = 1.0/param->ValueAsFloat(i,0)/0.2;
554 nd->SetValueAsDouble(i,0,gain); // gain
555 nd->SetValueAsDouble(i,1,param->ValueAsFloat(i,0)); // a1
556 nd->SetValueAsDouble(i,2,param->ValueAsFloat(i,1)); // a2
557 nd->SetValueAsInt(i,3,param->ValueAsInt(i,2)); // thres
558 nd->SetValueAsInt(i,4,q1); // qual1
559 nd->SetValueAsInt(i,5,q2); // qual2
560 nd->SetValueAsInt(i,6,param->ValueAsInt(i,4)); // sat