fEcore2ESD initialization is added to constructors
[u/mrichter/AliRoot.git] / MUON / AliMUONCDB.cxx
CommitLineData
de01cdf0 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
3d1463c8 18//-----------------------------------------------------------------------------
de01cdf0 19/// \class AliMUONCDB
20///
21/// Helper class to experience the OCDB
22/// It allows to generate dummy (but complete) containers for all the
23/// calibration data types we have for tracker and trigger, and to write
24/// them into OCDB.
25///
26/// For more information, please see READMECDB
27///
28// \author Laurent Aphecetche
3d1463c8 29//-----------------------------------------------------------------------------
de01cdf0 30
31#include "AliMUONCDB.h"
32
de01cdf0 33#include "AliMUON1DArray.h"
34#include "AliMUON1DMap.h"
35#include "AliMUON2DMap.h"
36#include "AliMUON2DStoreValidator.h"
37#include "AliMUONCalibParamNF.h"
38#include "AliMUONCalibParamNI.h"
39#include "AliMUONConstants.h"
49419555 40#include "AliMUONTrackerIO.h"
de01cdf0 41#include "AliMUONTriggerEfficiencyCells.h"
42#include "AliMUONTriggerLut.h"
a0eca509 43#include "AliMUONVStore.h"
de01cdf0 44#include "AliMUONVCalibParam.h"
45#include "AliMUONVCalibParam.h"
92c23b09 46#include "AliMUONGlobalCrateConfig.h"
47#include "AliMUONRegionalTriggerConfig.h"
92e36663 48
25e1df3e 49#include "AliMpCDB.h"
a0eca509 50#include "AliMpConstants.h"
de01cdf0 51#include "AliMpDDLStore.h"
52#include "AliMpDEIterator.h"
53#include "AliMpDEManager.h"
54#include "AliMpDetElement.h"
92c23b09 55#include "AliMpFiles.h"
409de10f 56#include "AliMpHVNamer.h"
57#include "AliMpManuIterator.h"
de01cdf0 58#include "AliMpSegmentation.h"
59#include "AliMpStationType.h"
60#include "AliMpVSegmentation.h"
92e36663 61
62#include "AliCodeTimer.h"
63#include "AliCDBEntry.h"
64#include "AliCDBManager.h"
65#include "AliDCSValue.h"
66#include "AliLog.h"
67
de01cdf0 68#include <Riostream.h>
69#include <TArrayI.h>
70#include <TClass.h>
71#include <TH1F.h>
72#include <TList.h>
73#include <TMap.h>
74#include <TObjString.h>
75#include <TROOT.h>
76#include <TRandom.h>
77#include <TStopwatch.h>
78#include <TSystem.h>
cf27231a 79#include <TMath.h>
de01cdf0 80
c05673c9 81
de01cdf0 82/// \cond CLASSIMP
83ClassImp(AliMUONCDB)
84/// \endcond
85
de01cdf0 86namespace
87{
409de10f 88 //_____________________________________________________________________________
89AliMUONVStore* Create2DMap()
90{
91 return new AliMUON2DMap(true);
92}
93
94 //_____________________________________________________________________________
046e5fd4 95void getBoundaries(const AliMUONVStore& store, Int_t dim,
96 Float_t* xmin, Float_t* xmax)
de01cdf0 97{
046e5fd4 98 /// Assuming the store contains AliMUONVCalibParam objects, compute the
99 /// limits of the value contained in the VCalibParam, for each of its dimensions
100 /// xmin and xmax must be of dimension dim
101
102 for ( Int_t i = 0; i < dim; ++i )
103 {
104 xmin[i]=1E30;
105 xmax[i]=-1E30;
106 }
de01cdf0 107
a0eca509 108 TIter next(store.CreateIterator());
109 AliMUONVCalibParam* value;
de01cdf0 110
a0eca509 111 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 112 {
a0eca509 113 Int_t detElemId = value->ID0();
114 Int_t manuId = value->ID1();
de01cdf0 115
116 const AliMpVSegmentation* seg =
117 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
118
119 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
120 {
121 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
122 if (!pad.IsValid()) continue;
123
046e5fd4 124 for ( Int_t i = 0; i < dim; ++i )
de01cdf0 125 {
046e5fd4 126 Float_t x0 = value->ValueAsFloat(manuChannel,i);
127
128 xmin[i] = TMath::Min(xmin[i],x0);
129 xmax[i] = TMath::Max(xmax[i],x0);
de01cdf0 130 }
131 }
046e5fd4 132 }
133
134 for ( Int_t i = 0; i < dim; ++i )
135 {
136 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
137 {
138 xmin[i] -= 1;
139 xmax[i] += 1;
140 }
141 }
de01cdf0 142}
143
cf27231a 144//_____________________________________________________________________________
145Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
146{
147 Double_t x(-1);
148 if ( mustBePositive )
149 {
150 while ( x < 0 )
151 {
152 x = gRandom->Gaus(mean,sigma);
153 }
154 }
155 else
156 {
157 x = gRandom->Gaus(mean,sigma);
158 }
159 return x;
160}
161
de01cdf0 162}
163
164//_____________________________________________________________________________
165AliMUONCDB::AliMUONCDB(const char* cdbpath)
166: TObject(),
167 fCDBPath(cdbpath),
046e5fd4 168 fMaxNofChannelsToGenerate(-1)
de01cdf0 169{
409de10f 170 /// ctor
92e36663 171 // Load mapping
0145e89a 172 if ( ! AliMpCDB::LoadDDLStore() ) {
92e36663 173 AliFatal("Could not access mapping from OCDB !");
174 }
de01cdf0 175}
176
177//_____________________________________________________________________________
178AliMUONCDB::~AliMUONCDB()
179{
180 /// dtor
a0eca509 181}
182
183//_____________________________________________________________________________
184AliMUONVStore*
185AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
de01cdf0 186 const char* opt)
187{
188 /// creates a store which contains store1-store2
189 /// if opt="abs" the difference is absolute one,
190 /// if opt="rel" then what is stored is (store1-store2)/store1
046e5fd4 191 /// if opt="percent" then what is stored is rel*100
192 ///
de01cdf0 193 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
194
195 TString sopt(opt);
196 sopt.ToUpper();
197
046e5fd4 198 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
de01cdf0 199 {
046e5fd4 200 AliErrorClass(Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
de01cdf0 201 return 0x0;
202 }
203
a0eca509 204 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
de01cdf0 205
a0eca509 206 TIter next(d->CreateIterator());
de01cdf0 207
a0eca509 208 AliMUONVCalibParam* param;
de01cdf0 209
a0eca509 210 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 211 {
a0eca509 212 Int_t detElemId = param->ID0();
213 Int_t manuId = param->ID1();
de01cdf0 214
a0eca509 215 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
de01cdf0 216 //FIXME: this might happen. Handle it.
217 if (!param2)
218 {
219 cerr << "param2 is null : FIXME : this might happen !" << endl;
220 delete d;
221 return 0;
222 }
223
224 for ( Int_t i = 0; i < param->Size(); ++i )
225 {
226 for ( Int_t j = 0; j < param->Dimension(); ++j )
227 {
228 Float_t value(0);
229 if ( sopt.Contains("ABS") )
230 {
231 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
232 }
046e5fd4 233 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
de01cdf0 234 {
235 if ( param->ValueAsFloat(i,j) )
236 {
237 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
238 }
239 else
240 {
241 continue;
242 }
046e5fd4 243 if ( sopt.Contains("PERCENT") ) value *= 100.0;
de01cdf0 244 }
245 param->SetValueAsFloat(i,j,value);
246 }
247 }
de01cdf0 248 }
249 return d;
250}
251
252//_____________________________________________________________________________
253void
a0eca509 254AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
de01cdf0 255{
046e5fd4 256 /// Make histograms of each dimension of the AliMUONVCalibParam
de01cdf0 257 /// contained inside store.
258 /// It produces histograms named name_0, name_1, etc...
259
046e5fd4 260 TIter next(store.CreateIterator());
261 AliMUONVCalibParam* param;
de01cdf0 262 Int_t n(0);
046e5fd4 263 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
264 Int_t* nPerStation = new Int_t[kNStations];
265 TH1** h(0x0);
de01cdf0 266
046e5fd4 267 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
de01cdf0 268
046e5fd4 269 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
de01cdf0 270 {
046e5fd4 271 if (!h)
272 {
273 Int_t dim = param->Dimension();
274 h = new TH1*[dim];
275 Float_t* xmin = new Float_t[dim];
276 Float_t* xmax = new Float_t[dim];
277 getBoundaries(store,dim,xmin,xmax);
278
279 for ( Int_t i = 0; i < dim; ++i )
280 {
281 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
282 nbins,xmin[i],xmax[i]);
283 AliInfo(Form("Created histogram %s",h[i]->GetName()));
284 }
285 }
286
287 Int_t detElemId = param->ID0();
288 Int_t manuId = param->ID1();
289 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
de01cdf0 290
291 const AliMpVSegmentation* seg =
292 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
293
046e5fd4 294 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
de01cdf0 295 {
046e5fd4 296 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
297 if (!pad.IsValid()) continue;
de01cdf0 298
046e5fd4 299 ++n;
300 ++nPerStation[station];
301
302 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
303 {
304 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
de01cdf0 305 }
306 }
046e5fd4 307 }
de01cdf0 308
046e5fd4 309 for ( Int_t i = 0; i < kNStations; ++i )
de01cdf0 310 {
311 AliInfo(Form("Station %d %d ",(i+1),nPerStation[i]));
312 }
046e5fd4 313
314 AliInfo(Form("Number of channels = %d",n));
315
316 delete[] nPerStation;
de01cdf0 317}
318
319//_____________________________________________________________________________
320Int_t
321AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
322{
323 /// Create a HV store
324
409de10f 325 AliMpHVNamer hvNamer;
de01cdf0 326
327 TObjArray* aliases = hvNamer.GenerateAliases();
328
329 Int_t nSwitch(0);
330 Int_t nChannels(0);
331
332 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
333 {
334 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
335 TString& aliasName = alias->String();
336 if ( aliasName.Contains("sw") )
337 {
338 // HV Switch (St345 only)
339 TObjArray* valueSet = new TObjArray;
340 valueSet->SetOwner(kTRUE);
341
342 Bool_t value = kTRUE;
343
344 if (!defaultValues)
345 {
a0eca509 346 Float_t r = gRandom->Uniform();
de01cdf0 347 if ( r < 0.007 ) value = kFALSE;
348 }
349
350 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
351 {
352 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
353 valueSet->Add(dcsValue);
354 }
355 aliasMap.Add(new TObjString(*alias),valueSet);
356 ++nSwitch;
357 }
358 else
359 {
360 TObjArray* valueSet = new TObjArray;
361 valueSet->SetOwner(kTRUE);
362 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
363 {
364 Float_t value = 1500;
cf27231a 365 if (!defaultValues) value = GetRandom(1750,62.5,true);
de01cdf0 366 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
367 valueSet->Add(dcsValue);
368 }
369 aliasMap.Add(new TObjString(*alias),valueSet);
370 ++nChannels;
371 }
372 }
373
374 delete aliases;
375
376 AliInfo(Form("%d HV channels and %d switches",nChannels,nSwitch));
377
378 return nChannels+nSwitch;
379}
380
381//_____________________________________________________________________________
382Int_t
a0eca509 383AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
de01cdf0 384{
385 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
386 /// otherwise mean and sigma are from a gaussian (with parameters
387 /// defined below by the kPedestal* constants)
409de10f 388
389 AliCodeTimerAuto("");
de01cdf0 390
391 Int_t nchannels(0);
392 Int_t nmanus(0);
393
a0eca509 394 const Int_t kChannels(AliMpConstants::ManuNofChannels());
de01cdf0 395 const Float_t kPedestalMeanMean(200);
396 const Float_t kPedestalMeanSigma(10);
397 const Float_t kPedestalSigmaMean(1.0);
398 const Float_t kPedestalSigmaSigma(0.2);
409de10f 399
400 Int_t detElemId;
401 Int_t manuId;
402
403 AliMpManuIterator it;
de01cdf0 404
409de10f 405 while ( it.Next(detElemId,manuId) )
de01cdf0 406 {
407 ++nmanus;
a0eca509 408
046e5fd4 409 AliMUONVCalibParam* ped =
410 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
409de10f 411
412 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 413
414 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
415 {
409de10f 416 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 417
418 ++nchannels;
419
420 Float_t meanPedestal;
421 Float_t sigmaPedestal;
422
423 if ( defaultValues )
424 {
425 meanPedestal = 0.0;
426 sigmaPedestal = 1.0;
427 }
428 else
429 {
cf27231a 430 Bool_t positive(kTRUE);
046e5fd4 431 meanPedestal = 0.0;
432 while ( meanPedestal == 0.0 ) // avoid strict zero
433 {
434 meanPedestal = GetRandom(kPedestalMeanMean,kPedestalMeanSigma,positive);
435 }
cf27231a 436 sigmaPedestal = GetRandom(kPedestalSigmaMean,kPedestalSigmaSigma,positive);
de01cdf0 437 }
438 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
439 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
440
441 }
a0eca509 442 Bool_t ok = pedestalStore.Add(ped);
de01cdf0 443 if (!ok)
444 {
445 AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
446 }
046e5fd4 447 if ( fMaxNofChannelsToGenerate > 0 && nchannels >= fMaxNofChannelsToGenerate ) break;
de01cdf0 448 }
449
450 AliInfo(Form("%d Manus and %d channels.",nmanus,nchannels));
451 return nchannels;
de01cdf0 452}
453
454//_____________________________________________________________________________
25e1df3e 455Int_t
456AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
457{
6687de6d 458 /// Read the capacitance values from file and append them to the capaStore
459
49419555 460 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
25e1df3e 461}
462
463//_____________________________________________________________________________
de01cdf0 464Int_t
a0eca509 465AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
de01cdf0 466{
467 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
468 /// otherwise they are from a gaussian with parameters defined in the
469 /// kCapa* constants below.
409de10f 470
471 AliCodeTimerAuto("");
de01cdf0 472
473 Int_t nchannels(0);
474 Int_t nmanus(0);
475 Int_t nmanusOK(0); // manus for which we got the serial number
a0eca509 476
25e1df3e 477 const Float_t kCapaMean(0.3);
478 const Float_t kCapaSigma(0.1);
479 const Float_t kInjectionGainMean(3);
480 const Float_t kInjectionGainSigma(1);
409de10f 481
482 Int_t detElemId;
483 Int_t manuId;
484
485 AliMpManuIterator it;
de01cdf0 486
409de10f 487 while ( it.Next(detElemId,manuId) )
de01cdf0 488 {
489 ++nmanus;
490
de01cdf0 491 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
492 Int_t serialNumber = de->GetManuSerialFromId(manuId);
493
a0eca509 494 if ( serialNumber <= 0 ) continue;
495
496 ++nmanusOK;
de01cdf0 497
a0eca509 498 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
de01cdf0 499
500 if (!capa)
501 {
25e1df3e 502 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
a0eca509 503 Bool_t ok = capaStore.Add(capa);
de01cdf0 504 if (!ok)
505 {
506 AliError(Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
507 }
508 }
509
510 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
511 {
409de10f 512 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 513
514 ++nchannels;
515
516 Float_t capaValue;
25e1df3e 517 Float_t injectionGain;
de01cdf0 518
519 if ( defaultValues )
520 {
521 capaValue = 1.0;
25e1df3e 522 injectionGain = 1.0;
de01cdf0 523 }
524 else
525 {
cf27231a 526 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
25e1df3e 527 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
de01cdf0 528 }
529 capa->SetValueAsFloat(manuChannel,0,capaValue);
25e1df3e 530 capa->SetValueAsFloat(manuChannel,1,injectionGain);
de01cdf0 531 }
532 }
533
534 Float_t percent = 0;
535 if ( nmanus ) percent = 100*nmanusOK/nmanus;
536 AliInfo(Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
537 nmanusOK,nmanus,percent));
538 AliInfo(Form("%5d channels",nchannels));
539 if ( percent < 100 )
540 {
541 AliWarning("Did not get all serial numbers. capaStore is incomplete !!!!");
542 }
543 return nchannels;
544
545}
546
547//_____________________________________________________________________________
548Int_t
a0eca509 549AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
de01cdf0 550{
cf27231a 551 /// Create a gain store. if defaultValues=true, all gains set so that
552 /// charge = (adc-ped)
553 ///
554 /// otherwise parameters are taken from gaussians with parameters
555 /// defined in the k* constants below.
de01cdf0 556
409de10f 557 AliCodeTimerAuto("");
de01cdf0 558
559 Int_t nchannels(0);
560 Int_t nmanus(0);
a0eca509 561
cf27231a 562 const Int_t kSaturation(3000);
563 const Double_t kA0Mean(1.2);
409de10f 564 const Double_t kA0Sigma(0.1);
565 const Double_t kA1Mean(1E-5);
566 const Double_t kA1Sigma(1E-6);
cf27231a 567 const Double_t kQualMean(0xFF);
568 const Double_t kQualSigma(0x10);
569 const Int_t kThresMean(1600);
409de10f 570 const Int_t kThresSigma(100);
571
572 Int_t detElemId;
573 Int_t manuId;
de01cdf0 574
409de10f 575 AliMpManuIterator it;
576
577 while ( it.Next(detElemId,manuId) )
de01cdf0 578 {
579 ++nmanus;
de01cdf0 580
a0eca509 581 AliMUONVCalibParam* gain =
cf27231a 582 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
a0eca509 583 detElemId,
584 manuId,
585 AliMUONVCalibParam::InvalidFloatValue());
586
409de10f 587 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 588
589 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
590 {
409de10f 591 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 592
593 ++nchannels;
594
de01cdf0 595 if ( defaultValues )
596 {
cf27231a 597 gain->SetValueAsFloat(manuChannel,0,1.0);
598 gain->SetValueAsFloat(manuChannel,1,0.0);
599 gain->SetValueAsInt(manuChannel,2,4095);
600 gain->SetValueAsInt(manuChannel,3,1);
601 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 602 }
603 else
604 {
cf27231a 605 Bool_t positive(kTRUE);
606 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
607 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
608 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
609 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
610 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 611 }
de01cdf0 612
613 }
a0eca509 614 Bool_t ok = gainStore.Add(gain);
de01cdf0 615 if (!ok)
616 {
617 AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
618 }
046e5fd4 619 if ( fMaxNofChannelsToGenerate > 0 && nchannels >= fMaxNofChannelsToGenerate ) break;
de01cdf0 620 }
621
622 AliInfo(Form("%d Manus and %d channels.",nmanus,nchannels));
623 return nchannels;
624}
625
626//_____________________________________________________________________________
627Int_t
a0eca509 628AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
de01cdf0 629{
630 /// Generate local trigger masks store. All masks are set to FFFF
631
409de10f 632 AliCodeTimerAuto("");
633
de01cdf0 634 Int_t ngenerated(0);
635 // Generate fake mask values for 234 localboards and put that into
636 // one single container (localBoardMasks)
0145e89a 637 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
de01cdf0 638 {
a0eca509 639 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
de01cdf0 640 for ( Int_t x = 0; x < 2; ++x )
641 {
642 for ( Int_t y = 0; y < 4; ++y )
643 {
644 Int_t index = x*4+y;
645 localBoard->SetValueAsInt(index,0,0xFFFF);
646 ++ngenerated;
647 }
648 }
a0eca509 649 localBoardMasks.Add(localBoard);
de01cdf0 650 }
651 return ngenerated;
652}
653
654//_____________________________________________________________________________
655Int_t
92c23b09 656AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm) const
de01cdf0 657{
92c23b09 658 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
de01cdf0 659
409de10f 660 AliCodeTimerAuto("");
661
92c23b09 662 return rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping());
c05673c9 663
de01cdf0 664}
665
92c23b09 666
de01cdf0 667//_____________________________________________________________________________
668Int_t
92c23b09 669AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm) const
de01cdf0 670{
92c23b09 671 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
de01cdf0 672
409de10f 673 AliCodeTimerAuto("");
92c23b09 674
675 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
de01cdf0 676}
677
92c23b09 678
de01cdf0 679//_____________________________________________________________________________
680AliMUONTriggerLut*
681AliMUONCDB::MakeTriggerLUT(const char* file) const
682{
683 /// Make a triggerlut object, from a file.
684
409de10f 685 AliCodeTimerAuto("");
686
de01cdf0 687 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
688 lut->ReadFromFile(file);
689 return lut;
690}
691
692//_____________________________________________________________________________
693AliMUONTriggerEfficiencyCells*
694AliMUONCDB::MakeTriggerEfficiency(const char* file) const
695{
696 /// Make a trigger efficiency object from a file.
697
409de10f 698 AliCodeTimerAuto("");
699
de01cdf0 700 return new AliMUONTriggerEfficiencyCells(file);
701}
702
703//_____________________________________________________________________________
704void
705AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
25e1df3e 706 Int_t startRun, Int_t endRun,
707 const char* filename)
708{
709 /// Write a given object to OCDB
710
711 AliCDBId id(calibpath,startRun,endRun);
712 AliCDBMetaData md;
713 md.SetAliRootVersion(gROOT->GetVersion());
714 md.SetComment(gSystem->ExpandPathName(filename));
715 md.SetResponsible("Uploaded using AliMUONCDB class");
716 AliCDBManager* man = AliCDBManager::Instance();
717 man->SetDefaultStorage(fCDBPath);
718 man->Put(object,id,&md);
719}
720
721//_____________________________________________________________________________
722void
723AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
de01cdf0 724 Int_t startRun, Int_t endRun, Bool_t defaultValues)
725{
726 /// Write a given object to OCDB
727
728 AliCDBId id(calibpath,startRun,endRun);
729 AliCDBMetaData md;
730 md.SetAliRootVersion(gROOT->GetVersion());
731 if ( defaultValues )
732 {
733 md.SetComment("Test with default values");
734 }
735 else
736 {
737 md.SetComment("Test with random values");
738 }
739 md.SetResponsible("AliMUONCDB tester class");
740
741 AliCDBManager* man = AliCDBManager::Instance();
742 man->SetDefaultStorage(fCDBPath);
743 man->Put(object,id,&md);
744}
745
746//_____________________________________________________________________________
747Int_t
a0eca509 748AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
de01cdf0 749{
750 /// Fill the neighbours store with, for each channel, a TObjArray of its
751 /// neighbouring pads (including itself)
752
409de10f 753 AliCodeTimerAuto("");
de01cdf0 754
409de10f 755 AliInfo("Generating NeighbourStore. This will take a while. Please be patient.");
de01cdf0 756
757 Int_t nchannels(0);
758
759 TObjArray tmp;
409de10f 760
761 Int_t detElemId;
762 Int_t manuId;
de01cdf0 763
409de10f 764 AliMpManuIterator it;
765
766 while ( it.Next(detElemId,manuId) )
de01cdf0 767 {
de01cdf0 768 const AliMpVSegmentation* seg =
769 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
770
a0eca509 771 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
de01cdf0 772 if (!calibParam)
773 {
774 Int_t dimension(11);
a0eca509 775 Int_t size(AliMpConstants::ManuNofChannels());
de01cdf0 776 Int_t defaultValue(-1);
a0eca509 777 Int_t packingFactor(size);
de01cdf0 778
a0eca509 779 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
780 Bool_t ok = neighbourStore.Add(calibParam);
de01cdf0 781 if (!ok)
782 {
783 AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
784 return -1;
785 }
786 }
787
a0eca509 788 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
de01cdf0 789 {
790 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
791
792 if (pad.IsValid())
793 {
794 ++nchannels;
795
796 seg->GetNeighbours(pad,tmp,true,true);
797 Int_t nofPadNeighbours = tmp.GetEntriesFast();
798
799 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
800 {
409de10f 801 AliMpPad* pad = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
de01cdf0 802 Int_t x;
409de10f 803// Bool_t ok =
804 calibParam->PackValues(pad->GetLocation().GetFirst(),pad->GetLocation().GetSecond(),x);
805// if (!ok)
806// {
807// AliError("Could not pack value. Something is seriously wrong. Please check");
808// StdoutToAliError(pad->Print(););
809// return -1;
810// }
de01cdf0 811 calibParam->SetValueAsInt(manuChannel,i,x);
812 }
813 }
814 }
815 }
816
de01cdf0 817 return nchannels;
818}
819
820//_____________________________________________________________________________
821void
046e5fd4 822AliMUONCDB::SetMaxNofChannelsToGenerate(Int_t n)
823{
824 /// Set the maximum number of channels to generate (used for testing only)
825 /// n < 0 means no limit
826 fMaxNofChannelsToGenerate = n;
827}
828
829//_____________________________________________________________________________
830void
de01cdf0 831AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
832{
833 /// Write local trigger masks to OCDB
834
a0eca509 835 AliMUONVStore* ltm = new AliMUON1DArray(235);
de01cdf0 836 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
837 AliInfo(Form("Ngenerated = %d",ngenerated));
838 if (ngenerated>0)
839 {
840 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
841 }
842 delete ltm;
843}
844
845//_____________________________________________________________________________
846void
92c23b09 847AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 848{
849 /// Write regional trigger masks to OCDB
850
92c23b09 851 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
852 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
de01cdf0 853 AliInfo(Form("Ngenerated = %d",ngenerated));
854 if (ngenerated>0)
855 {
92c23b09 856 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
de01cdf0 857 }
858 delete rtm;
859}
860
92c23b09 861
de01cdf0 862//_____________________________________________________________________________
863void
92c23b09 864AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 865{
866 /// Write global trigger masks to OCDB
867
92c23b09 868 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
de01cdf0 869
92c23b09 870 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
de01cdf0 871 AliInfo(Form("Ngenerated = %d",ngenerated));
872 if (ngenerated>0)
873 {
92c23b09 874 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
de01cdf0 875 }
876 delete gtm;
877}
878
92c23b09 879
de01cdf0 880//_____________________________________________________________________________
881void
882AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
883{
884 /// Write trigger LUT to OCDB
885
886 AliMUONTriggerLut* lut = MakeTriggerLUT();
887 if (lut)
888 {
889 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
890 }
891 delete lut;
892}
893
894//_____________________________________________________________________________
895void
896AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
897{
898 /// Write trigger efficiency to OCDB
899
900 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
901 if (eff)
902 {
903 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
904 }
905 delete eff;
906}
907
908//_____________________________________________________________________________
909void
910AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
911{
912 /// Write neighbours to OCDB
913
409de10f 914 AliMUONVStore* neighbours = Create2DMap();
de01cdf0 915 Int_t ngenerated = MakeNeighbourStore(*neighbours);
916 AliInfo(Form("Ngenerated = %d",ngenerated));
917 if (ngenerated>0)
918 {
919 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
920 }
921 delete neighbours;
922}
923
924//_____________________________________________________________________________
925void
926AliMUONCDB::WriteHV(Bool_t defaultValues,
927 Int_t startRun, Int_t endRun)
928{
929 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
930 /// if defaultValues=false, see makeHVStore) and
931 /// store them into CDB located at cdbpath, with a validity period
932 /// ranging from startRun to endRun
933
934 TMap* hvStore = new TMap;
935 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
936 AliInfo(Form("Ngenerated = %d",ngenerated));
937 if (ngenerated>0)
938 {
939 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
940 }
941 delete hvStore;
942}
943
944//_____________________________________________________________________________
945void
946AliMUONCDB::WritePedestals(Bool_t defaultValues,
947 Int_t startRun, Int_t endRun)
948{
949 /// generate pedestal values (either 0 if defaultValues=true or random
950 /// if defaultValues=false, see makePedestalStore) and
951 /// store them into CDB located at cdbpath, with a validity period
952 /// ranging from startRun to endRun
953
409de10f 954 AliMUONVStore* pedestalStore = Create2DMap();
de01cdf0 955 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
956 AliInfo(Form("Ngenerated = %d",ngenerated));
957 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
958 delete pedestalStore;
959}
960
961
962//_____________________________________________________________________________
963void
964AliMUONCDB::WriteGains(Bool_t defaultValues,
965 Int_t startRun, Int_t endRun)
966{
967 /// generate gain values (either 1 if defaultValues=true or random
968 /// if defaultValues=false, see makeGainStore) and
969 /// store them into CDB located at cdbpath, with a validity period
970 /// ranging from startRun to endRun
971
409de10f 972 AliMUONVStore* gainStore = Create2DMap();
de01cdf0 973 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
974 AliInfo(Form("Ngenerated = %d",ngenerated));
975 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
976 delete gainStore;
977}
978
979//_____________________________________________________________________________
980void
25e1df3e 981AliMUONCDB::WriteCapacitances(const char* filename,
982 Int_t startRun, Int_t endRun)
983{
984 /// read manu capacitance and injection gain values from file
985 /// and store them into CDB located at cdbpath, with a validity period
986 /// ranging from startRun to endRun
987
988 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
989 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
990 AliInfo(Form("Ngenerated = %d",ngenerated));
991 if ( ngenerated > 0 )
992 {
993 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
994 }
995 delete capaStore;
996}
997
998//_____________________________________________________________________________
999void
de01cdf0 1000AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1001 Int_t startRun, Int_t endRun)
1002{
1003 /// generate manu capacitance values (either 1 if defaultValues=true or random
1004 /// if defaultValues=false, see makeCapacitanceStore) and
1005 /// store them into CDB located at cdbpath, with a validity period
1006 /// ranging from startRun to endRun
1007
a0eca509 1008 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
de01cdf0 1009 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1010 AliInfo(Form("Ngenerated = %d",ngenerated));
1011 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1012 delete capaStore;
1013}
1014
1015//_____________________________________________________________________________
1016void
1017AliMUONCDB::WriteTrigger(Int_t startRun, Int_t endRun)
1018{
1019 /// Writes all Trigger related calibration to CDB
1020 WriteLocalTriggerMasks(startRun,endRun);
92c23b09 1021 WriteRegionalTriggerConfig(startRun,endRun);
1022 WriteGlobalTriggerConfig(startRun,endRun);
de01cdf0 1023 WriteTriggerLut(startRun,endRun);
1024 WriteTriggerEfficiency(startRun,endRun);
1025}
1026
1027//_____________________________________________________________________________
1028void
1029AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1030{
1031 /// Writes all Tracker related calibration to CDB
1032 WriteHV(defaultValues,startRun,endRun);
1033 WritePedestals(defaultValues,startRun,endRun);
1034 WriteGains(defaultValues,startRun,endRun);
1035 WriteCapacitances(defaultValues,startRun,endRun);
1036 WriteNeighbours(startRun,endRun);
1037}