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 "AliMUONRejectList.h"
44 #include "AliMUONTrackerData.h"
45 #include "AliMUONTrackerIO.h"
46 #include "AliMpArrayI.h"
47 #include "AliMpConstants.h"
48 #include "AliMpDCSNamer.h"
49 #include "AliMpDDLStore.h"
50 #include "AliMpDEManager.h"
51 #include "AliMpDetElement.h"
54 #include "TObjString.h"
55 #include "Riostream.h"
60 //_____________________________________________________________________________
61 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker():
62 AliMUONVTrackerDataMaker(),
67 /// default ctor to be able to stream
70 //_____________________________________________________________________________
71 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(Int_t runNumber, const char* ocdbPath, const char* type):
72 AliMUONVTrackerDataMaker(),
74 fSource(Form("%s-%010d-%s",ocdbPath,runNumber,type)),
79 AliCDBStorage* storage = AliCDBManager::Instance()->GetDefaultStorage();
81 AliCDBManager::Instance()->SetDefaultStorage(ocdbPath);
86 if ( stype == "REJECTLIST" )
89 Int_t startOfValidity(0);
91 AliMUONRejectList* rl = AliMUONCalibrationData::CreateRejectList(runNumber,&startOfValidity);
95 fData = new AliMUONTrackerData(Form("RL%d",startOfValidity),"RejectList",*rl);
102 Int_t startOfValidity;
103 AliMUONVStore* store = CreateStore(runNumber,ocdbPath,type,startOfValidity);
104 AliDebug(1,Form("runNumber=%d ocdbPath=%s type=%s startOfValidity=%d store=%p",
105 runNumber,ocdbPath,type,startOfValidity,store));
108 fData = CreateData(type,*store,startOfValidity);
115 TString name(fData->GetName());
119 fData->SetName(name);
122 AliCDBManager::Instance()->SetDefaultStorage(storage);
125 //_____________________________________________________________________________
126 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* filename, const char* type):
127 AliMUONVTrackerDataMaker(),
129 fSource(Form("%s-%s",filename,type)),
130 fIsOwnerOfData(kTRUE)
132 /// ctor from an ASCII file
134 TString sFilename(gSystem->ExpandPathName(filename));
136 std::ifstream in(sFilename.Data());
139 std::ostringstream stream;
141 while ( in.getline(line,1024) )
143 stream << line << "\n";
150 AliMUONVStore* store = CreateStore(-1,stream.str().c_str(),type,dummy);
154 fData = CreateData(type,*store,dummy);
160 //_____________________________________________________________________________
161 AliMUONTrackerConditionDataMaker::AliMUONTrackerConditionDataMaker(const char* data, const char* type, Bool_t) :
162 AliMUONVTrackerDataMaker(),
164 fSource(Form("direct-%s",type)),
165 fIsOwnerOfData(kTRUE)
168 /// ctor from a string containing the ASCII data
169 /// the last parameter is there just to distinguish this ctor from the previous one
173 AliMUONVStore* store = CreateStore(-1,data,type,dummy);
177 fData = CreateData(type,*store,dummy);
183 //_____________________________________________________________________________
184 AliMUONTrackerConditionDataMaker::~AliMUONTrackerConditionDataMaker()
187 if ( fIsOwnerOfData ) delete fData;
191 //_____________________________________________________________________________
193 AliMUONTrackerConditionDataMaker::CreateData(const char* type, AliMUONVStore& store, Int_t startOfValidity)
195 /// Create the data source
196 AliMUONVTrackerData* data(0x0);
201 if ( stype == "CAPACITANCES" )
203 data = new AliMUONTrackerData(Form("CAPA%d",startOfValidity),"Capacitances",2,kTRUE);
204 data->SetDimensionName(0,"Capa");
205 data->SetDimensionName(1,"Injection gain");
207 else if ( stype == "CONFIG" )
209 data = new AliMUONTrackerData(Form("CONFIG%d",startOfValidity),"Configuration",1);
210 data->SetDimensionName(0,"there");
211 data->DisableChannelLevel();
213 else if ( stype == "GAINS" )
215 data = new AliMUONTrackerData(Form("GAIN%d",startOfValidity),"Gains",7,kTRUE);
216 data->SetDimensionName(0,"gain");
217 data->SetDimensionName(1,"a1");
218 data->SetDimensionName(2,"a2");
219 data->SetDimensionName(3,"thres");
220 data->SetDimensionName(4,"qual1");
221 data->SetDimensionName(5,"qual2");
222 data->SetDimensionName(6,"sat");
224 else if ( stype == "HV" )
226 data = new AliMUONTrackerData(Form("HV%d",startOfValidity),"High Voltages",1); //,!isSingleEvent);
227 data->SetDimensionName(0,"HV");
229 else if ( stype == "OCCUPANCY" )
231 data = new AliMUONTrackerData(Form("OCC%d",startOfValidity),"OccupancyMap",store);
232 data->SetDimensionName(0,"One");
233 return data; // important to return now to avoid the data->Add(store) later on...
235 else if ( stype == "PEDESTALS" )
237 data = new AliMUONTrackerData(Form("PED%d",startOfValidity),"Pedestals",2,kTRUE);
238 data->SetDimensionName(0,"Mean");
239 data->SetDimensionName(1,"Sigma");
241 else if ( stype == "STATUS" )
243 data = new AliMUONTrackerData(Form("STATUS%d",startOfValidity),"Status",1,kTRUE);
244 data->SetDimensionName(0,"Bits");
246 else if ( stype == "STATUSMAP" )
248 data = new AliMUONTrackerData(Form("STATUSMAP%d",startOfValidity),"Status map",2,kTRUE);
249 data->SetDimensionName(0,"Bits");
250 data->SetDimensionName(1,"Dead");
255 AliErrorClass(Form("Could not create data for type=%s",type));
264 //_____________________________________________________________________________
266 AliMUONTrackerConditionDataMaker::CreateHVStore(TMap& m)
268 /// Create a store from hv values
270 AliMUONVStore* store = new AliMUON2DMap(kTRUE);
274 AliMpDCSNamer hvNamer("TRACKER");
276 while ( ( s = static_cast<TObjString*>(next()) ) )
278 TString name(s->String());
280 Int_t hvIndex = hvNamer.DCSIndexFromDCSAlias(name.Data());
282 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
284 if ( hvIndex >= 0 && detElemId < 0 )
290 if ( !AliMpDEManager::IsValidDetElemId(detElemId) )
292 AliErrorClass(Form("Got an invalid DE = %d from alias = %s",
293 detElemId,name.Data()));
297 Int_t nPCBs = hvNamer.NumberOfPCBs(detElemId);
298 Int_t indexMin = nPCBs ? 0 : hvIndex;
299 Int_t indexMax = nPCBs ? nPCBs : hvIndex+1;
301 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
303 for ( int i = indexMin ; i < indexMax; ++i )
305 Float_t switchValue(1.0);
309 TString switchName(hvNamer.DCSSwitchAliasName(detElemId,i));
311 TPair* p = static_cast<TPair*>(m.FindObject(switchName.Data()));
312 TObjArray* a = static_cast<TObjArray*>(p->Value());
314 switchValue = AliMUONPadStatusMaker::SwitchValue(*a);
317 const AliMpArrayI* manus = de->ManusForHV(i);
319 if (!manus) continue;
321 TPair* p = static_cast<TPair*>(m.FindObject(name.Data()));
322 TObjArray* a = static_cast<TObjArray*>(p->Value());
329 while ( ( v = static_cast<AliDCSValue*>(n2()) ) )
331 hvValue += v->GetFloat();
332 if ( v->GetFloat() < AliMpDCSNamer::TrackerHVOFF() ) ++noff;
335 hvValue *= switchValue;
337 if ( n ) hvValue /= n;
339 if (noff>0 && noff<n)
345 Int_t nofChannels(AliMpConstants::ManuNofChannels());
347 for ( Int_t k = 0 ; k < manus->GetSize(); ++k )
349 Int_t manuId = manus->GetValue(k);
350 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(store->FindObject(detElemId,manuId));
353 param = new AliMUONCalibParamND(1,nofChannels,detElemId,manuId,0);
356 for ( Int_t j = 0 ; j < nofChannels; ++j )
358 param->SetValueAsDouble(j,0,hvValue);
368 //_____________________________________________________________________________
370 AliMUONTrackerConditionDataMaker::CreateStatusStore(Int_t runNumber)
372 /// Get the status store
374 AliMUONDigitCalibrator calibrator(runNumber);
376 AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
378 AliMpManuIterator it;
379 Int_t detElemId, manuId;
381 while (it.Next(detElemId,manuId))
383 AliMUONVCalibParam* np = new AliMUONCalibParamNI(1,AliMpConstants::ManuNofChannels(),detElemId,manuId);
384 for ( Int_t i = 0; i < np->Size(); ++i )
386 Int_t value = calibrator.PadStatus(detElemId,manuId,i);
387 np->SetValueAsInt(i,0,value); // "raw" value of the status
395 //_____________________________________________________________________________
397 AliMUONTrackerConditionDataMaker::CreateStatusMapStore(Int_t runNumber)
399 /// Get the status map, and polish it a bit for representation purposes
401 AliMUONDigitCalibrator calibrator(runNumber);
403 AliMUONVStore* sm = new AliMUON2DMap(kTRUE);
405 AliMpManuIterator it;
406 Int_t detElemId, manuId;
408 while (it.Next(detElemId,manuId))
410 AliMUONVCalibParam* np = new AliMUONCalibParamNI(2,AliMpConstants::ManuNofChannels(),detElemId,manuId);
411 for ( Int_t i = 0; i < np->Size(); ++i )
413 Int_t value = calibrator.StatusMap(detElemId,manuId,i);
414 Int_t channelIsDead = ( value & AliMUONPadStatusMapMaker::SelfDeadMask() );
415 np->SetValueAsInt(i,0,value); // "raw" value of the status map
416 np->SetValueAsInt(i,1,channelIsDead); // simple 0 or 1 for this channel
424 //_____________________________________________________________________________
426 AliMUONTrackerConditionDataMaker::CreateStore(Int_t runNumber,
429 Int_t& startOfValidity)
431 /// Create the store by reading it from OCDB or from an ASCII file
436 AliMUONVStore* store(0x0);
440 Bool_t ocdb = (runNumber>=0);
442 if ( stype == "CAPACITANCES" )
446 store = AliMUONCalibrationData::CreateCapacitances(runNumber,&startOfValidity);
450 store = new AliMUON2DMap(20000);
451 AliMUONTrackerIO::DecodeCapacitances(source,*store);
454 else if ( stype == "CONFIG" )
456 AliMUONVStore* tmp(0x0);
459 tmp = AliMUONCalibrationData::CreateConfig(runNumber,&startOfValidity);
463 tmp = new AliMUON2DMap(kTRUE);
464 AliMUONTrackerIO::DecodeConfig(source,*tmp);
468 store = ExpandConfig(*tmp);
472 else if ( stype == "GAINS" )
474 AliMUONVStore* gains(0x0);
477 gains = AliMUONCalibrationData::CreateGains(runNumber,&startOfValidity);
481 gains = new AliMUON2DMap(kTRUE);
483 AliMUONTrackerIO::DecodeGains(source,*gains,comment);
485 store = PatchGainStore(*gains);
488 else if ( stype == "OCCUPANCY" )
492 store = AliMUONCalibrationData::CreateOccupancyMap(runNumber,&startOfValidity);
493 if (store) store = static_cast<AliMUONVStore*>(store->Clone());
497 store = new AliMUON2DMap(kTRUE);
498 AliMUONTrackerIO::DecodeOccupancy(source,*store);
501 else if ( stype == "PEDESTALS" )
505 store = AliMUONCalibrationData::CreatePedestals(runNumber,&startOfValidity);
509 store = new AliMUON2DMap(kTRUE);
510 AliMUONTrackerIO::DecodePedestals(source,*store);
514 /// Below are source that can only be accessed from OCDB
522 TMap* m = AliMUONCalibrationData::CreateHV(runNumber,&startOfValidity);
523 store = CreateHVStore(*m);
526 else if ( stype == "STATUS" )
528 store = CreateStatusStore(runNumber);
530 else if ( stype == "STATUSMAP" )
532 store = CreateStatusMapStore(runNumber);
538 //_____________________________________________________________________________
540 AliMUONTrackerConditionDataMaker::ExpandConfig(const AliMUONVStore& manuConfig)
542 /// Convert the config from manu level to channel level (just to
543 /// be able to add it correctly to the trackerdata...)
545 AliMUONVStore* store = manuConfig.Create();
547 TIter next(manuConfig.CreateIterator());
548 AliMUONVCalibParam* p;
550 while ( ( p = static_cast<AliMUONVCalibParam*>(next()) ) )
552 AliMUONVCalibParam* c = new AliMUONCalibParamNF(1,AliMpConstants::ManuNofChannels(),p->ID0(),p->ID1(),0.0);
554 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(p->ID0());
556 for ( Int_t i = 0; i < c->Size(); ++i )
558 if ( de->IsExistingChannel(p->ID1(),i) )
560 c->SetValueAsFloat(i,0,1.0);
569 //_____________________________________________________________________________
571 AliMUONTrackerConditionDataMaker::Merge(TCollection*)
574 AliError("Not implemented. Does it have sense ?");
578 //_____________________________________________________________________________
580 AliMUONTrackerConditionDataMaker::PatchGainStore(const AliMUONVStore& gains)
582 /// Polish the gain store :
583 /// a) adding a dimension, computed from a1, and called gain = 1/a1/0.2
584 /// where 0.2 is internal capa in pF, and gain is then in mV/fC
585 /// b) splitting the quality in two
587 AliMUONVStore* store = gains.Create();
589 TIter next(gains.CreateIterator());
590 AliMUONVCalibParam* param;
592 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
594 AliMUONVCalibParam* nd = new AliMUONCalibParamND(param->Dimension()+2,
598 for ( Int_t i = 0; i < param->Size(); ++i )
601 Int_t qual = param->ValueAsInt(i,3);
602 Int_t q1 = (qual & 0xF0) >> 4; // linear fit quality
603 Int_t q2 = qual & 0xF; // parabolic fit quality
606 if ( param->ValueAsFloat(i,0) > 1E-9 ) gain = 1.0/param->ValueAsFloat(i,0)/0.2;
608 nd->SetValueAsDouble(i,0,gain); // gain
609 nd->SetValueAsDouble(i,1,param->ValueAsFloat(i,0)); // a1
610 nd->SetValueAsDouble(i,2,param->ValueAsFloat(i,1)); // a2
611 nd->SetValueAsInt(i,3,param->ValueAsInt(i,2)); // thres
612 nd->SetValueAsInt(i,4,q1); // qual1
613 nd->SetValueAsInt(i,5,q2); // qual2
614 nd->SetValueAsInt(i,6,param->ValueAsInt(i,4)); // sat