]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCDB.cxx
Coverity fix
[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//-----------------------------------------------------------------------------
a99c3449 19/// \namespace AliMUONCDB
de01cdf0 20///
a99c3449 21/// Helper functions to experience the OCDB
22///
23/// They allow to read magnetic field, mapping and recoParam from OCDB
24///
25/// And also to generate dummy (but complete) containers for all the
de01cdf0 26/// calibration data types we have for tracker and trigger, and to write
27/// them into OCDB.
28///
a99c3449 29/// For more information, please see READMEcalib
de01cdf0 30///
baf1a7a0 31/// \author Laurent Aphecetche
3d1463c8 32//-----------------------------------------------------------------------------
de01cdf0 33
34#include "AliMUONCDB.h"
35
de01cdf0 36#include "AliMUON1DArray.h"
37#include "AliMUON1DMap.h"
38#include "AliMUON2DMap.h"
39#include "AliMUON2DStoreValidator.h"
7eafe398 40#include "AliMUONCalibParamND.h"
de01cdf0 41#include "AliMUONCalibParamNF.h"
42#include "AliMUONCalibParamNI.h"
207947f7 43#include "AliMUONCalibrationData.h"
de01cdf0 44#include "AliMUONConstants.h"
207947f7 45#include "AliMUONGlobalCrateConfig.h"
46#include "AliMUONPadStatusMaker.h"
47#include "AliMUONPadStatusMapMaker.h"
48#include "AliMUONRecoParam.h"
49#include "AliMUONRegionalTriggerConfig.h"
0045b488 50#include "AliMUONRejectList.h"
49419555 51#include "AliMUONTrackerIO.h"
de01cdf0 52#include "AliMUONTriggerEfficiencyCells.h"
53#include "AliMUONTriggerLut.h"
de01cdf0 54#include "AliMUONVCalibParam.h"
55#include "AliMUONVCalibParam.h"
207947f7 56#include "AliMUONVStore.h"
57
92e36663 58
25e1df3e 59#include "AliMpCDB.h"
a0eca509 60#include "AliMpConstants.h"
a99c3449 61#include "AliMpDEStore.h"
de01cdf0 62#include "AliMpDDLStore.h"
ab167304 63#include "AliMpManuStore.h"
de01cdf0 64#include "AliMpDEManager.h"
65#include "AliMpDetElement.h"
92c23b09 66#include "AliMpFiles.h"
49e110ec 67#include "AliMpDCSNamer.h"
409de10f 68#include "AliMpManuIterator.h"
de01cdf0 69#include "AliMpSegmentation.h"
70#include "AliMpStationType.h"
71#include "AliMpVSegmentation.h"
92e36663 72
73#include "AliCodeTimer.h"
74#include "AliCDBEntry.h"
75#include "AliCDBManager.h"
a99c3449 76#include "AliGRPManager.h"
92e36663 77#include "AliDCSValue.h"
78#include "AliLog.h"
a31df857 79#include "AliMpBusPatch.h"
92e36663 80
de01cdf0 81#include <Riostream.h>
82#include <TArrayI.h>
83#include <TClass.h>
84#include <TH1F.h>
85#include <TList.h>
86#include <TMap.h>
87#include <TObjString.h>
88#include <TROOT.h>
89#include <TRandom.h>
90#include <TStopwatch.h>
91#include <TSystem.h>
cf27231a 92#include <TMath.h>
a99c3449 93#include <TGeoGlobalMagField.h>
73d3aca5 94#include <TClonesArray.h>
a31df857 95#include <sstream>
c05673c9 96
de01cdf0 97namespace
98{
409de10f 99 //_____________________________________________________________________________
100AliMUONVStore* Create2DMap()
101{
102 return new AliMUON2DMap(true);
103}
104
105 //_____________________________________________________________________________
046e5fd4 106void getBoundaries(const AliMUONVStore& store, Int_t dim,
107 Float_t* xmin, Float_t* xmax)
de01cdf0 108{
046e5fd4 109 /// Assuming the store contains AliMUONVCalibParam objects, compute the
110 /// limits of the value contained in the VCalibParam, for each of its dimensions
111 /// xmin and xmax must be of dimension dim
112
113 for ( Int_t i = 0; i < dim; ++i )
114 {
115 xmin[i]=1E30;
116 xmax[i]=-1E30;
117 }
de01cdf0 118
a0eca509 119 TIter next(store.CreateIterator());
120 AliMUONVCalibParam* value;
de01cdf0 121
a0eca509 122 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 123 {
a0eca509 124 Int_t detElemId = value->ID0();
125 Int_t manuId = value->ID1();
de01cdf0 126
127 const AliMpVSegmentation* seg =
128 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
129
130 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
131 {
168e9c4d 132 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
de01cdf0 133 if (!pad.IsValid()) continue;
134
046e5fd4 135 for ( Int_t i = 0; i < dim; ++i )
de01cdf0 136 {
046e5fd4 137 Float_t x0 = value->ValueAsFloat(manuChannel,i);
138
139 xmin[i] = TMath::Min(xmin[i],x0);
140 xmax[i] = TMath::Max(xmax[i],x0);
de01cdf0 141 }
142 }
046e5fd4 143 }
144
145 for ( Int_t i = 0; i < dim; ++i )
146 {
147 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
148 {
149 xmin[i] -= 1;
150 xmax[i] += 1;
151 }
152 }
de01cdf0 153}
154
cf27231a 155//_____________________________________________________________________________
156Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
157{
158 Double_t x(-1);
159 if ( mustBePositive )
160 {
161 while ( x < 0 )
162 {
163 x = gRandom->Gaus(mean,sigma);
164 }
165 }
166 else
167 {
168 x = gRandom->Gaus(mean,sigma);
169 }
170 return x;
171}
172
de01cdf0 173}
174
175//_____________________________________________________________________________
a99c3449 176Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
de01cdf0 177{
a99c3449 178 /// Check that OCDB path and run number are properly set
179
180 AliCDBManager* man = AliCDBManager::Instance();
181
182 // first OCDB path
183 if (!man->IsDefaultStorageSet()) {
184 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
185 return kFALSE;
186 }
187
188 // then run number if required
189 if (pathOnly) return kTRUE;
190 if (man->GetRun() < 0) {
191 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
192 return kFALSE;
193 }
194
195 return kTRUE;
196
197}
198
199//_____________________________________________________________________________
200Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
201{
202 /// Check that the mapping has been loaded
203
204 // first the segmentation
205 if (!AliMpSegmentation::Instance(false)) {
206 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
207 return kFALSE;
208 }
209
210 // then the others if required
211 if (segmentationOnly) return kTRUE;
212 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
213 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
214 return kFALSE;
215 }
216
217 return kTRUE;
218
219}
220
221//_____________________________________________________________________________
222Bool_t AliMUONCDB::LoadField()
223{
224 /// Load magnetic field (existing field will be deleted).
225 /// OCDB path and run number are supposed to be set.
226
227 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
228
229 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
230
231 AliGRPManager grpMan;
232
233 // make sure the old field is deleted even if it is locked
234 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
235
236 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
237 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
238 return kFALSE;
239 }
240
241 return kTRUE;
242
243}
ab167304 244
a99c3449 245//_____________________________________________________________________________
246Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
247{
248 /// Load mapping (existing mapping will be unloaded).
249 /// OCDB path and run number are supposed to be set.
250
251 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
252
253 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
254
255 // in case it has already been set
256 AliMpCDB::UnloadAll();
257
258 if (segmentationOnly) {
259
260 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
261 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
262 return kFALSE;
263 }
264
265 } else {
266
267 if (!AliMpCDB::LoadAll(kTRUE)) {
268 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
269 return kFALSE;
ab167304 270 }
a99c3449 271
272 }
273
274 return kTRUE;
275
de01cdf0 276}
277
278//_____________________________________________________________________________
a99c3449 279AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
de01cdf0 280{
a99c3449 281 /// Load and return reconstruction parameters.
282 /// OCDB path is supposed to be set.
283
284 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
285
286 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
287
288 AliMUONRecoParam* recoParam = 0x0;
289 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
290
291 if(entry) {
292
293 // load recoParam according OCDB content (single or array)
294 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
295
296 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
297
298 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
299 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
300 if (recoParam->IsDefault()) break;
301 recoParam = 0x0;
302 }
303
304 }
305
306 }
307
308 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
309
310 return recoParam;
311
a0eca509 312}
313
314//_____________________________________________________________________________
73d3aca5 315TClonesArray* AliMUONCDB::LoadAlignmentData()
316{
317 /// Load and return the array of alignment objects.
318
319 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
320
321 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
322
323 TClonesArray* alignmentArray = 0x0;
324 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
325
326 if (entry) {
327 // load alignement array
328 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
329 }
330
331 if (!alignmentArray) {
332 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
333 }
334
335 return alignmentArray;
336}
337
338//_____________________________________________________________________________
a0eca509 339AliMUONVStore*
340AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
de01cdf0 341 const char* opt)
342{
343 /// creates a store which contains store1-store2
344 /// if opt="abs" the difference is absolute one,
345 /// if opt="rel" then what is stored is (store1-store2)/store1
046e5fd4 346 /// if opt="percent" then what is stored is rel*100
347 ///
de01cdf0 348 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
349
350 TString sopt(opt);
351 sopt.ToUpper();
352
046e5fd4 353 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
de01cdf0 354 {
a99c3449 355 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
de01cdf0 356 return 0x0;
357 }
358
a0eca509 359 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
de01cdf0 360
a0eca509 361 TIter next(d->CreateIterator());
de01cdf0 362
a0eca509 363 AliMUONVCalibParam* param;
de01cdf0 364
a0eca509 365 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 366 {
a0eca509 367 Int_t detElemId = param->ID0();
368 Int_t manuId = param->ID1();
de01cdf0 369
a0eca509 370 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
de01cdf0 371 //FIXME: this might happen. Handle it.
372 if (!param2)
373 {
374 cerr << "param2 is null : FIXME : this might happen !" << endl;
375 delete d;
376 return 0;
377 }
378
379 for ( Int_t i = 0; i < param->Size(); ++i )
380 {
381 for ( Int_t j = 0; j < param->Dimension(); ++j )
382 {
383 Float_t value(0);
384 if ( sopt.Contains("ABS") )
385 {
386 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
387 }
046e5fd4 388 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
de01cdf0 389 {
390 if ( param->ValueAsFloat(i,j) )
391 {
392 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
393 }
394 else
395 {
396 continue;
397 }
046e5fd4 398 if ( sopt.Contains("PERCENT") ) value *= 100.0;
de01cdf0 399 }
400 param->SetValueAsFloat(i,j,value);
401 }
402 }
de01cdf0 403 }
404 return d;
405}
406
407//_____________________________________________________________________________
408void
a0eca509 409AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
de01cdf0 410{
046e5fd4 411 /// Make histograms of each dimension of the AliMUONVCalibParam
de01cdf0 412 /// contained inside store.
413 /// It produces histograms named name_0, name_1, etc...
414
a99c3449 415 if (!AliMUONCDB::CheckMapping(kTRUE)) return;
416
046e5fd4 417 TIter next(store.CreateIterator());
418 AliMUONVCalibParam* param;
de01cdf0 419 Int_t n(0);
046e5fd4 420 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
421 Int_t* nPerStation = new Int_t[kNStations];
422 TH1** h(0x0);
de01cdf0 423
046e5fd4 424 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
de01cdf0 425
046e5fd4 426 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
de01cdf0 427 {
046e5fd4 428 if (!h)
429 {
430 Int_t dim = param->Dimension();
431 h = new TH1*[dim];
432 Float_t* xmin = new Float_t[dim];
433 Float_t* xmax = new Float_t[dim];
434 getBoundaries(store,dim,xmin,xmax);
435
436 for ( Int_t i = 0; i < dim; ++i )
437 {
438 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
439 nbins,xmin[i],xmax[i]);
a99c3449 440 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
046e5fd4 441 }
f1bf7efd 442 delete [] xmin;
443 delete [] xmax;
046e5fd4 444 }
445
446 Int_t detElemId = param->ID0();
447 Int_t manuId = param->ID1();
448 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
de01cdf0 449
450 const AliMpVSegmentation* seg =
451 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
452
046e5fd4 453 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
de01cdf0 454 {
168e9c4d 455 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
046e5fd4 456 if (!pad.IsValid()) continue;
de01cdf0 457
046e5fd4 458 ++n;
459 ++nPerStation[station];
460
461 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
462 {
463 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
de01cdf0 464 }
465 }
046e5fd4 466 }
de01cdf0 467
046e5fd4 468 for ( Int_t i = 0; i < kNStations; ++i )
de01cdf0 469 {
a99c3449 470 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
de01cdf0 471 }
046e5fd4 472
a99c3449 473 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
046e5fd4 474
475 delete[] nPerStation;
de01cdf0 476}
477
478//_____________________________________________________________________________
479Int_t
480AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
481{
482 /// Create a HV store
483
a99c3449 484 if (!AliMUONCDB::CheckMapping()) return 0;
485
49e110ec 486 AliMpDCSNamer hvNamer("TRACKER");
de01cdf0 487
488 TObjArray* aliases = hvNamer.GenerateAliases();
489
490 Int_t nSwitch(0);
491 Int_t nChannels(0);
492
493 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
494 {
495 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
496 TString& aliasName = alias->String();
497 if ( aliasName.Contains("sw") )
498 {
499 // HV Switch (St345 only)
500 TObjArray* valueSet = new TObjArray;
501 valueSet->SetOwner(kTRUE);
502
503 Bool_t value = kTRUE;
504
505 if (!defaultValues)
506 {
a0eca509 507 Float_t r = gRandom->Uniform();
de01cdf0 508 if ( r < 0.007 ) value = kFALSE;
509 }
510
511 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
512 {
513 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
514 valueSet->Add(dcsValue);
515 }
516 aliasMap.Add(new TObjString(*alias),valueSet);
517 ++nSwitch;
518 }
519 else
520 {
521 TObjArray* valueSet = new TObjArray;
522 valueSet->SetOwner(kTRUE);
523 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
524 {
525 Float_t value = 1500;
cf27231a 526 if (!defaultValues) value = GetRandom(1750,62.5,true);
de01cdf0 527 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
528 valueSet->Add(dcsValue);
529 }
530 aliasMap.Add(new TObjString(*alias),valueSet);
531 ++nChannels;
532 }
533 }
534
535 delete aliases;
536
a99c3449 537 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
de01cdf0 538
539 return nChannels+nSwitch;
540}
541
49e110ec 542//_____________________________________________________________________________
543Int_t
544AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
545{
546 /// Create a Trigger HV and Currents store
547
a99c3449 548 if (!AliMUONCDB::CheckMapping()) return 0;
549
49e110ec 550 AliMpDCSNamer triggerDCSNamer("TRIGGER");
551
552 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
553
554 Int_t nChannels[2] = {0, 0};
555
556 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
557 {
558 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
559 TString& aliasName = alias->String();
560
561 TObjArray* valueSet = new TObjArray;
562 valueSet->SetOwner(kTRUE);
ad30b53f 563
49e110ec 564 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
ad30b53f 565 if ( measureType < 0 ) {
566 AliErrorGeneralStream("AliMUONCDB")
567 << "Failed to get DCS variable from an alias (trigger): "
568 << aliasName.Data() << endl;
569 return 0;
570 }
571
49e110ec 572 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
573 {
574 Float_t value =
9b1e069f 575 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
49e110ec 576 if (!defaultValues) {
577 switch (measureType){
578 case AliMpDCSNamer::kDCSI:
9b1e069f 579 value = GetRandom(2.,0.4,true);
49e110ec 580 break;
581 case AliMpDCSNamer::kDCSHV:
9b1e069f 582 value = GetRandom(8000.,16.,true);
49e110ec 583 break;
584 }
585 }
586 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
587 valueSet->Add(dcsValue);
588 }
589 aliasMap.Add(new TObjString(*alias),valueSet);
590 ++nChannels[measureType];
591 }
592
593 delete aliases;
594
a99c3449 595 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
49e110ec 596
597 return nChannels[0] + nChannels[1];
598}
599
de01cdf0 600//_____________________________________________________________________________
601Int_t
a0eca509 602AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
de01cdf0 603{
604 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
605 /// otherwise mean and sigma are from a gaussian (with parameters
606 /// defined below by the kPedestal* constants)
409de10f 607
a99c3449 608 AliCodeTimerAutoGeneral("",0);
609
610 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 611
612 Int_t nchannels(0);
613 Int_t nmanus(0);
614
a0eca509 615 const Int_t kChannels(AliMpConstants::ManuNofChannels());
e7ee8d13 616
617 // bending
618 const Float_t kPedestalMeanMeanB(200.);
619 const Float_t kPedestalMeanSigmaB(10.);
620 const Float_t kPedestalSigmaMeanB(1.);
621 const Float_t kPedestalSigmaSigmaB(0.2);
622
623 // non bending
624 const Float_t kPedestalMeanMeanNB(200.);
625 const Float_t kPedestalMeanSigmaNB(10.);
626 const Float_t kPedestalSigmaMeanNB(1.);
627 const Float_t kPedestalSigmaSigmaNB(0.2);
628
629 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
409de10f 630
631 Int_t detElemId;
632 Int_t manuId;
633
634 AliMpManuIterator it;
de01cdf0 635
409de10f 636 while ( it.Next(detElemId,manuId) )
de01cdf0 637 {
e7ee8d13 638 // skip a given fraction of manus
639 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
640
de01cdf0 641 ++nmanus;
a0eca509 642
046e5fd4 643 AliMUONVCalibParam* ped =
644 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
409de10f 645
646 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 647
648 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
649 {
409de10f 650 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 651
652 ++nchannels;
653
654 Float_t meanPedestal;
655 Float_t sigmaPedestal;
656
657 if ( defaultValues )
658 {
659 meanPedestal = 0.0;
660 sigmaPedestal = 1.0;
661 }
662 else
663 {
cf27231a 664 Bool_t positive(kTRUE);
046e5fd4 665 meanPedestal = 0.0;
e7ee8d13 666
667 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
668
669 while ( meanPedestal == 0.0 ) // avoid strict zero
670 {
671 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
672 }
673 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
674
675 } else { // manu in bending plane
676
677 while ( meanPedestal == 0.0 ) // avoid strict zero
678 {
679 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
680 }
681 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
682
683 }
684
de01cdf0 685 }
e7ee8d13 686
de01cdf0 687 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
688 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
689
690 }
a0eca509 691 Bool_t ok = pedestalStore.Add(ped);
de01cdf0 692 if (!ok)
693 {
a99c3449 694 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 695 }
696 }
697
a99c3449 698 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
de01cdf0 699 return nchannels;
de01cdf0 700}
701
0045b488 702//_____________________________________________________________________________
703AliMUONRejectList*
704AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
705{
706 /// Create a reject list
707
a99c3449 708 AliCodeTimerAutoGeneral("",0);
0045b488 709
710 AliMUONRejectList* rl = new AliMUONRejectList;
711
712 if (!defaultValues)
713 {
714 rl->SetDetectionElementProbability(510);
715 rl->SetDetectionElementProbability(508);
716 return rl;
717 }
718
719 return rl;
720}
721
2b8a1212 722//_____________________________________________________________________________
723Int_t
7eafe398 724AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
2b8a1212 725{
7eafe398 726 /// Create an occupancy map.
2b8a1212 727
a99c3449 728 AliCodeTimerAutoGeneral("",0);
729
730 if (!AliMUONCDB::CheckMapping()) return 0;
2b8a1212 731
2b8a1212 732 Int_t nmanus(0);
733
2b8a1212 734 Int_t detElemId;
735 Int_t manuId;
736
737 AliMpManuIterator it;
738
7eafe398 739 Int_t nevents(1000);
740
2b8a1212 741 while ( it.Next(detElemId,manuId) )
742 {
2b8a1212 743 ++nmanus;
744
7eafe398 745 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
2b8a1212 746
7eafe398 747 Double_t occ = 0.0;
748
2b8a1212 749 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
750
7eafe398 751 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
752
a99c3449 753 if (!defaultValues) occ = gRandom->Rndm(1);
7eafe398 754
755 Double_t sumn = occ*nevents;
756
757 occupancy->SetValueAsFloat(0,0,sumn);
758 occupancy->SetValueAsFloat(0,1,sumn);
759 occupancy->SetValueAsFloat(0,2,sumn);
760 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
761 occupancy->SetValueAsInt(0,4,nevents);
762
763 Bool_t ok = occupancyMapStore.Add(occupancy);
2b8a1212 764 if (!ok)
765 {
a99c3449 766 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
2b8a1212 767 }
2b8a1212 768 }
769
7eafe398 770 return nmanus;
2b8a1212 771}
772
25e1df3e 773//_____________________________________________________________________________
774Int_t
775AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
776{
6687de6d 777 /// Read the capacitance values from file and append them to the capaStore
778
a99c3449 779 if (!AliMUONCDB::CheckMapping()) return 0;
780
49419555 781 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
25e1df3e 782}
783
de01cdf0 784//_____________________________________________________________________________
785Int_t
a0eca509 786AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
de01cdf0 787{
788 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
789 /// otherwise they are from a gaussian with parameters defined in the
790 /// kCapa* constants below.
409de10f 791
a99c3449 792 AliCodeTimerAutoGeneral("",0);
793
794 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 795
796 Int_t nchannels(0);
797 Int_t nmanus(0);
798 Int_t nmanusOK(0); // manus for which we got the serial number
a0eca509 799
25e1df3e 800 const Float_t kCapaMean(0.3);
801 const Float_t kCapaSigma(0.1);
802 const Float_t kInjectionGainMean(3);
803 const Float_t kInjectionGainSigma(1);
409de10f 804
805 Int_t detElemId;
806 Int_t manuId;
807
808 AliMpManuIterator it;
de01cdf0 809
409de10f 810 while ( it.Next(detElemId,manuId) )
de01cdf0 811 {
812 ++nmanus;
813
de01cdf0 814 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
ab167304 815 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
de01cdf0 816
a0eca509 817 if ( serialNumber <= 0 ) continue;
818
819 ++nmanusOK;
de01cdf0 820
a0eca509 821 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
de01cdf0 822
823 if (!capa)
824 {
25e1df3e 825 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
a0eca509 826 Bool_t ok = capaStore.Add(capa);
de01cdf0 827 if (!ok)
828 {
a99c3449 829 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
de01cdf0 830 }
831 }
832
833 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
834 {
409de10f 835 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 836
837 ++nchannels;
838
839 Float_t capaValue;
25e1df3e 840 Float_t injectionGain;
de01cdf0 841
842 if ( defaultValues )
843 {
844 capaValue = 1.0;
25e1df3e 845 injectionGain = 1.0;
de01cdf0 846 }
847 else
848 {
cf27231a 849 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
25e1df3e 850 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
de01cdf0 851 }
852 capa->SetValueAsFloat(manuChannel,0,capaValue);
25e1df3e 853 capa->SetValueAsFloat(manuChannel,1,injectionGain);
de01cdf0 854 }
855 }
856
857 Float_t percent = 0;
858 if ( nmanus ) percent = 100*nmanusOK/nmanus;
a99c3449 859 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
de01cdf0 860 nmanusOK,nmanus,percent));
a99c3449 861 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
de01cdf0 862 if ( percent < 100 )
863 {
a99c3449 864 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
de01cdf0 865 }
866 return nchannels;
867
868}
869
870//_____________________________________________________________________________
871Int_t
a0eca509 872AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
de01cdf0 873{
cf27231a 874 /// Create a gain store. if defaultValues=true, all gains set so that
875 /// charge = (adc-ped)
876 ///
877 /// otherwise parameters are taken from gaussians with parameters
878 /// defined in the k* constants below.
de01cdf0 879
a99c3449 880 AliCodeTimerAutoGeneral("",0);
881
882 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 883
884 Int_t nchannels(0);
885 Int_t nmanus(0);
a0eca509 886
cf27231a 887 const Int_t kSaturation(3000);
888 const Double_t kA0Mean(1.2);
409de10f 889 const Double_t kA0Sigma(0.1);
890 const Double_t kA1Mean(1E-5);
891 const Double_t kA1Sigma(1E-6);
cf27231a 892 const Double_t kQualMean(0xFF);
893 const Double_t kQualSigma(0x10);
894 const Int_t kThresMean(1600);
409de10f 895 const Int_t kThresSigma(100);
896
897 Int_t detElemId;
898 Int_t manuId;
de01cdf0 899
409de10f 900 AliMpManuIterator it;
901
902 while ( it.Next(detElemId,manuId) )
de01cdf0 903 {
904 ++nmanus;
de01cdf0 905
a0eca509 906 AliMUONVCalibParam* gain =
cf27231a 907 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
a0eca509 908 detElemId,
909 manuId,
910 AliMUONVCalibParam::InvalidFloatValue());
911
409de10f 912 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 913
914 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
915 {
409de10f 916 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 917
918 ++nchannels;
919
de01cdf0 920 if ( defaultValues )
921 {
cf27231a 922 gain->SetValueAsFloat(manuChannel,0,1.0);
923 gain->SetValueAsFloat(manuChannel,1,0.0);
924 gain->SetValueAsInt(manuChannel,2,4095);
925 gain->SetValueAsInt(manuChannel,3,1);
926 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 927 }
928 else
929 {
cf27231a 930 Bool_t positive(kTRUE);
931 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
932 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
933 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
934 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
935 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 936 }
de01cdf0 937
938 }
a0eca509 939 Bool_t ok = gainStore.Add(gain);
de01cdf0 940 if (!ok)
941 {
a99c3449 942 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 943 }
944 }
945
a99c3449 946 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
de01cdf0 947 return nchannels;
948}
949
950//_____________________________________________________________________________
951Int_t
a99c3449 952AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
de01cdf0 953{
954 /// Generate local trigger masks store. All masks are set to FFFF
955
a99c3449 956 AliCodeTimerAutoGeneral("",0);
409de10f 957
de01cdf0 958 Int_t ngenerated(0);
630711ed 959 // Generate fake mask values for all localboards and put that into
de01cdf0 960 // one single container (localBoardMasks)
0145e89a 961 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
de01cdf0 962 {
a0eca509 963 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
de01cdf0 964 for ( Int_t x = 0; x < 2; ++x )
965 {
966 for ( Int_t y = 0; y < 4; ++y )
967 {
968 Int_t index = x*4+y;
969 localBoard->SetValueAsInt(index,0,0xFFFF);
970 ++ngenerated;
971 }
972 }
a0eca509 973 localBoardMasks.Add(localBoard);
de01cdf0 974 }
975 return ngenerated;
976}
977
978//_____________________________________________________________________________
979Int_t
a99c3449 980AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
de01cdf0 981{
92c23b09 982 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
de01cdf0 983
a99c3449 984 AliCodeTimerAutoGeneral("",0);
409de10f 985
5cc125b2 986 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
a99c3449 987 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
5cc125b2 988 return 0;
989 }
990
991 return rtm.GetNofTriggerCrates();
de01cdf0 992}
993
92c23b09 994
de01cdf0 995//_____________________________________________________________________________
996Int_t
a99c3449 997AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
de01cdf0 998{
92c23b09 999 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
de01cdf0 1000
a99c3449 1001 AliCodeTimerAutoGeneral("",0);
913f1b43 1002
1003 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
de01cdf0 1004}
1005
92c23b09 1006
de01cdf0 1007//_____________________________________________________________________________
1008AliMUONTriggerLut*
a99c3449 1009AliMUONCDB::MakeTriggerLUT(const char* file)
de01cdf0 1010{
1011 /// Make a triggerlut object, from a file.
1012
a99c3449 1013 AliCodeTimerAutoGeneral("",0);
409de10f 1014
de01cdf0 1015 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1016 lut->ReadFromFile(file);
1017 return lut;
1018}
1019
1020//_____________________________________________________________________________
1021AliMUONTriggerEfficiencyCells*
a99c3449 1022AliMUONCDB::MakeTriggerEfficiency(const char* file)
de01cdf0 1023{
1024 /// Make a trigger efficiency object from a file.
1025
a99c3449 1026 AliCodeTimerAutoGeneral("",0);
409de10f 1027
de01cdf0 1028 return new AliMUONTriggerEfficiencyCells(file);
1029}
1030
25e1df3e 1031//_____________________________________________________________________________
1032void
1033AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1034 Int_t startRun, Int_t endRun,
1035 const char* filename)
1036{
1037 /// Write a given object to OCDB
1038
913f1b43 1039 TString comment(gSystem->ExpandPathName(filename));
1040
1041 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
25e1df3e 1042}
1043
de01cdf0 1044//_____________________________________________________________________________
1045void
1046AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1047 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1048{
1049 /// Write a given object to OCDB
1050
913f1b43 1051 TString comment;
1052 if ( defaultValues ) comment += "Test with default values";
1053 else comment += "Test with random values";
1054
1055 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1056}
1057
1058//_____________________________________________________________________________
1059void
1060AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1061 const char* comment, const char* responsible)
1062{
1063 /// Write a given object to OCDB
1064
a99c3449 1065 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1066
de01cdf0 1067 AliCDBId id(calibpath,startRun,endRun);
1068 AliCDBMetaData md;
1069 md.SetAliRootVersion(gROOT->GetVersion());
913f1b43 1070 md.SetComment(comment);
1071 md.SetResponsible(responsible);
a99c3449 1072 AliCDBManager::Instance()->Put(object,id,&md);
de01cdf0 1073}
1074
1075//_____________________________________________________________________________
1076Int_t
a0eca509 1077AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
de01cdf0 1078{
1079 /// Fill the neighbours store with, for each channel, a TObjArray of its
1080 /// neighbouring pads (including itself)
1081
a99c3449 1082 AliCodeTimerAutoGeneral("",0);
1083
1084 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 1085
a99c3449 1086 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
de01cdf0 1087
1088 Int_t nchannels(0);
1089
1090 TObjArray tmp;
409de10f 1091
1092 Int_t detElemId;
1093 Int_t manuId;
de01cdf0 1094
409de10f 1095 AliMpManuIterator it;
1096
1097 while ( it.Next(detElemId,manuId) )
de01cdf0 1098 {
de01cdf0 1099 const AliMpVSegmentation* seg =
1100 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1101
a0eca509 1102 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
de01cdf0 1103 if (!calibParam)
1104 {
1105 Int_t dimension(11);
a0eca509 1106 Int_t size(AliMpConstants::ManuNofChannels());
de01cdf0 1107 Int_t defaultValue(-1);
a0eca509 1108 Int_t packingFactor(size);
de01cdf0 1109
a0eca509 1110 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1111 Bool_t ok = neighbourStore.Add(calibParam);
de01cdf0 1112 if (!ok)
1113 {
a99c3449 1114 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 1115 return -1;
1116 }
1117 }
1118
a0eca509 1119 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
de01cdf0 1120 {
168e9c4d 1121 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
de01cdf0 1122
1123 if (pad.IsValid())
1124 {
1125 ++nchannels;
1126
1127 seg->GetNeighbours(pad,tmp,true,true);
1128 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1129
1130 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1131 {
bf0d3528 1132 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
de01cdf0 1133 Int_t x;
409de10f 1134// Bool_t ok =
6e97fbb8 1135 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
409de10f 1136// if (!ok)
1137// {
1138// AliError("Could not pack value. Something is seriously wrong. Please check");
1139// StdoutToAliError(pad->Print(););
1140// return -1;
1141// }
de01cdf0 1142 calibParam->SetValueAsInt(manuChannel,i,x);
1143 }
1144 }
1145 }
1146 }
1147
de01cdf0 1148 return nchannels;
1149}
1150
1151//_____________________________________________________________________________
1152void
1153AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1154{
1155 /// Write local trigger masks to OCDB
1156
630711ed 1157 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
de01cdf0 1158 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
a99c3449 1159 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1160 if (ngenerated>0)
1161 {
1162 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1163 }
1164 delete ltm;
1165}
1166
1167//_____________________________________________________________________________
1168void
92c23b09 1169AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 1170{
1171 /// Write regional trigger masks to OCDB
1172
92c23b09 1173 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1174 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
a99c3449 1175 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1176 if (ngenerated>0)
1177 {
92c23b09 1178 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
de01cdf0 1179 }
1180 delete rtm;
1181}
1182
92c23b09 1183
de01cdf0 1184//_____________________________________________________________________________
1185void
92c23b09 1186AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 1187{
1188 /// Write global trigger masks to OCDB
1189
92c23b09 1190 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
de01cdf0 1191
92c23b09 1192 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
a99c3449 1193 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1194 if (ngenerated>0)
1195 {
92c23b09 1196 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
de01cdf0 1197 }
1198 delete gtm;
1199}
1200
92c23b09 1201
de01cdf0 1202//_____________________________________________________________________________
1203void
1204AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1205{
1206 /// Write trigger LUT to OCDB
1207
1208 AliMUONTriggerLut* lut = MakeTriggerLUT();
1209 if (lut)
1210 {
1211 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1212 }
1213 delete lut;
1214}
1215
1216//_____________________________________________________________________________
1217void
1218AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1219{
1220 /// Write trigger efficiency to OCDB
1221
1222 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1223 if (eff)
1224 {
1225 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1226 }
1227 delete eff;
1228}
1229
1230//_____________________________________________________________________________
1231void
1232AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1233{
1234 /// Write neighbours to OCDB
1235
409de10f 1236 AliMUONVStore* neighbours = Create2DMap();
de01cdf0 1237 Int_t ngenerated = MakeNeighbourStore(*neighbours);
a99c3449 1238 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1239 if (ngenerated>0)
1240 {
1241 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1242 }
1243 delete neighbours;
1244}
1245
1246//_____________________________________________________________________________
1247void
1248AliMUONCDB::WriteHV(Bool_t defaultValues,
1249 Int_t startRun, Int_t endRun)
1250{
1251 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1252 /// if defaultValues=false, see makeHVStore) and
1253 /// store them into CDB located at cdbpath, with a validity period
1254 /// ranging from startRun to endRun
1255
1256 TMap* hvStore = new TMap;
1257 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
a99c3449 1258 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1259 if (ngenerated>0)
1260 {
1261 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1262 }
1263 delete hvStore;
1264}
1265
49e110ec 1266//_____________________________________________________________________________
1267void
1268AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1269 Int_t startRun, Int_t endRun)
1270{
1271 /// generate Trigger HV and current values (either const if defaultValues=true or random
1272 /// if defaultValues=false, see makeTriggerDCSStore) and
1273 /// store them into CDB located at cdbpath, with a validity period
1274 /// ranging from startRun to endRun
1275
1276 TMap* triggerDCSStore = new TMap;
1277 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
a99c3449 1278 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
49e110ec 1279 if (ngenerated>0)
1280 {
1281 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1282 }
1283 delete triggerDCSStore;
1284}
1285
de01cdf0 1286//_____________________________________________________________________________
1287void
1288AliMUONCDB::WritePedestals(Bool_t defaultValues,
1289 Int_t startRun, Int_t endRun)
1290{
1291 /// generate pedestal values (either 0 if defaultValues=true or random
1292 /// if defaultValues=false, see makePedestalStore) and
1293 /// store them into CDB located at cdbpath, with a validity period
1294 /// ranging from startRun to endRun
1295
409de10f 1296 AliMUONVStore* pedestalStore = Create2DMap();
de01cdf0 1297 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
a99c3449 1298 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1299 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1300 delete pedestalStore;
1301}
1302
2b8a1212 1303//_____________________________________________________________________________
1304void
7eafe398 1305AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1306 Int_t startRun, Int_t endRun)
2b8a1212 1307{
7eafe398 1308 /// generate occupancy map values (either empty one if defaultValues=true, or
1309 /// random one, see MakeOccupancyMapStore) and
2b8a1212 1310 /// store them into CDB located at cdbpath, with a validity period
1311 /// ranging from startRun to endRun
1312
7eafe398 1313 AliMUONVStore* occupancyMapStore = Create2DMap();
1314 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
a99c3449 1315 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
7eafe398 1316 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1317 delete occupancyMapStore;
2b8a1212 1318}
1319
0045b488 1320//_____________________________________________________________________________
1321void
1322AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1323 Int_t startRun, Int_t endRun)
1324{
1325 /// generate reject list values (either empty one if defaultValues=true, or
1326 /// random one, see MakeRejectListStore) and
1327 /// store them into CDB located at cdbpath, with a validity period
1328 /// ranging from startRun to endRun
1329
1330 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1331 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1332 delete rl;
1333}
1334
de01cdf0 1335
1336//_____________________________________________________________________________
1337void
1338AliMUONCDB::WriteGains(Bool_t defaultValues,
1339 Int_t startRun, Int_t endRun)
1340{
1341 /// generate gain values (either 1 if defaultValues=true or random
1342 /// if defaultValues=false, see makeGainStore) and
1343 /// store them into CDB located at cdbpath, with a validity period
1344 /// ranging from startRun to endRun
1345
409de10f 1346 AliMUONVStore* gainStore = Create2DMap();
de01cdf0 1347 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
a99c3449 1348 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1349 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1350 delete gainStore;
1351}
1352
25e1df3e 1353//_____________________________________________________________________________
1354void
1355AliMUONCDB::WriteCapacitances(const char* filename,
1356 Int_t startRun, Int_t endRun)
1357{
1358 /// read manu capacitance and injection gain values from file
1359 /// and store them into CDB located at cdbpath, with a validity period
1360 /// ranging from startRun to endRun
1361
1362 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1363 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
a99c3449 1364 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
25e1df3e 1365 if ( ngenerated > 0 )
1366 {
1367 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1368 }
1369 delete capaStore;
1370}
1371
de01cdf0 1372//_____________________________________________________________________________
1373void
1374AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1375 Int_t startRun, Int_t endRun)
1376{
1377 /// generate manu capacitance values (either 1 if defaultValues=true or random
1378 /// if defaultValues=false, see makeCapacitanceStore) and
1379 /// store them into CDB located at cdbpath, with a validity period
1380 /// ranging from startRun to endRun
1381
a0eca509 1382 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
de01cdf0 1383 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
a99c3449 1384 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1385 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1386 delete capaStore;
1387}
1388
1389//_____________________________________________________________________________
1390void
49e110ec 1391AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
de01cdf0 1392{
1393 /// Writes all Trigger related calibration to CDB
49e110ec 1394 WriteTriggerDCS(defaultValues,startRun,endRun);
de01cdf0 1395 WriteLocalTriggerMasks(startRun,endRun);
92c23b09 1396 WriteRegionalTriggerConfig(startRun,endRun);
1397 WriteGlobalTriggerConfig(startRun,endRun);
de01cdf0 1398 WriteTriggerLut(startRun,endRun);
1399 WriteTriggerEfficiency(startRun,endRun);
1400}
1401
a31df857 1402//_____________________________________________________________________________
1403void
1404AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1405{
1406 /// Write complete tracker configuration to OCDB
1407 ostringstream lines;
1408 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1409 AliMpBusPatch* bp;
1410 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1411 {
1412 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1413 {
1414 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1415 }
1416 }
1417
1418 AliMUON2DMap config(kTRUE);
a31df857 1419
042cd64e 1420 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
a31df857 1421
1422 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1423}
1424
de01cdf0 1425//_____________________________________________________________________________
1426void
1427AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1428{
1429 /// Writes all Tracker related calibration to CDB
1430 WriteHV(defaultValues,startRun,endRun);
1431 WritePedestals(defaultValues,startRun,endRun);
1432 WriteGains(defaultValues,startRun,endRun);
1433 WriteCapacitances(defaultValues,startRun,endRun);
1434 WriteNeighbours(startRun,endRun);
c21c5694 1435 WriteOccupancyMap(defaultValues,startRun,endRun);
1436 WriteRejectList(defaultValues,startRun,endRun);
a31df857 1437 WriteConfig(startRun,endRun);
de01cdf0 1438}
913f1b43 1439
c241bfaa 1440//_____________________________________________________________________________
1441void
1442AliMUONCDB::ShowCapacitances()
1443{
1444 /// Show briefly the number of capa values we have in the OCDB,
1445 /// and the list of manu that are actually in the config and for which
1446 /// we miss the capa (if any).
1447
1448 if (!AliMUONCDB::CheckOCDB()) return;
1449
1450 AliMUONCDB::LoadMapping();
1451
1452 if (!AliMUONCDB::CheckMapping()) return;
1453
1454 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1455
1456 if (!e) return ;
1457
1458 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1459
1460 e = AliCDBManager::Instance()->Get("MUON/Calib/Capacitances");
1461
1462 if (!e) return;
1463
1464 AliMUONVStore* capacitances = static_cast<AliMUONVStore*>(e->GetObject());
1465
1466 AliInfoGeneral("ShowCapacitances",Form("%d capacitances are in OCDB",capacitances->GetSize()));
1467
1468 TIter nextManu(config->CreateIterator());
1469 AliMUONVCalibParam* param;
1470
1471 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1472 {
1473 Int_t detElemId = param->ID0();
1474 Int_t manuId = param->ID1();
1475
1476 Int_t serialNumber
1477 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
1478
1479 if (serialNumber<0)
1480 {
1481 AliErrorGeneral("ShowCapacitances",Form("Did not find serial for DE %04d MANUID %04d",detElemId,manuId));
1482 }
1483 else
1484 {
1485 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capacitances->FindObject(serialNumber));
1486 if (!capa)
1487 {
1488 AliErrorGeneral("ShowCapacitances",Form("Did not find capacitance for DE %04d MANUID %04d SERIAL %d",detElemId,manuId,serialNumber));
1489 }
1490 }
1491 }
1492
1493}
1494
5148da98 1495//_____________________________________________________________________________
1496void
207947f7 1497AliMUONCDB::ShowConfig(Bool_t withStatusMap)
5148da98 1498{
1499 /// Dumps the current tracker configuration, i.e. number and identity of missing buspatches
207947f7 1500 /// If statusMap is true, will also take into account the status map to report the number
1501 /// of good channels
1502
5148da98 1503 if (!AliMUONCDB::CheckOCDB()) return;
1504
1505 AliMUONCDB::LoadMapping();
1506
1507 if (!AliMUONCDB::CheckMapping()) return;
1508
1509 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1510
1511 if (!e) return ;
1512
1513 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1514
207947f7 1515 AliMUONPadStatusMapMaker* statusMapMaker(0x0);
1516 AliMUONCalibrationData* cd(0x0);
1517 AliMUONPadStatusMaker* statusMaker(0x0);
1518
1519 if ( withStatusMap )
1520 {
1521 cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1522
1523 statusMaker = new AliMUONPadStatusMaker(*cd);
1524
1525 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
1526
1527 statusMaker->SetLimits(*recoParam);
1528
207947f7 1529 UInt_t mask = recoParam->PadGoodnessMask();
9b780418 1530
1531 delete recoParam;
1532
207947f7 1533 const Bool_t deferredInitialization = kFALSE;
1534
1535 statusMapMaker = new AliMUONPadStatusMapMaker(*cd,mask,deferredInitialization);
1536 }
1537
5148da98 1538 TIter nextManu(config->CreateIterator());
1539 AliMUONVCalibParam* param;
1540
1541 AliMpExMap buspatches;
1542
1543 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1544 {
1545 Int_t detElemId = param->ID0();
1546 Int_t manuId = param->ID1();
1547 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1548 if ( buspatches.GetValue(busPatchId) == 0x0 )
1549 {
1550 buspatches.Add(busPatchId,new TObjString(Form("BP%04d",busPatchId)));
1551 }
1552 }
1553
1554 TArrayI removed(buspatches.GetSize());
1555
1556 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1557 AliMpBusPatch* bp;
1558 Int_t n(0);
1559 Int_t nok(0);
1560 Int_t nremoved(0);
1561
207947f7 1562 // accounting of bus patches first
1563
5148da98 1564 while ( ( bp = static_cast<AliMpBusPatch*>(next())))
1565 {
1566 if ( buspatches.GetValue(bp->GetId()) )
1567 {
1568 ++nok;
1569 }
1570 else
1571 {
1572 removed.SetAt(bp->GetId(),nremoved++);
1573 }
5148da98 1574 }
1575
207947f7 1576 // accounting of channels
1577
1578 AliMpManuIterator it;
1579
1580 Int_t totalNumberOfChannels(0);
1581 Int_t removedChannels(0);
1582 Int_t badChannels(0);
1583 Int_t badAndRemovedChannels(0);
1584 Int_t badOrRemovedChannels(0);
1585
1586 Int_t detElemId, manuId;
1587
1588 while ( it.Next(detElemId,manuId) )
1589 {
1590 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1591 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1592 {
1593 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1594
1595 if ( de->IsConnectedChannel(manuId,i) )
1596 {
1597 ++totalNumberOfChannels;
1598 Bool_t badBusPatch = ( buspatches.GetValue(busPatchId) == 0x0 );
1599
1600 if ( withStatusMap )
1601 {
47274b13 1602 Bool_t badChannel = ( ( statusMapMaker->StatusMap(detElemId,manuId,i) & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0);
207947f7 1603 if ( badChannel ) ++badChannels;
1604 if ( badBusPatch && badChannel ) ++badAndRemovedChannels;
1605 if ( badBusPatch || badChannel ) ++badOrRemovedChannels;
1606 }
1607
1608 if ( badBusPatch) ++removedChannels;
1609 }
1610 }
1611 }
1612
5148da98 1613
1614 Int_t* indices = new Int_t[nremoved];
1615
1616 TMath::Sort(nremoved,removed.GetArray(),indices,kFALSE);
1617
1618 for ( Int_t i = 0; i < nremoved; ++i )
1619 {
1620 Int_t busPatchId = removed[indices[i]];
1621 bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1622 bp->Print();
1623 }
1624
1625 delete[] indices;
207947f7 1626
1627 cout << endl;
1628 cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d",n,nok,nremoved) << endl;
1629
1630 cout << Form("Channels n=%6d nremoved=%6d bad=%6d bad and removed=%6d bad or removed=%6d",
1631 totalNumberOfChannels,removedChannels,badChannels,badAndRemovedChannels,badOrRemovedChannels) << endl;
1632
1633 if (totalNumberOfChannels>0)
1634 {
1635 cout << Form("Percentage of readout channels %5.1f %%",removedChannels*100.0/totalNumberOfChannels) << endl;
1636 if ( withStatusMap )
1637 {
1638 cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1639 badOrRemovedChannels*100.0/totalNumberOfChannels) << endl;
1640 }
1641 }
1642
1643
1644 delete statusMapMaker;
1645 delete cd;
1646 delete statusMaker;
5148da98 1647}