Adding handling of Capacitances (Laurent)
[u/mrichter/AliRoot.git] / MUON / MUONCDB.C
CommitLineData
b3c7c475 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
18/// By Laurent Aphecetche
19
20#if !defined(__CINT__) || defined(__MAKECINT__)
d29760d6 21
b3c7c475 22#include "MUONCDB.h"
d29760d6 23
b3c7c475 24#include "AliCDBEntry.h"
25#include "AliCDBManager.h"
c3357e6d 26#include "AliDCSValue.h"
d29760d6 27#include "AliMUON1DArray.h"
c1bbaf66 28#include "AliMUON1DMap.h"
8f7d7575 29#include "AliMUON2DMap.h"
c3357e6d 30#include "AliMUON2DStoreValidator.h"
8f7d7575 31#include "AliMUONCalibParam1I.h"
9ff4fb4b 32#include "AliMUONCalibParamNF.h"
d29760d6 33#include "AliMUONConstants.h"
c3357e6d 34#include "AliMUONHVNamer.h"
5322694c 35#include "AliMUONObjectPair.h"
36#include "AliMUONTriggerEfficiencyCells.h"
d29760d6 37#include "AliMUONTriggerLut.h"
38#include "AliMUONV2DStore.h"
39#include "AliMUONVCalibParam.h"
c3357e6d 40#include "AliMUONVCalibParam.h"
5322694c 41#include "AliMUONVDataIterator.h"
c1bbaf66 42#include "AliMpDDLStore.h"
b3c7c475 43#include "AliMpDEIterator.h"
44#include "AliMpDEManager.h"
c1bbaf66 45#include "AliMpDetElement.h"
5322694c 46#include "AliMpManuList.h"
3e8e7033 47#include "AliMpSegmentation.h"
3e8e7033 48#include "AliMpStationType.h"
c3357e6d 49#include "AliMpVSegmentation.h"
b3c7c475 50#include "Riostream.h"
c3357e6d 51#include "TArrayI.h"
b3c7c475 52#include "TH1F.h"
53#include "TList.h"
c3357e6d 54#include "TMap.h"
55#include "TObjString.h"
c1bbaf66 56#include "TROOT.h"
b3c7c475 57#include "TRandom.h"
58#include "TStopwatch.h"
59#include "TSystem.h"
c3357e6d 60#include <map>
d29760d6 61
c3357e6d 62#endif
8f7d7575 63
64//_____________________________________________________________________________
5322694c 65AliMUONV2DStore* diff(AliMUONV2DStore& store1, AliMUONV2DStore& store2,
66 const char* /* opt */)
b3c7c475 67{
5322694c 68 // creates a store which contains store1-store2
69 // if opt="abs" the difference is absolute one,
70 // if opt="rel" then what is stored is (store1-store2)/store1
b3c7c475 71
5322694c 72 AliMUONV2DStore* d = static_cast<AliMUONV2DStore*>(store1.Clone());
73
74 AliMUONVDataIterator* it = d->Iterator();
75
76 AliMUONObjectPair* p;
b3c7c475 77
5322694c 78 while ( ( p = dynamic_cast<AliMUONObjectPair*>(it->Next() ) ) )
b3c7c475 79 {
5322694c 80 AliMpIntPair* dm = dynamic_cast<AliMpIntPair*>(p->Key());
81 //FIXME: this might happen (if a full manu is missing, for instance)
82 //handle it.
83 assert(dm!=0);
84 AliMUONVCalibParam* param = dynamic_cast<AliMUONVCalibParam*>(p->Value());
85 //FIXMENOT: this should *not* happen
86 assert(param!=0);
87
88 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.Get(dm->GetFirst(),dm->GetSecond()));
89 //FIXME: this might happen. Handle it.
90 assert(param2!=0);
91
92 for ( Int_t i = 0; i < param->Size(); ++i )
93 {
94 for ( Int_t j = 0; j < param->Dimension(); ++j )
95 {
96 param->SetValueAsFloat(i,j,param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j));
97 }
98 }
b3c7c475 99 }
5322694c 100 return d;
101}
102
103//_____________________________________________________________________________
104void getBoundaries(const AliMUONV2DStore& store,
105 Float_t& x0min, Float_t& x0max,
106 Float_t& x1min, Float_t& x1max)
107{
108 x0min=1E30;
109 x0max=-1E30;
110 x1min=1E30;
111 x1max=-1E30;
112
113 TList* list = AliMpManuList::ManuList();
114 TIter next(list);
115 AliMpIntPair* p;
116
117 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 118 {
5322694c 119 Int_t detElemId = p->GetFirst();
120 Int_t manuId = p->GetSecond();
121
3e8e7033 122 const AliMpVSegmentation* seg =
123 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
5322694c 124
125 AliMUONVCalibParam* value =
126 dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
127
128 if (!value) continue;
129
130 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
131 {
132 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
133 if (!pad.IsValid()) continue;
134
135 Float_t x0 = value->ValueAsFloat(manuChannel,0);
136
137 x0min = TMath::Min(x0min,x0);
138 x0max = TMath::Max(x0max,x0);
139 if ( value->Dimension()>1 )
140 {
141 Float_t x1 = value->ValueAsFloat(manuChannel,1);
142 x1min = TMath::Min(x1min,x1);
143 x1max = TMath::Max(x1max,x1);
144 }
145 }
146 }
147 delete list;
148}
149
150//_____________________________________________________________________________
151void plot(const AliMUONV2DStore& store, const char* name, Int_t nbins)
152{
153 Float_t x0min, x0max, x1min, x1max;
154
155 getBoundaries(store,x0min,x0max,x1min,x1max);
156
157 if ( x0min > x0max )
158 {
159 cerr << Form("Something is wrong with boundaries : x0(min,max)=%e,%e",
160 x0min,x0max) << endl;
161 return;
8f7d7575 162 }
5322694c 163
164 if ( TMath::Abs(x0min-x0max) < 1E-3 )
8f7d7575 165 {
5322694c 166 x0min -= 1;
167 x0max += 1;
b3c7c475 168 }
5322694c 169
170 TH1* h0 = new TH1F(Form("%s_0",name),Form("%s_0",name),
171 nbins,x0min,x0max);
172
173 TH1* h1(0);
174
175 if ( x1max > x1min )
b3c7c475 176 {
5322694c 177 h1 = new TH1F(Form("%s_1",name),Form("%s_1",name),
178 nbins,x1min,x1max);
b3c7c475 179 }
180
5322694c 181 TList* list = AliMpManuList::ManuList();
182 TIter next(list);
8f7d7575 183 AliMpIntPair* p;
184 Int_t n(0);
8f7d7575 185 Int_t nPerStation[7];
186
187 for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
b3c7c475 188
8f7d7575 189 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 190 {
8f7d7575 191 Int_t detElemId = p->GetFirst();
192 Int_t manuId = p->GetSecond();
aaf6e802 193 Int_t station = AliMpDEManager::GetChamberId(detElemId);
8f7d7575 194
3e8e7033 195 const AliMpVSegmentation* seg =
196 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
5322694c 197
8f7d7575 198 AliMUONVCalibParam* value =
5322694c 199 dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
b3c7c475 200
b3c7c475 201 if (value)
202 {
8f7d7575 203 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
204 {
5322694c 205 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
206 if (!pad.IsValid()) continue;
207
8f7d7575 208 ++n;
209 ++nPerStation[station];
5322694c 210 Float_t x = value->ValueAsFloat(manuChannel,0);
9ff4fb4b 211 if ( x>1E4 )
212 {
213 cout << Form("DE %d Manu %d Ch %d x=%e",detElemId,manuId,manuChannel,x)
214 << endl;
215 }
5322694c 216 h0->Fill(x);
217 if (h1)
8f7d7575 218 {
5322694c 219 h1->Fill(value->ValueAsFloat(manuChannel,1));
8f7d7575 220 }
221 }
b3c7c475 222 }
223 else
224 {
225 cout << "Got a null value for DE=" << detElemId << " manuId="
5322694c 226 << manuId << endl;
b3c7c475 227 }
228 }
229
8f7d7575 230 cout << "Number of channels = " << n << endl;
231 for ( Int_t i = 0; i < 7; ++i )
232 {
233 cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
234 }
235
5322694c 236 delete list;
237}
238
b3c7c475 239//_____________________________________________________________________________
8f7d7575 240void testReadStore(const AliMUONV2DStore& store, Int_t n)
b3c7c475 241{
5322694c 242 TList* list = AliMpManuList::ManuList();
243 TIter next(list);
8f7d7575 244 AliMpIntPair* p;
b3c7c475 245
8f7d7575 246 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 247 {
248 for ( Int_t i = 0; i < n; ++i )
249 {
8f7d7575 250 store.Get(p->GetFirst(),p->GetSecond());
b3c7c475 251 }
252 }
5322694c 253 delete list;
b3c7c475 254}
255
c3357e6d 256//_____________________________________________________________________________
257Int_t makeHVStore(TMap& aliasMap, Bool_t defaultValues)
258{
259 AliMUONHVNamer hvNamer;
260 TRandom random;
261
262 TObjArray* aliases = hvNamer.GenerateAliases();
263
264 Int_t nSwitch(0);
265 Int_t nChannels(0);
266
267 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
268 {
269 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
270 TString& aliasName = alias->String();
271 if ( aliasName.Contains("sw") )
272 {
273 // HV Switch (St345 only)
274 TObjArray* valueSet = new TObjArray;
275 valueSet->SetOwner(kTRUE);
276
277 Bool_t value = kTRUE;
278
279 if (!defaultValues)
280 {
281 Float_t r = random.Uniform();
282 if ( r < 0.007 ) value = kFALSE;
283 }
284
285 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
286 {
287 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
288 valueSet->Add(dcsValue);
289 }
290 aliasMap.Add(new TObjString(*alias),valueSet);
291 ++nSwitch;
292 }
293 else
294 {
295 TObjArray* valueSet = new TObjArray;
296 valueSet->SetOwner(kTRUE);
297 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
298 {
299 Float_t value = 1500;
300 if (!defaultValues) value = random.Gaus(1750,62.5);
301 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
302 valueSet->Add(dcsValue);
303 }
304 aliasMap.Add(new TObjString(*alias),valueSet);
305 ++nChannels;
306 }
307 }
308
309 delete aliases;
310
311 cout << nChannels << " HV channels and " << nSwitch << " switches" << endl;
312
313 return nChannels+nSwitch;
314}
315
b3c7c475 316//_____________________________________________________________________________
5322694c 317Int_t makePedestalStore(AliMUONV2DStore& pedestalStore, Bool_t defaultValues)
318{
319 TList* list = AliMpManuList::ManuList();
320 TIter next(list);
b3c7c475 321
8f7d7575 322 AliMpIntPair* p;
b3c7c475 323
5322694c 324 Int_t nchannels(0);
325 Int_t nmanus(0);
b3c7c475 326
327 Bool_t replace = kFALSE;
328
8f7d7575 329 const Int_t nChannels(64);
5322694c 330 const Float_t kPedestalMeanMean(150);
331 const Float_t kPedestalMeanSigma(10);
332 const Float_t kPedestalSigmaMean(1.0);
333 const Float_t kPedestalSigmaSigma(0.2);
8f7d7575 334
335 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 336 {
5322694c 337 ++nmanus;
9ff4fb4b 338 AliMUONVCalibParam* ped = new AliMUONCalibParamNF(2,nChannels,AliMUONVCalibParam::InvalidFloatValue());
5322694c 339
340 Int_t detElemId = p->GetFirst();
b70d763d 341
5322694c 342 Int_t manuId = p->GetSecond();
343
3e8e7033 344 const AliMpVSegmentation* seg =
345 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
5322694c 346
8f7d7575 347 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
b3c7c475 348 {
5322694c 349 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
350 if (!pad.IsValid()) continue;
351
352 ++nchannels;
353
8f7d7575 354 Float_t meanPedestal;
355 Float_t sigmaPedestal;
5322694c 356
8f7d7575 357 if ( defaultValues )
b3c7c475 358 {
8f7d7575 359 meanPedestal = 0.0;
360 sigmaPedestal = 1.0;
b3c7c475 361 }
8f7d7575 362 else
b3c7c475 363 {
8f7d7575 364 meanPedestal = -1;
365 while ( meanPedestal < 0 )
366 {
5322694c 367 meanPedestal = gRandom->Gaus(kPedestalMeanMean,kPedestalMeanSigma);
8f7d7575 368 }
369 sigmaPedestal = -1;
370 while ( sigmaPedestal < 0 )
371 {
5322694c 372 sigmaPedestal = gRandom->Gaus(kPedestalSigmaMean,kPedestalSigmaSigma);
8f7d7575 373 }
b3c7c475 374 }
8f7d7575 375 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
376 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
8f7d7575 377
5322694c 378 }
379 Bool_t ok = pedestalStore.Set(detElemId,manuId,ped,replace);
380 if (!ok)
381 {
382 cout << "Could not set DetElemId=" << detElemId << " manuId="
383 << manuId << endl;
384 }
385 }
386
387 delete list;
388 cout << nmanus << " Manus and " << nchannels << " channels." << endl;
389 return nchannels;
390
391}
392
c1bbaf66 393//_____________________________________________________________________________
394Int_t makeCapacitanceStore(AliMUONV1DStore& capaStore, Bool_t defaultValues)
395{
396 TList* list = AliMpManuList::ManuList();
397 TIter next(list);
398
399 AliMpIntPair* p;
400
401 Int_t nchannels(0);
402 Int_t nmanus(0);
403 Int_t nmanusOK(0); // manus for which we got the serial number
404
405 Bool_t replace = kFALSE;
406
407 const Int_t nChannels(64);
408 const Float_t kCapaMean(1.0);
409 const Float_t kCapaSigma(0.5);
410
411 while ( ( p = (AliMpIntPair*)next() ) )
412 {
413 ++nmanus;
414
415 Int_t detElemId = p->GetFirst();
416 Int_t manuId = p->GetSecond();
417
418 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
419 Int_t serialNumber = de->GetManuSerialFromId(manuId);
420
421 if ( serialNumber > 0 ) ++nmanusOK;
422
423 const AliMpVSegmentation* seg =
424 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
425
426 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.Get(serialNumber));
427
428 if (!capa)
429 {
430 capa = new AliMUONCalibParamNF(1,nChannels,1.0);
431 Bool_t ok = capaStore.Set(serialNumber,capa,replace);
432 if (!ok)
433 {
434 cout << "Could not set serialNumber=" << serialNumber << " manuId="
435 << manuId << endl;
436 }
437 }
438
439 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
440 {
441 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
442 if (!pad.IsValid()) continue;
443
444 ++nchannels;
445
446 Float_t capaValue;
447
448 if ( defaultValues )
449 {
450 capaValue = 1.0;
451 }
452 else
453 {
454 capaValue = -1;
455 while ( capaValue < 0 )
456 {
457 capaValue = gRandom->Gaus(kCapaMean,kCapaSigma);
458 }
459 }
460 capa->SetValueAsFloat(manuChannel,0,capaValue);
461 }
462 }
463
464 delete list;
465 Float_t percent = 0;
466 if ( nmanus ) percent = 100*nmanusOK/nmanus;
467 cout << Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
468 nmanusOK,nmanus,percent) << endl;
469 cout << Form("%5d channels",nchannels) << endl;
470 if ( percent < 100 )
471 {
472 cout << "WARNING : did not get all serial numbers. capaStore is incomplete !!!!"
473 << endl;
474 }
475 return nchannels;
476
477}
478
5322694c 479//_____________________________________________________________________________
480Int_t makeGainStore(AliMUONV2DStore& gainStore, Bool_t defaultValues)
481{
482 TList* list = AliMpManuList::ManuList();
483 TIter next(list);
484
485 AliMpIntPair* p;
486
487 Int_t nchannels(0);
488 Int_t nmanus(0);
489
490 Bool_t replace = kFALSE;
491
492 const Int_t nChannels(64);
493 const Double_t kSaturation(3000);
494 const Double_t kGainMean(1.0);
495 const Double_t kGainSigma(0.05);
496
497 while ( ( p = (AliMpIntPair*)next() ) )
498 {
499 ++nmanus;
9ff4fb4b 500 AliMUONVCalibParam* gain = new AliMUONCalibParamNF(2,nChannels,AliMUONVCalibParam::InvalidFloatValue());
5322694c 501
502 Int_t detElemId = p->GetFirst();
503 Int_t manuId = p->GetSecond();
504
3e8e7033 505 const AliMpVSegmentation* seg =
506 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
5322694c 507
508 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
509 {
510 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
511 if (!pad.IsValid()) continue;
512
513 ++nchannels;
514
515 Float_t meanGain;
516 Float_t saturation(kSaturation);
517
518 if ( defaultValues )
b3c7c475 519 {
5322694c 520 meanGain = 1.0;
521 }
522 else
523 {
524 meanGain = -1;
525 while ( meanGain < 0 )
8f7d7575 526 {
5322694c 527 meanGain = gRandom->Gaus(kGainMean,kGainSigma);
8f7d7575 528 }
b3c7c475 529 }
5322694c 530 gain->SetValueAsFloat(manuChannel,0,meanGain);
531 gain->SetValueAsFloat(manuChannel,1,saturation);
532
b3c7c475 533 }
5322694c 534 Bool_t ok = gainStore.Set(detElemId,manuId,gain,replace);
535 if (!ok)
b3c7c475 536 {
537 cout << "Could not set DetElemId=" << detElemId << " manuId="
8f7d7575 538 << manuId << endl;
b3c7c475 539 }
b3c7c475 540 }
541
5322694c 542 delete list;
543 cout << nmanus << " Manus and " << nchannels << " channels." << endl;
544 return nchannels;
b3c7c475 545}
546
b3c7c475 547//_____________________________________________________________________________
8f7d7575 548void testMakeStores(Int_t readLoop)
b3c7c475 549{
8f7d7575 550 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
551 AliMUONV2DStore* gainStore = new AliMUON2DMap;
b3c7c475 552
553 TStopwatch timer;
554
555 cout << "Creating" << endl;
556
5322694c 557 Bool_t defaultValues = kTRUE;
558
b3c7c475 559 timer.Start(kTRUE);
5322694c 560 makePedestalStore(*pedestalStore,defaultValues);
561 makeGainStore(*gainStore,defaultValues);
b3c7c475 562 timer.Print();
563
564 cout << "Reading..." << endl;
565 timer.Start(kTRUE);
566 testReadStore(*pedestalStore,readLoop);
567 testReadStore(*gainStore,readLoop);
568 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
569 <<" samples." << endl;
570
571 delete pedestalStore;
572 delete gainStore;
573}
574
d29760d6 575//_____________________________________________________________________________
576void generateTrigger(const char* cdbpath)
577{
578 //
579 // Generate trigger related conditions :
580 //
581 // - trigger masks for board (locals, regionals, global)
582 // - trigger lut
583 // - trigger efficiency
584 // - trigger switches (to be implemented FIXME)
585 //
586 const Int_t nlboards = 234;
587 AliMUONV1DStore* localBoardMasks = new AliMUON1DArray(nlboards+1);
588
589 // Generate fake mask values for 234 localboards and put that into
590 // one single container (localBoardMasks)
591 for ( Int_t i = 1; i <= nlboards; ++i )
592 {
593 AliMUONVCalibParam* localBoard = new AliMUONCalibParam1I(8);
594 for ( Int_t x = 0; x < 2; ++x )
595 {
596 for ( Int_t y = 0; y < 4; ++y )
597 {
598 Int_t index = x*4+y;
599 localBoard->SetValueAsInt(index,0,0xFFFF);
600 }
601 }
602 localBoardMasks->Set(i,localBoard,kFALSE);
603 }
604
605 // Generate values for regional boards
606 const Int_t nrboards = 16;
607 AliMUONV1DStore* regionalBoardMasks = new AliMUON1DArray(16);
608
609 for ( Int_t i = 0; i < nrboards; ++i )
610 {
611 AliMUONVCalibParam* regionalBoard = new AliMUONCalibParam1I(16);
612 for ( Int_t j = 0; j < 16; ++j )
613 {
614 regionalBoard->SetValueAsInt(j,0,0x3F);
615 }
616 regionalBoardMasks->Set(i,regionalBoard,kFALSE);
617 }
618
619 // Generate values for global board
620 AliMUONVCalibParam* globalBoardMasks = new AliMUONCalibParam1I(16);
621
622 for ( Int_t j = 0; j < 16; ++j )
623 {
624 globalBoardMasks->SetValueAsInt(j,0,0xFFF);
625 }
626
627 AliMUONTriggerLut lut;
bc6da0f1 628 lut.ReadFromFile("$(ALICE_ROOT)/MUON/data/lutAptLpt1Hpt1p7.root");
d29760d6 629
630 AliMUONTriggerEfficiencyCells cells("$ALICE_ROOT/MUON/data/efficiencyCells.dat");
631
632 //--------------------------------------------
633 // Store the resulting containers into the CDB
634 Int_t ever = 99999999;
635
636 AliCDBId id("MUON/Calib/LocalTriggerBoardMasks",0,ever);
637
638 AliCDBMetaData md;
639 md.SetBeamPeriod(1);
640 md.SetAliRootVersion(gROOT->GetVersion());
641 md.SetComment("Test with default values");
642 md.SetResponsible("Rachid Guernane");
643
644 AliCDBManager* man = AliCDBManager::Instance();
645 man->SetDefaultStorage(cdbpath);
646 man->Put(localBoardMasks,id,&md);
647
648 id.SetPath("MUON/Calib/RegionalTriggerBoardMasks");
649
650 man->Put(regionalBoardMasks,id,(AliCDBMetaData*)md.Clone());
651
652 id.SetPath("MUON/Calib/GlobalTriggerBoardMasks");
653
654 man->Put(globalBoardMasks,id,(AliCDBMetaData*)md.Clone());
655
656 id.SetPath("MUON/Calib/TriggerLut");
657
658 man->Put(&lut,id,(AliCDBMetaData*)md.Clone());
659
660 id.SetPath("MUON/Calib/TriggerEfficiency");
661 md.SetResponsible("Diego Stocco");
662
663 man->Put(&cells,id,(AliCDBMetaData*)md.Clone());
664
665 delete localBoardMasks;
666 delete regionalBoardMasks;
667 delete globalBoardMasks;
668}
669
5322694c 670
b3c7c475 671//_____________________________________________________________________________
5322694c 672void writeToCDB(const char* cdbpath, const char* calibpath, TObject* object,
673 Int_t startRun, Int_t endRun, Bool_t defaultValues)
b3c7c475 674{
5322694c 675 AliCDBId id(calibpath,startRun,endRun);
b3c7c475 676 AliCDBMetaData md;
677 md.SetBeamPeriod(1);
678 md.SetAliRootVersion(gROOT->GetVersion());
679 if ( defaultValues )
680 {
681 md.SetComment("Test with default values");
682 }
683 else
684 {
685 md.SetComment("Test with random values");
686 }
687 md.SetResponsible("Laurent Aphecetche");
688
689 AliCDBManager* man = AliCDBManager::Instance();
690 man->SetDefaultStorage(cdbpath);
5322694c 691 man->Put(object,id,&md);
692}
693
9ff4fb4b 694//_____________________________________________________________________________
695Int_t makeNeighbourStore(AliMUONV2DStore& neighbourStore)
696{
697 /// Fill the neighbours store with, for each channel, a TObjArray of its
698 /// neighbouring pads (including itself)
699
700 TStopwatch timer;
701
702 timer.Start(kTRUE);
703
704 TList* list = AliMpManuList::ManuList();
705 TIter next(list);
706
707 AliMpIntPair* p;
708
709 Int_t nchannels(0);
710
711 TObjArray tmp;
712
713 while ( ( p = (AliMpIntPair*)next() ) )
714 {
715 TObjArray* neighbours = new TObjArray(64);
716 neighbours->SetOwner(kTRUE);
717
718 Int_t detElemId = p->GetFirst();
719 Int_t manuId = p->GetSecond();
720
721 const AliMpVSegmentation* seg =
722 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
723
724 for ( Int_t manuChannel = 0; manuChannel < 64; ++manuChannel )
725 {
726 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
727 AliMUONVCalibParam* calibParam(0x0);
728
729 if (pad.IsValid())
730 {
731 ++nchannels;
732
733 seg->GetNeighbours(pad,tmp,true,true);
734 Int_t nofPadNeighbours = tmp.GetEntriesFast();
735
736 calibParam = new AliMUONCalibParam1I(nofPadNeighbours);
737 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
738 {
739 AliMpPad* pad = static_cast<AliMpPad*>(tmp.At(i));
740 Int_t x = pad->GetLocation().GetFirst() * 1000000 + pad->GetLocation().GetSecond();
741 calibParam->SetValueAsInt(i,0,x);
742 }
743 }
744 neighbours->AddAt(calibParam,manuChannel);
745 }
746
747 Bool_t ok = neighbourStore.Set(detElemId,manuId,neighbours,kFALSE);
748 if (!ok)
749 {
750 cout << "Could not set DetElemId=" << detElemId << " manuId="
751 << manuId << endl;
752 return -1;
753 }
754 }
755
756 timer.Print();
757
758 return nchannels;
759}
760
761//_____________________________________________________________________________
762void writeNeighbours(const char* cdbpath, Int_t startRun, Int_t endRun)
763{
764 AliMUONV2DStore* neighbours = new AliMUON2DMap(kTRUE);
765 Int_t ngenerated = makeNeighbourStore(*neighbours);
766 cout << "Ngenerated = " << ngenerated << endl;
767 if (ngenerated>0)
768 {
769 writeToCDB(cdbpath,"MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
770 }
771 delete neighbours;
772}
773
c3357e6d 774//_____________________________________________________________________________
775void writeHV(const char* cdbpath, Bool_t defaultValues,
776 Int_t startRun, Int_t endRun)
777{
778 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
779 /// if defaultValues=false, see makeHVStore) and
780 /// store them into CDB located at cdbpath, with a validity period
781 /// ranging from startRun to endRun
782
783 TMap* hvStore = new TMap;
784 Int_t ngenerated = makeHVStore(*hvStore,defaultValues);
785 cout << "Ngenerated = " << ngenerated << endl;
9ff4fb4b 786 if (ngenerated>0)
787 {
788 writeToCDB(cdbpath,"MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
789 }
c3357e6d 790 delete hvStore;
791}
792
5322694c 793//_____________________________________________________________________________
794void writePedestals(const char* cdbpath, Bool_t defaultValues,
795 Int_t startRun, Int_t endRun)
796{
c3357e6d 797 /// generate pedestal values (either 0 if defaultValues=true or random
798 /// if defaultValues=false, see makePedestalStore) and
799 /// store them into CDB located at cdbpath, with a validity period
800 /// ranging from startRun to endRun
801
5322694c 802 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
803 Int_t ngenerated = makePedestalStore(*pedestalStore,defaultValues);
804 cout << "Ngenerated = " << ngenerated << endl;
b3c7c475 805
5322694c 806 writeToCDB(cdbpath,"MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
c3357e6d 807 delete pedestalStore;
5322694c 808}
809
c1bbaf66 810
5322694c 811//_____________________________________________________________________________
812void writeGains(const char* cdbpath, Bool_t defaultValues,
813 Int_t startRun, Int_t endRun)
814{
c3357e6d 815 /// generate gain values (either 1 if defaultValues=true or random
c1bbaf66 816 /// if defaultValues=false, see makeGainStore) and
c3357e6d 817 /// store them into CDB located at cdbpath, with a validity period
818 /// ranging from startRun to endRun
819
5322694c 820 AliMUONV2DStore* gainStore = new AliMUON2DMap;
821 Int_t ngenerated = makeGainStore(*gainStore,defaultValues);
822 cout << "Ngenerated = " << ngenerated << endl;
8f7d7575 823
5322694c 824 writeToCDB(cdbpath,"MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
c3357e6d 825 delete gainStore;
5322694c 826}
827
c1bbaf66 828//_____________________________________________________________________________
829void writeCapacitances(const char* cdbpath, Bool_t defaultValues,
830 Int_t startRun, Int_t endRun)
831{
832 /// generate manu capacitance values (either 1 if defaultValues=true or random
833 /// if defaultValues=false, see makeCapacitanceStore) and
834 /// store them into CDB located at cdbpath, with a validity period
835 /// ranging from startRun to endRun
836
837 AliMUONV1DStore* capaStore = new AliMUON1DMap(16828);
838 Int_t ngenerated = makeCapacitanceStore(*capaStore,defaultValues);
839 cout << "Ngenerated = " << ngenerated << endl;
840
841 writeToCDB(cdbpath,"MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
842 delete capaStore;
843}
844
5322694c 845//_____________________________________________________________________________
c3357e6d 846Bool_t check1I(const AliMUONVCalibParam& calib, Int_t channel)
5322694c 847{
c3357e6d 848 ///
849
850 return ( calib.ValueAsInt(channel) == 0);
851}
852
853//_____________________________________________________________________________
854void validate1I(const AliMUONV2DStore& store)
855{
856 AliMUON2DStoreValidator validator;
857
858 TObjArray* a = validator.Validate(store,check1I);
859
860 if (a) a->Print();
861
862 TList lines;
863
864 validator.Report(lines);
865
866 lines.Print();
867}
868
869//_____________________________________________________________________________
870void validate2F(const AliMUONV2DStore& store)
871{
872 AliMUON2DStoreValidator validator;
873
9ff4fb4b 874 TObjArray* a = validator.Validate(store,AliMUONVCalibParam::InvalidFloatValue());
c3357e6d 875
876 if (a) a->Print();
877
878 TList lines;
879
880 validator.Report(lines);
881
882 lines.Print();
883}
884
885//_____________________________________________________________________________
886void dump(const TArrayI& a, const char* what)
887{
888 cout << what << " " << a.GetSize() << " manus" << endl;
889 for ( Int_t i = 0; i < a.GetSize(); ++i )
890 {
891 cout << Form(" %5d ",a[i]);
892 }
893 cout << endl;
894}
895
896//_____________________________________________________________________________
897void countManus()
898{
899 AliMpDEIterator it;
900
901 it.First();
902
903 Int_t b(0);
904 Int_t nb(0);
905
906 while (!it.IsDone())
907 {
908 Int_t detElemId = it.CurrentDEId();
909 AliMp::StationType stationType = AliMpDEManager::GetStationType(detElemId);
910 if ( stationType != AliMp::kStationTrigger )
911 {
912 const AliMpVSegmentation* seg0 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath0);
913 const AliMpVSegmentation* seg1 = AliMpSegmentation::Instance()->GetMpSegmentation(detElemId,AliMp::kCath1);
914 TArrayI a1;
915 TArrayI a0;
916 seg0->GetAllElectronicCardIDs(a0);
917 seg1->GetAllElectronicCardIDs(a1);
918
919 cout << Form("DE %5d B %4d NB %4d Total %5d",detElemId,
920 a0.GetSize(),a1.GetSize(),a0.GetSize()+a1.GetSize())
921 << endl;
922
923 b += a0.GetSize();
924 nb += a1.GetSize();
925
926 if ( detElemId == 500 )
927 {
928 dump(a0,"B");
929 dump(a1,"NB");
930 }
931 }
932 it.Next();
933 }
934
935 cout << Form("B %5d NB %5d Total %5d",b,nb,b+nb) << endl;
936}
937
938//_____________________________________________________________________________
939void count(const AliMUONV2DStore& store)
940{
941 AliMUONVDataIterator* it = store.Iterator();
942 AliMUONObjectPair* pair;
943 std::map<int,std::pair<int,int> > demap;
944
945 while ( ( pair = static_cast<AliMUONObjectPair*>(it->Next()) ) )
946 {
947 AliMpIntPair* ip = static_cast<AliMpIntPair*>(pair->First());
948
949 Int_t detElemId = ip->GetFirst();
950
951 Int_t manuId = ip->GetSecond();
952
953 const AliMpVSegmentation* seg =
954 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
955
956 if ( seg->PlaneType() == AliMp::kNonBendingPlane )
957 {
958 demap[detElemId].second++;
959 }
960 else
961 {
962 demap[detElemId].first++;
963 }
964 }
965
966 std::map<int,std::pair<int,int> >::const_iterator mit;
967
968 Int_t b(0);
969 Int_t nb(0);
970
971 for ( mit = demap.begin(); mit != demap.end(); ++mit )
972 {
973 cout << Form("DE %5d B %4d NB %4d Total %5d",mit->first,
974 mit->second.first,mit->second.second,
975 mit->second.first+mit->second.second) << endl;
976 b += mit->second.first;
977 nb += mit->second.second;
978 }
8f7d7575 979
c3357e6d 980 cout << Form("B %5d NB %5d Total %5d",b,nb,b+nb) << endl;
b3c7c475 981}
982
983