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