AliRoot Core  ee782a0 (ee782a0)
AliMUONCDB.cxx
Go to the documentation of this file.
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 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
33 
34 #include "AliMUONCDB.h"
35 
36 #include "AliMUON1DArray.h"
37 #include "AliMUON1DMap.h"
38 #include "AliMUON2DMap.h"
40 #include "AliMUONCalibParamND.h"
41 #include "AliMUONCalibParamNF.h"
42 #include "AliMUONCalibParamNI.h"
43 #include "AliMUONCalibrationData.h"
44 #include "AliMUONConstants.h"
46 #include "AliMUONLogger.h"
47 #include "AliMUONPadStatusMaker.h"
49 #include "AliMUONRecoParam.h"
51 #include "AliMUONRejectList.h"
52 #include "AliMUONTrackerData.h"
53 #include "AliMUONTrackerIO.h"
55 #include "AliMUONTriggerLut.h"
56 #include "AliMUONVCalibParam.h"
57 #include "AliMUONVCalibParam.h"
58 #include "AliMUONVStore.h"
59 
60 #include "AliMpCDB.h"
61 #include "AliMpConstants.h"
62 #include "AliMpDEStore.h"
63 #include "AliMpDDLStore.h"
64 #include "AliMpManuStore.h"
65 #include "AliMpDEManager.h"
66 #include "AliMpDetElement.h"
67 #include "AliMpFiles.h"
68 #include "AliMpDCSNamer.h"
69 #include "AliMpManuIterator.h"
70 #include "AliMpSegmentation.h"
71 #include "AliMpStationType.h"
72 #include "AliMpVSegmentation.h"
73 
74 #include "AliCodeTimer.h"
75 #include "AliCDBEntry.h"
76 #include "AliCDBManager.h"
77 #include "AliGRPManager.h"
78 #include "AliDCSValue.h"
79 #include "AliLog.h"
80 #include "AliMpBusPatch.h"
81 #include "AliMergeableCollection.h"
82 
83 #include <Riostream.h>
84 #include <TArrayI.h>
85 #include <TClass.h>
86 #include "TF1.h"
87 #include <TFile.h>
88 #include <TH1F.h>
89 #include <TList.h>
90 #include <TMap.h>
91 #include <TObjString.h>
92 #include <TROOT.h>
93 #include <TRandom.h>
94 #include <TStopwatch.h>
95 #include <TSystem.h>
96 #include <TMath.h>
97 #include <TGeoGlobalMagField.h>
98 #include <TClonesArray.h>
99 #include <fstream>
100 #include <sstream>
101 #include <set>
102 #include <cassert>
103 
104 using std::endl;
105 using std::cout;
106 using std::cerr;
107 using std::ostringstream;
108 using std::ifstream;
109 
110 namespace
111 {
112  //_____________________________________________________________________________
113 AliMUONVStore* Create2DMap()
114 {
115  return new AliMUON2DMap(true);
116 }
117 
118  //_____________________________________________________________________________
119 void getBoundaries(const AliMUONVStore& store, Int_t dim,
120  Float_t* xmin, Float_t* xmax)
121 {
125 
126  for ( Int_t i = 0; i < dim; ++i )
127  {
128  xmin[i]=1E30;
129  xmax[i]=-1E30;
130  }
131 
132  TIter next(store.CreateIterator());
133  AliMUONVCalibParam* value;
134 
135  while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
136  {
137  Int_t detElemId = value->ID0();
138  Int_t manuId = value->ID1();
139 
140  const AliMpVSegmentation* seg =
142 
143  if (!seg) continue;
144 
145  for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
146  {
147  AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
148  if (!pad.IsValid()) continue;
149 
150  for ( Int_t i = 0; i < dim; ++i )
151  {
152  Float_t x0 = value->ValueAsFloat(manuChannel,i);
153 
154  xmin[i] = TMath::Min(xmin[i],x0);
155  xmax[i] = TMath::Max(xmax[i],x0);
156  }
157  }
158  }
159 
160  for ( Int_t i = 0; i < dim; ++i )
161  {
162  if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
163  {
164  xmin[i] -= 1;
165  xmax[i] += 1;
166  }
167  }
168 }
169 
170 //_____________________________________________________________________________
171 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
172 {
173  Double_t x(-1);
174  if ( mustBePositive )
175  {
176  while ( x < 0 )
177  {
178  x = gRandom->Gaus(mean,sigma);
179  }
180  }
181  else
182  {
183  x = gRandom->Gaus(mean,sigma);
184  }
185  return x;
186 }
187 
188 }
189 
190 namespace AliMUONCDB {
191 
192 //_____________________________________________________________________________
193 Bool_t CheckOCDB(Bool_t pathOnly)
194 {
196 
198 
199  // first OCDB path
200  if (!man->IsDefaultStorageSet()) {
201  AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
202  return kFALSE;
203  }
204 
205  // then run number if required
206  if (pathOnly) return kTRUE;
207  if (man->GetRun() < 0) {
208  AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
209  return kFALSE;
210  }
211 
212  return kTRUE;
213 
214 }
215 
216 //______________________________________________________________________________
217 void CheckHV(Int_t runNumber, Int_t verbose)
218 {
220 
221  TList messages;
222  messages.SetOwner(kTRUE);
223 
224  Bool_t patched(kTRUE);
225 
226  if (!AliCDBManager::Instance()->IsDefaultStorageSet()) {
228  }
229 
230  AliCDBManager::Instance()->SetRun(runNumber);
231 
232  if (!CheckMapping()) {
233  LoadMapping();
234  }
235 
236  AliMUONCalibrationData::CreateHV(runNumber, 0, patched, &messages);
237 
238  AliMUONCalibrationData cd(runNumber, true);
239 
240  AliMUONPadStatusMaker statusMaker(cd);
241 
243 
244  if (!rp) {
245  AliErrorGeneral("CheckHV", "Could not get RecoParam !!!");
246  return;
247  }
248 
249  statusMaker.SetLimits(*rp);
250 
251  TIter next(&messages);
252  TObjString *s;
253  AliMpDCSNamer hvNamer("TRACKER");
254  AliMUONLogger log;
255  Double_t meanHVValue(0.0);
256  Double_t nofHVValues(0.0);
257 
258  while ((s = static_cast<TObjString *>(next()))) {
259  TObjArray *a = s->String().Tokenize(":");
260 
261  TString name(static_cast<TObjString *>(a->At(0))->String());
262 
263  TObjArray *b = name.Tokenize(" ");
264 
265  name = static_cast<TObjString *>(b->At(0))->String();
266 
267  delete a;
268  delete b;
269 
270  if (name.Contains("sw") || name.Contains("SUMMARY")) { continue; }
271 
272  Int_t index = hvNamer.DCSIndexFromDCSAlias(name.Data());
273 
274  Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
275 
277 
278  if (!de) {
279  AliErrorGeneral("CheckHV", Form("Could not get detElemId from dcsAlias %s", name.Data()));
280  continue;
281  }
282 
283  Int_t manuId;
284 
285  if (index >= 0) {
286  const AliMpArrayI *array = de->ManusForHV(index);
287  manuId = array->GetValue(0);
288  } else {
290  manuId = bp->GetManuId(0);
291  }
292 
293  Int_t status = statusMaker.HVStatus(detElemId, manuId);
294 
295  log.Log(AliMUONPadStatusMaker::AsString(status).Data());
296 
297  meanHVValue += MeanHVValueForDCSAlias((*cd.HV()), name.Data());
298 
299  nofHVValues += 1.0;
300 
301  s->String() += Form(" (DE %4d) ", detElemId);
302  s->String() += AliMUONPadStatusMaker::AsString(status).Data();
303  }
304 
305  TIter nextMessage(&messages);
306  TObjString *msg;
307 
308  while ((msg = static_cast<TObjString *>(nextMessage()))) {
309  if (verbose > 0 || msg->String().Contains("SUMMARY")) {
310  AliInfoGeneral("CheckHV", Form("RUN %09d HVchannel %s", runNumber, msg->String().Data()));
311  }
312  }
313 
314  TString lmsg;
315  Int_t occurance;
316  TString totalLog;
317 
318  while (log.Next(lmsg, occurance)) {
319  totalLog += Form("%s(%d)", lmsg.Data(), occurance);
320  totalLog += " | ";
321  }
322 
323  AliInfoGeneral("CheckHV", Form("RUN %09d %s", runNumber, totalLog.Data()));
324 
325  // one last loop to get the list of problematic HV channels
326  nextMessage.Reset();
327 
328  while ((msg = static_cast<TObjString *>(nextMessage()))) {
329  if (msg->String().Contains("HV ")) {
330  AliInfoGeneral("CheckHV", Form(" Problem at %s", msg->String().Data()));
331  }
332  }
333 
334  if (nofHVValues) {
335  meanHVValue /= nofHVValues;
336  AliInfoGeneral("CheckHV", Form("Mean HV for run %09d was %7.2f", runNumber, meanHVValue));
337  }
338 
340 }
341 
342 //______________________________________________________________________________
343 void CheckHV_ALIROOT_6402(const char *runlist, Bool_t verbose)
344 {
348 
349  std::vector<int> runnumbers;
350 
351  ReadIntegers(runlist, runnumbers);
352 
353  std::vector<int> affectedRuns;
354 
355  for (unsigned int i = 0; i < runnumbers.size(); ++i) {
356  int runNumber = runnumbers[i];
357 
358  Bool_t affected = CheckHV_ALIROOT_6402(runNumber, verbose);
359 
360  std::cout << Form("RUN %09d is potentially affected by bug ALIROOT-6402 : %s", runNumber, affected ? "YES" : "NO")
361  << std::endl;
362 
363  if (affected) {
364  affectedRuns.push_back(runNumber);
365  }
366  }
367 
368  std::cout << Form("%4lu runs affected in the list of %4lu runs : ", affectedRuns.size(), runnumbers.size());
369  for (unsigned int i = 0; i < affectedRuns.size(); ++i) {
370  std::cout << affectedRuns[i] << ",";
371  }
372  std::cout << std::endl;
373 }
374 
375 //______________________________________________________________________________
376 Bool_t CheckHV_ALIROOT_6402(Int_t runNumber, Bool_t verbose)
377 {
384 
386 
387  TList messages;
388  messages.SetOwner(kTRUE);
389 
390  if (!AliCDBManager::Instance()->IsDefaultStorageSet()) {
392  }
393 
394  AliCDBManager::Instance()->SetRun(runNumber);
395 
396  LoadMapping();
397 
398  TMap *hvMap = dynamic_cast<TMap *>(AliMUONCalibrationData::CreateObject(runNumber, "MUON/Calib/HV"));
399 
400  PatchHV(*hvMap, &messages, kTRUE);
401 
402  if (verbose) {
403  TIter next(&messages);
404  TObjString *msg;
405  while ((msg = static_cast<TObjString *>(next()))) {
406  std::cout << Form("RUN %09d %s", runNumber, msg->String().Data()) << std::endl;
407  }
408  }
409 
410  TIter next(hvMap);
411  TObjString *hvChannelName;
412 
413  Bool_t affected(kFALSE);
414 
415  while ((hvChannelName = static_cast<TObjString *>(next()))) {
416  TString name(hvChannelName->String());
417  if (IsSt1DCSAliasRemapped(name)) {
418  Float_t hvvalue = MeanHVValueForDCSAlias(*hvMap, name.Data());
419  if (hvvalue < 1590.0) {
420  affected = kTRUE;
421  if (verbose) {
422  std::cout << Form("RUN %09d %40s HV VALUE %7.2f", runNumber, name.Data(), hvvalue) << std::endl;
423  }
424  }
425  }
426  }
427 
429 
430  return affected;
431 }
432 
433 //_____________________________________________________________________________
434 Bool_t CheckMapping(Bool_t segmentationOnly)
435 {
437 
438  // first the segmentation
439  if (!AliMpSegmentation::Instance(false)) {
440  AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
441  return kFALSE;
442  }
443 
444  // then the others if required
445  if (segmentationOnly) return kTRUE;
446  if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
447  AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
448  return kFALSE;
449  }
450 
451  return kTRUE;
452 
453 }
454 
455 //______________________________________________________________________________
456 Bool_t IsSt1DCSAliasRemapped(const TString &name)
457 {
458  Bool_t isit(kFALSE);
459 
460  if (name.Contains("Chamber00Left")) {
461  if (name.Contains("Quad1Sect0")) isit = kTRUE;
462 
463  if (name.Contains("Quad1Sect1")) isit = kTRUE;
464  if (name.Contains("Quad1Sect2")) isit = kTRUE;
465 
466  if (name.Contains("Quad2Sect2")) isit = kTRUE;
467  if (name.Contains("Quad2Sect1")) isit = kTRUE;
468  if (name.Contains("Quad2Sect0")) isit = kTRUE;
469  } else if (name.Contains("Chamber01Left")) {
470  if (name.Contains("Quad2Sect2")) isit = kTRUE;
471  if (name.Contains("Quad2Sect0")) isit = kTRUE;
472  }
473 
474  return isit;
475 }
476 
477 //_____________________________________________________________________________
478 Bool_t LoadField()
479 {
482 
483  AliInfoGeneral("AliMUONCDB", "Loading field map from GRP...");
484 
485  if (!CheckOCDB()) return kFALSE;
486 
487  AliGRPManager grpMan;
488 
489  // make sure the old field is deleted even if it is locked
490  if (TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
491 
492  if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
493  AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
494  return kFALSE;
495  }
496 
497  return kTRUE;
498 
499 }
500 
501 //_____________________________________________________________________________
502 Bool_t LoadMapping(Bool_t segmentationOnly)
503 {
506 
507  AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
508 
509  if (!CheckOCDB()) return kFALSE;
510 
511  // in case it has already been set
513 
514  if (segmentationOnly) {
515 
516  if (!AliMpCDB::LoadMpSegmentation(kTRUE)) {
517  AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
518  return kFALSE;
519  }
520 
521  } else {
522 
523  if (!AliMpCDB::LoadAll(kTRUE)) {
524  AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
525  return kFALSE;
526  }
527 
528  }
529 
530  return kTRUE;
531 
532 }
533 
534 //_____________________________________________________________________________
536 {
539 
540  AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
541 
542  if (!CheckOCDB()) return 0x0;
543 
544  AliMUONRecoParam *recoParam = 0x0;
545  AliCDBEntry *entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
546 
547  if (entry) {
548 
549  // load recoParam according OCDB content (single or array)
550  if (!(recoParam = dynamic_cast<AliMUONRecoParam *>(entry->GetObject()))) {
551 
552  TObjArray *recoParamArray = static_cast<TObjArray *>(entry->GetObject());
553 // recoParamArray->SetOwner(kTRUE); // FIXME: this should be done, but is causing a problem at the end of the reco... investigate why...
554 
555  for (Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
556  recoParam = static_cast<AliMUONRecoParam *>(recoParamArray->UncheckedAt(i));
557  if (recoParam->IsDefault()) break;
558  recoParam = 0x0;
559  }
560 
561  }
562 
563  }
564 
565  if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
566 
567  return recoParam;
568 
569 }
570 
571 //_____________________________________________________________________________
572 TClonesArray *LoadAlignmentData()
573 {
575 
576  AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
577 
578  if (!CheckOCDB()) return 0x0;
579 
580  TClonesArray *alignmentArray = 0x0;
581  AliCDBEntry *entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
582 
583  if (entry) {
584  // load alignement array
585  alignmentArray = dynamic_cast<TClonesArray *>(entry->GetObject());
586  }
587 
588  if (!alignmentArray) {
589  AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
590  }
591 
592  return alignmentArray;
593 }
594 
595 //_____________________________________________________________________________
598  const char *opt)
599 {
606 
607  TString sopt(opt);
608  sopt.ToUpper();
609 
610  if (!sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT")) {
611  AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are", opt));
612  return 0x0;
613  }
614 
615  AliMUONVStore *d = static_cast<AliMUONVStore *>(store1.Clone());
616 
617  TIter next(d->CreateIterator());
618 
619  AliMUONVCalibParam *param;
620 
621  while ((param = dynamic_cast<AliMUONVCalibParam *>(next()))) {
622  Int_t detElemId = param->ID0();
623  Int_t manuId = param->ID1();
624 
625  AliMUONVCalibParam *param2 = dynamic_cast<AliMUONVCalibParam *>(store2.FindObject(detElemId, manuId));
626  //FIXME: this might happen. Handle it.
627  if (!param2) {
628  cerr << "param2 is null : FIXME : this might happen !" << endl;
629  delete d;
630  return 0;
631  }
632 
633  for (Int_t i = 0; i < param->Size(); ++i) {
634  for (Int_t j = 0; j < param->Dimension(); ++j) {
635  Float_t value(0);
636  if (sopt.Contains("ABS")) {
637  value = param->ValueAsFloat(i, j) - param2->ValueAsFloat(i, j);
638  } else if (sopt.Contains("REL") || sopt.Contains("PERCENT")) {
639  if (param->ValueAsFloat(i, j)) {
640  value = (param->ValueAsFloat(i, j) - param2->ValueAsFloat(i, j)) / param->ValueAsFloat(i, j);
641  } else {
642  continue;
643  }
644  if (sopt.Contains("PERCENT")) value *= 100.0;
645  }
646  param->SetValueAsFloat(i, j, value);
647  }
648  }
649  }
650  return d;
651 }
652 
653 //_____________________________________________________________________________
654 TH1 **
655 Plot(const AliMUONVStore &store, const char *name, Int_t nbins)
656 {
660 
661  if (!CheckMapping(kTRUE)) return 0x0;
662 
663  TIter next(store.CreateIterator());
664  AliMUONVCalibParam *param;
665  Int_t n(0);
666  const Int_t kNStations = AliMpConstants::NofTrackingChambers() / 2;
667  Int_t *nPerStation = new Int_t[kNStations];
668  TH1 **h(0x0);
669 
670  for (Int_t i = 0; i < kNStations; ++i) nPerStation[i] = 0;
671 
672  while ((param = static_cast<AliMUONVCalibParam *>(next()))) {
673  if (!h) {
674  Int_t dim = param->Dimension();
675  h = new TH1 *[dim];
676  Float_t *xmin = new Float_t[dim];
677  Float_t *xmax = new Float_t[dim];
678  getBoundaries(store, dim, xmin, xmax);
679 
680  for (Int_t i = 0; i < dim; ++i) {
681  h[i] = new TH1F(Form("%s_%d", name, i), Form("%s_%d", name, i),
682  nbins, xmin[i], xmax[i]);
683  AliInfoGeneral("AliMUONCDB", Form("Created histogram %s", h[i]->GetName()));
684  }
685  delete[] xmin;
686  delete[] xmax;
687  }
688 
689  Int_t detElemId = param->ID0();
690  Int_t manuId = param->ID1();
691  Int_t station = AliMpDEManager::GetChamberId(detElemId) / 2;
692 
693  const AliMpVSegmentation *seg =
695 
696  if (!seg) continue;
697 
698  for (Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel) {
699  AliMpPad pad = seg->PadByLocation(manuId, manuChannel, kFALSE);
700  if (!pad.IsValid()) continue;
701 
702  ++n;
703  ++nPerStation[station];
704 
705  for (Int_t dim = 0; dim < param->Dimension(); ++dim) {
706  h[dim]->Fill(param->ValueAsFloat(manuChannel, dim));
707  }
708  }
709  }
710 
711  for (Int_t i = 0; i < kNStations; ++i) {
712  AliInfoGeneral("AliMUONCDB", Form("Station %d %d ", (i + 1), nPerStation[i]));
713  }
714 
715  AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d", n));
716 
717  delete[] nPerStation;
718 
719  return h;
720 }
721 
722 //_____________________________________________________________________________
723 Int_t MakeBusPatchEvolution(AliMergeableCollection &hc, int timeResolution)
724 {
727 
728  if (!CheckMapping()) return 0;
729 
730  TDatime origin;
731 
732  double xmin = 0;
733  double xmax = xmin + 3600;
734 
735  int nbins = TMath::Nint((xmax - xmin) / timeResolution);
736 
737  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
738  AliMpBusPatch *bp;
739 
740  Int_t total(0);
741 
742  TF1 f1("f1", "pol0", xmin, xmax);
743 
744  while ((bp = static_cast<AliMpBusPatch *>(next()))) {
745  ++total;
746  TH1 *h = new TH1F(Form("BP%04d", bp->GetId()), Form("Number of hits in %d s bins", timeResolution), nbins, xmin,
747  xmax);
748  f1.SetParameter(0, bp->GetId());
749  h->FillRandom("f1", 10000);
750  h->GetXaxis()->SetTimeDisplay(1);
751  h->GetXaxis()->SetTimeFormat("%d/%m/%y %H:%M");
752  h->GetXaxis()->SetTimeOffset(origin.Convert());
753  hc.Adopt(Form("/BUSPATCH/HITS/%ds", timeResolution), h);
754  }
755 
756  // number of events needed for normalization
757 
758  TH1 *h = new TH1F(Form("Nevents%ds", timeResolution), Form("Number of events %d s bins", timeResolution), nbins, xmin,
759  xmax);
760 
761  f1.SetParameter(0, 4200);
762 
763  h->FillRandom("f1", 10000);
764 
765  h->GetXaxis()->SetTimeDisplay(1);
766  h->GetXaxis()->SetTimeFormat("%d/%m/%y %H:%M");
767  h->GetXaxis()->SetTimeOffset(origin.Convert());
768 
769  hc.Adopt("", h);
770 
771  return (total == 888);
772 }
773 
774 //_____________________________________________________________________________
775 Int_t
776 MakeHVStore(TMap &aliasMap, Bool_t defaultValues)
777 {
779 
780  if (!CheckMapping()) return 0;
781 
782  AliMpDCSNamer hvNamer("TRACKER");
783 
784  TObjArray *aliases = hvNamer.GenerateAliases();
785 
786  Int_t nSwitch(0);
787  Int_t nChannels(0);
788 
789  for (Int_t i = 0; i < aliases->GetEntries(); ++i) {
790  TObjString *alias = static_cast<TObjString *>(aliases->At(i));
791  TString &aliasName = alias->String();
792  if (aliasName.Contains("sw")) {
793  // HV Switch (St345 only)
794  TObjArray *valueSet = new TObjArray;
795  valueSet->SetOwner(kTRUE);
796 
797  Bool_t value = kTRUE;
798 
799  if (!defaultValues) {
800  Float_t r = gRandom->Uniform();
801  if (r < 0.007) value = kFALSE;
802  }
803 
804  for (UInt_t timeStamp = 0; timeStamp < 60 * 3; timeStamp += 60) {
805  AliDCSValue *dcsValue = new AliDCSValue(value, timeStamp);
806  valueSet->Add(dcsValue);
807  }
808  aliasMap.Add(new TObjString(*alias), valueSet);
809  ++nSwitch;
810  } else if (aliasName.Contains("Mon")) {
811  TObjArray *valueSet = new TObjArray;
812  valueSet->SetOwner(kTRUE);
813  for (UInt_t timeStamp = 0; timeStamp < 60 * 15; timeStamp += 120) {
814  Float_t value = 1500;
815  if (!defaultValues) value = GetRandom(1750, 62.5, true);
816  AliDCSValue *dcsValue = new AliDCSValue(value, timeStamp);
817  valueSet->Add(dcsValue);
818  }
819  aliasMap.Add(new TObjString(*alias), valueSet);
820  ++nChannels;
821  }
822  }
823 
824  delete aliases;
825 
826  AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches", nChannels, nSwitch));
827 
828  return nChannels + nSwitch;
829 }
830 
831 //_____________________________________________________________________________
832 Int_t
833 MakeLVStore(TMap &aliasMap, Bool_t defaultValues, time_t refTime)
834 {
836 
837  if (!CheckMapping()) return 0;
838 
839  AliMpDCSNamer hvNamer("TRACKER");
840 
841  TObjArray *aliases = hvNamer.GenerateAliases("Group");
842 
843  Int_t npos(0), nneg(0), ndig(0);
844 
845  for (Int_t i = 0; i < aliases->GetEntries(); ++i) {
846  TObjString *alias = static_cast<TObjString *>(aliases->At(i));
847  TString &aliasName = alias->String();
848  Float_t refValue = 0;
849 
850  if (aliasName.Contains("anp")) {
851  refValue = 2.5;
852  ++npos;
853  } else if (aliasName.Contains("dig")) {
854  refValue = 3.3;
855  ++ndig;
856  } else if (aliasName.Contains("ann")) {
857  refValue = 2.5; // that's not a bug : even though we're describing
858  // a negative value, the DCS data point is positive.
859  ++nneg;
860  } else {
861  AliErrorGeneral("AliMUONCDB", "Should not be here ! CHECK ME !");
862  continue;
863  }
864 
865  TObjArray *valueSet = new TObjArray;
866  valueSet->SetOwner(kTRUE);
867 
868  Float_t value = refValue;
869 
870  for (UInt_t timeStamp = 0; timeStamp < 60 * 15; timeStamp += 120) {
871  if (!defaultValues) value = GetRandom(refValue, 0.05, false);
872  AliDCSValue *dcsValue = new AliDCSValue(value, refTime + timeStamp);
873  valueSet->Add(dcsValue);
874  }
875  aliasMap.Add(new TObjString(*alias), valueSet);
876  }
877 
878  Bool_t ok = (npos == nneg) && (npos == ndig) && (ndig == nneg);
879 
880  if (!ok) {
881  AliErrorGeneral("AliMUONCDB", Form("Wrong number of LV channels : npos=%d nneg=%d ndig=%d", npos, nneg, ndig));
882  } else {
883  AliInfoGeneral("AliMUONCDB", Form("%d LV groups - %d aliases", npos, aliasMap.GetEntries()));
884  }
885 
886  delete aliases;
887 
888  return npos;
889 }
890 
891 //_____________________________________________________________________________
892 void AddDCSValue(TMap &aliasMap, Int_t imeas, const char *smt, const char *sInOut, Int_t rpc, Float_t value)
893 {
894  TString sMeasure = (imeas == AliMpDCSNamer::kDCSHV) ? "HV.vEff" : "HV.actual.iMon";
895  TString alias = Form("MTR_%s_%s_RPC%i_%s", sInOut, smt, rpc, sMeasure.Data());
896  TObjArray *valueSet = new TObjArray;
897  valueSet->SetOwner(kTRUE);
898 
899  for (UInt_t timeStamp = 0; timeStamp < 60 * 2; timeStamp += 60) {
900  AliDCSValue *dcsValue = new AliDCSValue(value, timeStamp);
901  valueSet->Add(dcsValue);
902  }
903 
904  aliasMap.Add(new TObjString(alias), valueSet);
905 }
906 
907 //_____________________________________________________________________________
908 Int_t
909 MakeTriggerDCSStore(TMap &aliasMap)
910 {
912 
913 // if (!CheckMapping()) return 0;
914 
915  Int_t nChannels[2] = {0, 0};
916 
917  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 1, 10400.);
918  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 2, 10351.);
919  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 3, 10300.);
920  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 4, 10450.);
921  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 5, 10250.);
922  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 6, 10100.);
923  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 7, 10250.);
924  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 8, 10350.);
925  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "INSIDE", 9, 10350.);
926 
927  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 1, 10300.);
928  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 2, 10350.);
929  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 3, 10150.);
930  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 4, 10350.);
931  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 5, 10150.);
932  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 6, 10350.);
933  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 7, 10150.);
934  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 8, 10150.);
935  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT11", "OUTSIDE", 9, 10250.);
936 
937  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 1, 10350.);
938  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 2, 10350.);
939  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 3, 10250.);
940  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 4, 10250.);
941  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 5, 10150.);
942  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 6, 10350.);
943  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 7, 10400.);
944  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 8, 10200.);
945  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "INSIDE", 9, 10350.);
946 
947  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 1, 10400.);
948  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 2, 10250.);
949  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 3, 10250.);
950  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 4, 10300.);
951  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 5, 10300.);
952  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 6, 10200.);
953  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 7, 10100.);
954  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 8, 10400.);
955  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT12", "OUTSIDE", 9, 10400.);
956 
957  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 1, 10200.);
958  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 2, 10250.);
959  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 3, 10250.);
960  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 4, 10150.);
961  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 5, 10100.);
962  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 6, 10100.);
963  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 7, 10200.);
964  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 8, 10150.);
965  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "INSIDE", 9, 10250.);
966 
967  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 1, 10200.);
968  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 2, 10350.);
969  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 3, 10200.);
970  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 4, 10100.);
971  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 5, 10250.);
972  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 6, 10101.);
973  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 7, 10200.);
974  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 8, 10300.);
975  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT21", "OUTSIDE", 9, 10250.);
976 
977  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 1, 10300.);
978  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 2, 10300.);
979  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 3, 9624.); // FEERIC
980  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 4, 10150.);
981  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 5, 10250.);
982  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 6, 10150.);
983  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 7, 10050.);
984  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 8, 10050.);
985  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "INSIDE", 9, 10150.);
986 
987  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 1, 10225.);
988  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 2, 10250.);
989  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 3, 10150.);
990  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 4, 10100.);
991  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 5, 10200.);
992  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 6, 10200.);
993  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 7, 10250.);
994  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 8, 10225.);
995  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSHV, "MT22", "OUTSIDE", 9, 10250.);
996 
997  nChannels[0] = 72;
998 
999  TString chName[4] = {"MT11", "MT12", "MT21", "MT22"};
1000 
1001  for (Int_t ich = 0; ich < 4; ich++) {
1002  for (Int_t iside = 0; iside < 2; iside++) {
1003  TString sInOut = (iside == 0) ? "INSIDE" : "OUTSIDE";
1004  for (Int_t irpc = 1; irpc <= 9; irpc++) {
1005  AddDCSValue(aliasMap, AliMpDCSNamer::kDCSI, chName[ich].Data(), sInOut.Data(), irpc, 2.);
1006  ++nChannels[1];
1007  }
1008  }
1009  }
1010 
1011  AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i", nChannels[0], nChannels[1]));
1012 
1013  return nChannels[0] + nChannels[1];
1014 }
1015 
1016 //_____________________________________________________________________________
1017 Int_t
1018 MakePedestalStore(AliMUONVStore &pedestalStore, Bool_t defaultValues)
1019 {
1023 
1024  AliCodeTimerAutoGeneral("", 0);
1025 
1026  if (!CheckMapping()) return 0;
1027 
1028  Int_t nchannels(0);
1029  Int_t nmanus(0);
1030 
1031  const Int_t kChannels(AliMpConstants::ManuNofChannels());
1032 
1033  // bending
1034  const Float_t kPedestalMeanMeanB(200.);
1035  const Float_t kPedestalMeanSigmaB(10.);
1036  const Float_t kPedestalSigmaMeanB(1.);
1037  const Float_t kPedestalSigmaSigmaB(0.2);
1038 
1039  // non bending
1040  const Float_t kPedestalMeanMeanNB(200.);
1041  const Float_t kPedestalMeanSigmaNB(10.);
1042  const Float_t kPedestalSigmaMeanNB(1.);
1043  const Float_t kPedestalSigmaSigmaNB(0.2);
1044 
1045  const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
1046 
1047  Int_t detElemId;
1048  Int_t manuId;
1049 
1050  AliMpManuIterator it;
1051 
1052  while (it.Next(detElemId, manuId)) {
1053  // skip a given fraction of manus
1054  if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
1055 
1056  ++nmanus;
1057 
1058  AliMUONVCalibParam *ped =
1059  new AliMUONCalibParamNF(2, kChannels, detElemId, manuId, AliMUONVCalibParam::InvalidFloatValue());
1060 
1062 
1063  for (Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel) {
1064  if (!de->IsConnectedChannel(manuId, manuChannel)) continue;
1065 
1066  ++nchannels;
1067 
1068  Float_t meanPedestal;
1069  Float_t sigmaPedestal;
1070 
1071  if (defaultValues) {
1072  meanPedestal = 0.0;
1073  sigmaPedestal = 1.0;
1074  } else {
1075  Bool_t positive(kTRUE);
1076  meanPedestal = 0.0;
1077 
1078  if (manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane)) { // manu in non bending plane
1079 
1080  while (meanPedestal == 0.0) // avoid strict zero
1081  {
1082  meanPedestal = GetRandom(kPedestalMeanMeanNB, kPedestalMeanSigmaNB, positive);
1083  }
1084  sigmaPedestal = GetRandom(kPedestalSigmaMeanNB, kPedestalSigmaSigmaNB, positive);
1085 
1086  } else { // manu in bending plane
1087 
1088  while (meanPedestal == 0.0) // avoid strict zero
1089  {
1090  meanPedestal = GetRandom(kPedestalMeanMeanB, kPedestalMeanSigmaB, positive);
1091  }
1092  sigmaPedestal = GetRandom(kPedestalSigmaMeanB, kPedestalSigmaSigmaB, positive);
1093 
1094  }
1095 
1096  }
1097 
1098  ped->SetValueAsFloat(manuChannel, 0, meanPedestal);
1099  ped->SetValueAsFloat(manuChannel, 1, sigmaPedestal);
1100 
1101  }
1102  Bool_t ok = pedestalStore.Add(ped);
1103  if (!ok) {
1104  AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d", detElemId, manuId));
1105  }
1106  }
1107 
1108  AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.", nmanus, nchannels));
1109  return nchannels;
1110 }
1111 
1112 //_____________________________________________________________________________
1114 MakeRejectListStore(Bool_t defaultValues)
1115 {
1117 
1118  AliCodeTimerAutoGeneral("", 0);
1119 
1121 
1122  if (!defaultValues) {
1125  return rl;
1126  }
1127 
1128  return rl;
1129 }
1130 
1131 //_____________________________________________________________________________
1132 Int_t
1133 MakeOccupancyMapStore(AliMUONVStore &occupancyMapStore, Bool_t defaultValues)
1134 {
1136 
1137  AliCodeTimerAutoGeneral("", 0);
1138 
1139  if (!CheckMapping()) return 0;
1140 
1141  Int_t nmanus(0);
1142 
1143  Int_t detElemId;
1144  Int_t manuId;
1145 
1146  AliMpManuIterator it;
1147 
1148  Int_t nevents(1000);
1149 
1150  while (it.Next(detElemId, manuId)) {
1151  ++nmanus;
1152 
1153  AliMUONVCalibParam *occupancy = new AliMUONCalibParamND(5, 1, detElemId, manuId, 0);
1154 
1155  Double_t occ = 0.0;
1156 
1158 
1159  Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
1160 
1161  if (!defaultValues) occ = gRandom->Rndm(1);
1162 
1163  Double_t sumn = occ * nevents;
1164 
1165  occupancy->SetValueAsFloat(0, 0, sumn);
1166  occupancy->SetValueAsFloat(0, 1, sumn);
1167  occupancy->SetValueAsFloat(0, 2, sumn);
1168  occupancy->SetValueAsInt(0, 3, numberOfChannelsInManu);
1169  occupancy->SetValueAsInt(0, 4, nevents);
1170 
1171  Bool_t ok = occupancyMapStore.Add(occupancy);
1172  if (!ok) {
1173  AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d", detElemId, manuId));
1174  }
1175  }
1176 
1177  return nmanus;
1178 }
1179 
1180 //_____________________________________________________________________________
1181 Int_t
1183 {
1185 
1186  AliCodeTimerAutoGeneral("", 0);
1187 
1188  Int_t ngenerated(0);
1189  // Generate fake mask values for all localboards and put that into
1190  // one single container (localBoardMasks)
1191  for (Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i) {
1192  AliMUONVCalibParam *localBoard = new AliMUONCalibParamNI(1, 8, i, 0, 0);
1193  for (Int_t x = 0; x < 2; ++x) {
1194  for (Int_t y = 0; y < 4; ++y) {
1195  Int_t index = x * 4 + y;
1196  localBoard->SetValueAsInt(index, 0, 0xFFFF);
1197  ++ngenerated;
1198  }
1199  }
1200  localBoardMasks.Add(localBoard);
1201  }
1202  return ngenerated;
1203 }
1204 
1205 //_____________________________________________________________________________
1206 Int_t
1208 {
1210 
1211  AliCodeTimerAutoGeneral("", 0);
1212 
1214  AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
1215  return 0;
1216  }
1217 
1218  return rtm.GetNofTriggerCrates();
1219 }
1220 
1221 
1222 //_____________________________________________________________________________
1223 Int_t
1225 {
1227 
1228  AliCodeTimerAutoGeneral("", 0);
1229 
1231 }
1232 
1233 
1234 //_____________________________________________________________________________
1236 MakeTriggerLUT(const char *file)
1237 {
1239 
1240  AliCodeTimerAutoGeneral("", 0);
1241 
1243  lut->ReadFromFile(file);
1244  return lut;
1245 }
1246 
1247 //_____________________________________________________________________________
1249 MakeTriggerEfficiency(const char *file)
1250 {
1252 
1253  AliCodeTimerAutoGeneral("", 0);
1254 
1255  return new AliMUONTriggerEfficiencyCells(file);
1256 }
1257 
1258 //______________________________________________________________________________
1259 void PatchHV(TMap &hvMap, TList *messages, Bool_t onlySt1remapped)
1260 {
1261  TIter next(&hvMap);
1262  TObjString *hvChannelName;
1263 
1264  while ((hvChannelName = static_cast<TObjString *>(next()))) {
1265  TString name(hvChannelName->String());
1266 
1267  if (name.Contains("sw")) continue; // skip switches
1268 
1269  if (name.Contains("iMon")) continue; // skip HV currents
1270 
1271  if (onlySt1remapped) {
1272  if (!IsSt1DCSAliasRemapped(name)) {
1273  continue;
1274  }
1275  }
1276 
1277  TPair *hvPair = static_cast<TPair *>(hvMap.FindObject(name.Data()));
1278  TObjArray *values = static_cast<TObjArray *>(hvPair->Value());
1279  if (!values) {
1280  AliErrorGeneral("PatchHV", Form("Could not get values for alias %s", name.Data()));
1281  } else {
1282  TString msg;
1283 
1284  Bool_t ok = AliMUONCalibrationData::PatchHVValues(*values, &msg, kFALSE);
1285 
1286  if (messages) {
1287  messages->Add(new TObjString(Form("%s %s", hvChannelName->String().Data(), msg.Data())));
1288  }
1289 
1290  if (!ok) {
1291  AliErrorGeneral("PatchHV", Form("PatchHVValue was not successfull ! This is serious ! "
1292  "You'll have to check the logic for channel %s",
1293  hvChannelName->String().Data()));
1294  }
1295  }
1296  }
1297 }
1298 
1299 
1300 //_____________________________________________________________________________
1301 void
1302 WriteToCDB(const char *calibpath, TObject *object,
1303  Int_t startRun, Int_t endRun,
1304  const char *filename)
1305 {
1307 
1308  TString comment(gSystem->ExpandPathName(filename));
1309 
1310  WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1311 }
1312 
1313 //_____________________________________________________________________________
1314 void
1315 WriteToCDB(const char *calibpath, TObject *object,
1316  Int_t startRun, Int_t endRun, Bool_t defaultValues)
1317 {
1319 
1320  TString comment;
1321  if (defaultValues) comment += "Test with default values";
1322  else comment += "Test with random values";
1323 
1324  WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1325 }
1326 
1327 //_____________________________________________________________________________
1328 void
1329 WriteToCDB(TObject *object, const char *calibpath, Int_t startRun, Int_t endRun,
1330  const char *comment, const char *responsible)
1331 {
1333 
1334  if (!CheckOCDB(kTRUE)) return;
1335 
1336  AliCDBId id(calibpath, startRun, endRun);
1337  AliCDBMetaData md;
1338  md.SetAliRootVersion(gROOT->GetVersion());
1339  md.SetComment(comment);
1340  md.SetResponsible(responsible);
1341  AliCDBManager::Instance()->Put(object, id, &md);
1342 }
1343 
1344 //_____________________________________________________________________________
1345 void
1346 WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1347 {
1349 
1351  Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1352  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1353  if (ngenerated > 0) {
1354  WriteToCDB("MUON/Calib/LocalTriggerBoardMasks", ltm, startRun, endRun, true);
1355  }
1356  delete ltm;
1357 }
1358 
1359 //_____________________________________________________________________________
1360 void
1361 WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1362 {
1364 
1366  Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1367  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1368  if (ngenerated > 0) {
1369  WriteToCDB("MUON/Calib/RegionalTriggerConfig", rtm, startRun, endRun, true);
1370  }
1371  delete rtm;
1372 }
1373 
1374 
1375 //_____________________________________________________________________________
1376 void
1377 WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1378 {
1380 
1382 
1383  Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1384  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1385  if (ngenerated > 0) {
1386  WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig", gtm, startRun, endRun, true);
1387  }
1388  delete gtm;
1389 }
1390 
1391 
1392 //_____________________________________________________________________________
1393 void
1394 WriteTriggerLut(Int_t startRun, Int_t endRun)
1395 {
1397 
1399  if (lut) {
1400  WriteToCDB("MUON/Calib/TriggerLut", lut, startRun, endRun, true);
1401  }
1402  delete lut;
1403 }
1404 
1405 //_____________________________________________________________________________
1406 void
1407 WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1408 {
1410 
1412  if (eff) {
1413  WriteToCDB("MUON/Calib/TriggerEfficiency", eff, startRun, endRun, true);
1414  }
1415  delete eff;
1416 }
1417 
1418 //_____________________________________________________________________________
1419 void
1420 WriteHV(const char *inputFile, Int_t runNumber)
1421 {
1425 
1426  TFile *f = TFile::Open(gSystem->ExpandPathName(inputFile));
1427 
1428  if (!f->IsOpen()) return;
1429 
1430  TMap *hvStore = static_cast<TMap *>(f->Get("map"));
1431 
1432  WriteToCDB("MUON/Calib/HV", hvStore, runNumber, runNumber, kFALSE);
1433 
1434  delete hvStore;
1435 }
1436 
1437 //_____________________________________________________________________________
1438 void
1439 WriteHV(Bool_t defaultValues,
1440  Int_t startRun, Int_t endRun)
1441 {
1446 
1447  TMap *hvStore = new TMap;
1448  Int_t ngenerated = MakeHVStore(*hvStore, defaultValues);
1449  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1450  if (ngenerated > 0) {
1451  WriteToCDB("MUON/Calib/HV", hvStore, startRun, endRun, defaultValues);
1452  }
1453  delete hvStore;
1454 }
1455 
1456 //_____________________________________________________________________________
1457 void
1458 WriteLV(Bool_t defaultValues,
1459  Int_t startRun, Int_t endRun,
1460  time_t refTime)
1461 {
1466 
1467  TMap *lvStore = new TMap;
1468  Int_t ngenerated = MakeLVStore(*lvStore, defaultValues, refTime);
1469  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1470  if (ngenerated > 0) {
1471  WriteToCDB("MUON/Calib/LV", lvStore, startRun, endRun, defaultValues);
1472  }
1473  delete lvStore;
1474 }
1475 
1476 //_____________________________________________________________________________
1477 void
1478 WriteTriggerDCS(Int_t startRun, Int_t endRun)
1479 {
1483 
1484  TMap *triggerDCSStore = new TMap;
1485  Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore);
1486  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1487  if (ngenerated > 0) {
1488  WriteToCDB("MUON/Calib/TriggerDCS", triggerDCSStore, startRun, endRun, true);
1489  }
1490  delete triggerDCSStore;
1491 }
1492 
1493 //_____________________________________________________________________________
1494 void
1495 WritePedestals(Bool_t defaultValues,
1496  Int_t startRun, Int_t endRun)
1497 {
1502 
1503  AliMUONVStore *pedestalStore = Create2DMap();
1504  Int_t ngenerated = MakePedestalStore(*pedestalStore, defaultValues);
1505  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1506  WriteToCDB("MUON/Calib/Pedestals", pedestalStore, startRun, endRun, defaultValues);
1507  delete pedestalStore;
1508 }
1509 
1510 //_____________________________________________________________________________
1511 void
1512 WriteOccupancyMap(Bool_t defaultValues,
1513  Int_t startRun, Int_t endRun)
1514 {
1519 
1520  AliMUONVStore *occupancyMapStore = Create2DMap();
1521  Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore, defaultValues);
1522  AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d", ngenerated));
1523  WriteToCDB("MUON/Calib/OccupancyMap", occupancyMapStore, startRun, endRun, defaultValues);
1524  delete occupancyMapStore;
1525 }
1526 
1527 //_____________________________________________________________________________
1528 void
1529 WriteRejectList(Bool_t defaultValues,
1530  Int_t startRun, Int_t endRun)
1531 {
1536 
1537  AliMUONRejectList *rl = MakeRejectListStore(defaultValues);
1538  WriteToCDB("MUON/Calib/RejectList", rl, startRun, endRun, defaultValues);
1539  delete rl;
1540 }
1541 
1542 //_____________________________________________________________________________
1543 void WriteMapping(Int_t startRun, Int_t endRun)
1544 {
1545  gSystem->Setenv("MINSTALL", gSystem->ExpandPathName("$ALICE_ROOT/MUON/mapping"));
1546  AliMpCDB::WriteMpData(startRun, endRun);
1547  AliMpCDB::WriteMpRunData(startRun, endRun);
1548 }
1549 
1550 //_____________________________________________________________________________
1551 void
1552 WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1553 {
1555  WriteTriggerDCS(startRun, endRun);
1556  WriteLocalTriggerMasks(startRun, endRun);
1557  WriteRegionalTriggerConfig(startRun, endRun);
1558  WriteGlobalTriggerConfig(startRun, endRun);
1559  WriteTriggerLut(startRun, endRun);
1560  WriteTriggerEfficiency(startRun, endRun);
1561 }
1562 
1563 //_____________________________________________________________________________
1564 void
1565 WriteConfig(Int_t startRun, Int_t endRun)
1566 {
1568  ostringstream lines;
1569  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1570  AliMpBusPatch *bp;
1571  while ((bp = static_cast<AliMpBusPatch *>(next()))) {
1572  for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu) {
1573  lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1574  }
1575  }
1576 
1577  AliMUON2DMap config(kTRUE);
1578 
1579  AliMUONTrackerIO::DecodeConfig(lines.str().c_str(), config);
1580 
1581  WriteToCDB("MUON/Calib/Config", &config, startRun, endRun, kTRUE);
1582 }
1583 
1584 //_____________________________________________________________________________
1585 void
1586 WriteBPEVO(Int_t startRun, Int_t endRun)
1587 {
1589 
1590  AliMergeableCollection bpevo("BPEVO");
1591 
1592  if (MakeBusPatchEvolution(bpevo, 60)) {
1593  WriteToCDB("MUON/Calib/BPEVO", &bpevo, startRun, endRun, kTRUE);
1594  }
1595 }
1596 
1597 //_____________________________________________________________________________
1598 void
1599 WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1600 {
1602  WriteMapping(startRun, endRun);
1603  WriteHV(defaultValues, startRun, endRun);
1604  WriteLV(defaultValues, startRun, endRun);
1605  WritePedestals(defaultValues, startRun, endRun);
1606  WriteOccupancyMap(defaultValues, startRun, endRun);
1607  WriteRejectList(defaultValues, startRun, endRun);
1608  WriteConfig(startRun, endRun);
1609  WriteBPEVO(startRun, endRun);
1610 }
1611 
1612 //_____________________________________________________________________________
1613 void
1614 ShowConfig(Bool_t withStatusMap)
1615 {
1619 
1620  if (!CheckOCDB()) return;
1621 
1622  LoadMapping();
1623 
1624  if (!CheckMapping()) return;
1625 
1626  AliCDBEntry *e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1627 
1628  if (!e) return;
1629 
1630  AliMUONVStore *config = static_cast<AliMUONVStore *>(e->GetObject());
1631 
1632  AliMUONPadStatusMapMaker *statusMapMaker(0x0);
1633  AliMUONCalibrationData *cd(0x0);
1634  AliMUONPadStatusMaker *statusMaker(0x0);
1635 
1636  if (withStatusMap) {
1637  cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1638 
1639  statusMaker = new AliMUONPadStatusMaker(*cd);
1640 
1641  AliMUONRecoParam *recoParam = LoadRecoParam();
1642 
1643  if (!recoParam) {
1644  AliErrorGeneral("ShowConfig", "Cannot get recoParams from OCDB !");
1645  return;
1646  }
1647 
1648  statusMaker->SetLimits(*recoParam);
1649 
1650  UInt_t mask = recoParam->PadGoodnessMask();
1651 
1652  delete recoParam;
1653 
1654  const Bool_t deferredInitialization = kFALSE;
1655 
1656  statusMapMaker = new AliMUONPadStatusMapMaker(*cd, mask, deferredInitialization);
1657  }
1658 
1659  TIter nextManu(config->CreateIterator());
1660  AliMUONVCalibParam *param;
1661 
1662  AliMpExMap buspatches;
1663 
1664  while ((param = static_cast<AliMUONVCalibParam *>(nextManu()))) {
1665  Int_t detElemId = param->ID0();
1666  Int_t manuId = param->ID1();
1667  Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId, manuId);
1668  if (buspatches.GetValue(busPatchId) == 0x0) {
1669  buspatches.Add(busPatchId, new TObjString(Form("BP%04d", busPatchId)));
1670  }
1671  }
1672 
1673  TArrayI removed(buspatches.GetSize());
1674 
1675  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1676  AliMpBusPatch *bp;
1677  Int_t n(0);
1678  Int_t nok(0);
1679  Int_t nremoved(0);
1680 
1681  // accounting of bus patches first
1682 
1683  while ((bp = static_cast<AliMpBusPatch *>(next()))) {
1684  if (buspatches.GetValue(bp->GetId())) {
1685  ++nok;
1686  } else {
1687  removed.SetAt(bp->GetId(), nremoved++);
1688  }
1689  }
1690 
1691  // accounting of channels
1692 
1693  AliMpManuIterator it;
1694 
1695  Int_t totalNumberOfChannels(0);
1696  Int_t removedChannels(0);
1697  Int_t badChannels(0);
1698  Int_t badAndRemovedChannels(0);
1699  Int_t badOrRemovedChannels(0);
1700 
1701  Int_t detElemId, manuId;
1702 
1703  while (it.Next(detElemId, manuId)) {
1705  for (Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i) {
1706  Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId, manuId);
1707 
1708  if (de->IsConnectedChannel(manuId, i)) {
1709  ++totalNumberOfChannels;
1710  Bool_t badBusPatch = (buspatches.GetValue(busPatchId) == 0x0);
1711 
1712  if (withStatusMap) {
1713  Bool_t badChannel = (
1714  (statusMapMaker->StatusMap(detElemId, manuId, i) & AliMUONPadStatusMapMaker::SelfDeadMask()) != 0);
1715  if (badChannel) ++badChannels;
1716  if (badBusPatch && badChannel) ++badAndRemovedChannels;
1717  if (badBusPatch || badChannel) ++badOrRemovedChannels;
1718  }
1719 
1720  if (badBusPatch) ++removedChannels;
1721  }
1722  }
1723  }
1724 
1725  Int_t *indices = new Int_t[nremoved];
1726 
1727  TMath::Sort(nremoved, removed.GetArray(), indices, kFALSE);
1728 
1729  for (Int_t i = 0; i < nremoved; ++i) {
1730  Int_t busPatchId = removed[indices[i]];
1731  bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1732  bp->Print();
1733  }
1734 
1735  delete[] indices;
1736 
1737  cout << endl;
1738  cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d", n, nok, nremoved) << endl;
1739 
1740  cout << Form("Channels n=%6d nremoved=%6d bad=%6d bad and removed=%6d bad or removed=%6d",
1741  totalNumberOfChannels, removedChannels, badChannels, badAndRemovedChannels, badOrRemovedChannels)
1742  << endl;
1743 
1744  if (totalNumberOfChannels > 0) {
1745  cout << Form("Percentage of readout channels %5.1f %%", removedChannels * 100.0 / totalNumberOfChannels) << endl;
1746  if (withStatusMap) {
1747  cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1748  badOrRemovedChannels * 100.0 / totalNumberOfChannels) << endl;
1749  }
1750  }
1751 
1752  delete statusMapMaker;
1753  delete cd;
1754  delete statusMaker;
1755 }
1756 
1757 //______________________________________________________________________________
1758 void ReadIntegers(const char *filename, std::vector<int> &integers)
1759 {
1762  ifstream in(gSystem->ExpandPathName(filename));
1763  int i;
1764 
1765  std::set<int> runset;
1766 
1767  char line[10000];
1768 
1769  in.getline(line, 10000, '\n');
1770 
1771  TString sline(line);
1772 
1773  if (sline.Contains(",")) {
1774  TObjArray *a = sline.Tokenize(",");
1775  TIter next(a);
1776  TObjString *s;
1777  while ((s = static_cast<TObjString *>(next()))) {
1778  runset.insert(s->String().Atoi());
1779  }
1780  delete a;
1781  } else {
1782  runset.insert(sline.Atoi());
1783 
1784  while (in >> i) {
1785  runset.insert(i);
1786  }
1787  }
1788 
1789  for (std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it) {
1790  integers.push_back((*it));
1791  }
1792 
1793  std::sort(integers.begin(), integers.end());
1794 }
1795 
1796 namespace {
1797 void GetBusPatchIdAndNofChannels(std::vector<int> &busPatchIds, std::vector<int> &busPatchNofChannels)
1798 {
1799  busPatchIds.clear();
1800  busPatchNofChannels.clear();
1801 
1802  TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1803  AliMpBusPatch *bp;
1804 
1805  while ((bp = static_cast<AliMpBusPatch *>(nextBP()))) {
1806  busPatchIds.push_back(bp->GetId());
1807  }
1808 
1809  std::sort(busPatchIds.begin(),busPatchIds.end());
1810 
1811  for ( int i = 0; i < busPatchIds.size(); ++i ) {
1812 
1813  int bpid = busPatchIds[i];
1814 
1816 
1817  int bpnofchannels = 0;
1818 
1820  AliMpDDLStore::Instance()->GetDEfromBus(bpid));
1821 
1822  for (int i = 0; i < bp->GetNofManus(); ++i) {
1823  bpnofchannels += de->NofChannelsInManu(bp->GetManuId(i));
1824  }
1825 
1826  busPatchNofChannels.push_back(bpnofchannels);
1827  }
1828 
1829  int totalNofChannels = 0;
1830 
1831  for ( int i = 0 ; i < busPatchIds.size(); ++i ) {
1832  totalNofChannels += busPatchNofChannels[i];
1833  }
1834 
1835  assert(totalNofChannels==1064008);
1836 }
1837 
1838 std::set<int> GetConfig(int runNumber) {
1839 
1840  std::set<int> buspatches;
1841 
1842  AliCDBEntry *e = AliCDBManager::Instance()->Get("MUON/Calib/Config", runNumber);
1843 
1844  AliMUONVStore *config = static_cast<AliMUONVStore *>(e->GetObject());
1845 
1846  TIter next(config->CreateIterator());
1847  AliMUONVCalibParam* param;
1848 
1849  while ( ( param = static_cast<AliMUONVCalibParam*>(next()))) {
1850  buspatches.insert(AliMpDDLStore::Instance()->GetBusPatchId(param->ID0(),param->ID1()));
1851  }
1852 
1853  return buspatches;
1854 }
1855 
1856 }
1857 
1858 
1859 //______________________________________________________________________________
1861  double fractionLimit,
1862  double meanLimit,
1863  double sigmaLimit,
1864  double outputFractionLimit,
1865  const char *outputBaseName,
1866  const char *ocdbPath)
1867 {
1874 
1876 
1878 
1879  man->SetDefaultStorage(ocdbPath);
1880 
1881  std::vector<int> runnumbers;
1882 
1883  ReadIntegers(runlist, runnumbers);
1884 
1885  if (runnumbers.empty()) {
1886  std::cout << "empty runlist. Bailing out\n";
1887  return;
1888  }
1889 
1890  man->SetRun(runnumbers[0]);
1891 
1893 
1894  std::vector<int> busPatchIds;
1895  std::vector<int> busPatchNofChannels;
1896 
1897  GetBusPatchIdAndNofChannels(busPatchIds,busPatchNofChannels);
1898 
1899  std::vector<int> busPatchInConfig(busPatchIds.size());
1900  std::vector<int> busPatchNotOK(busPatchIds.size());
1901 
1902  for (int i = 0; i < runnumbers.size(); ++i ) {
1903 
1904  int runNumber = runnumbers[i];
1905 
1906  man->SetRun(runNumber);
1907 
1908  std::set<int> buspatches = GetConfig(runNumber);
1909 
1910  AliCDBEntry *e = man->Get("MUON/Calib/Pedestals", runNumber);
1911 
1912  if (!e) {
1913  AliErrorGeneral("ShowFaultyPedestalsBusPatches",
1914  Form("Could not get Pedestals for run %09d", runNumber));
1915  continue;
1916  }
1917 
1918  AliMUONVStore *pedmap = static_cast<AliMUONVStore *>(e->GetObject());
1919 
1920  for ( int i = 0; i < busPatchIds.size(); ++i ) {
1921 
1922  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(busPatchIds[i]);
1924  AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchIds[i]);
1925 
1926  int nbad = 0;
1927 
1928  if (buspatches.find(busPatchIds[i]) != buspatches.end() ) {
1929  busPatchInConfig[i]++;
1930  }
1931 
1932  for (int m = 0; m < bp->GetNofManus(); ++m) {
1933 
1934  int manuId = bp->GetManuId(m);
1935 
1936  AliMUONVCalibParam *calibParam = static_cast<AliMUONVCalibParam *>(pedmap->FindObject(detElemId, manuId));
1937 
1938  if (!calibParam) {
1939  continue;
1940  }
1941 
1942  int nofchannels = de->NofChannelsInManu(manuId);
1943 
1944  for (int c = 0; c < nofchannels; ++c) {
1945  float mean = calibParam->ValueAsFloat(c, 0);
1946  float sigma = calibParam->ValueAsFloat(c, 1);
1947  if (mean >= meanLimit || sigma >= sigmaLimit) {
1948  ++nbad;
1949  }
1950  }
1951  }
1952 
1953  if (nbad / busPatchNofChannels[i] > fractionLimit) {
1954  busPatchNotOK[i]++;
1955  }
1956  }
1957  }
1958 
1959  std::ofstream outfile(Form("%s.txt", outputBaseName));
1960  for (int i = 0; i < busPatchIds.size(); ++i ) {
1961  if ( busPatchNotOK[i]) {
1962  float fraction = 1.0*busPatchNotOK[i]/busPatchInConfig[i];
1963  if (fraction>outputFractionLimit) {
1964  outfile << Form("BP %04d is bad for %3d runs in %3d (%7.2f%%)\n",
1965  busPatchIds[i], busPatchNotOK[i], busPatchInConfig[i],
1966  fraction*100);
1967  }
1968  }
1969  }
1970 
1971 }
1972 
1973 //______________________________________________________________________________
1974 void ShowFaultyBusPatches(const char* runlist, double occLimit,
1975  const char* outputBaseName,
1976  const char* ocdbPath)
1977 {
1980 
1982 
1983  // AliLog::SetPrintType(AliLog::kInfo,kFALSE);
1984  // AliLog::SetPrintType(AliLog::kWarning,kFALSE);
1985  // gErrorIgnoreLevel=kError; // to avoid all the TAlienFile::Open messages...
1986 
1988 
1989  man->SetDefaultStorage(ocdbPath);
1990 
1991  Bool_t first(kTRUE);
1992 
1993  std::vector<int> runnumbers;
1994 
1995  ReadIntegers(runlist,runnumbers);
1996 
1997  AliMUON2DMap bpValues(kFALSE);
1998 
1999  std::ofstream outfile(Form("%s.txt",outputBaseName));
2000 
2001  for ( unsigned int i = 0 ; i < runnumbers.size(); ++i )
2002  {
2003  int runNumber = runnumbers[i];
2004 
2005  man->SetRun(runNumber);
2006 
2007  if ( first )
2008  {
2010  first = kFALSE;
2011  }
2012 
2013  AliCDBEntry* e = man->Get("MUON/Calib/OccupancyMap",runNumber);
2014 
2015  if (!e)
2016  {
2017  AliErrorGeneral("ShowFaultyBusPatches",
2018  Form("Could not get OccupancyMap for run %09d",runNumber));
2019  continue;
2020  }
2021 
2022  AliMUONVStore* occmap = static_cast<AliMUONVStore*>(e->GetObject());
2023 
2024  AliMUONTrackerData td("occ","occ",*occmap);
2025 
2026  TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
2027  AliMpBusPatch* bp;
2028  std::set<int> buspatches;
2029  Double_t sumn = 1000.0;
2030 
2031  while ( ( bp = static_cast<AliMpBusPatch*>(nextBP()) ) )
2032  {
2033  Double_t occ = td.BusPatch(bp->GetId(),2);
2034 
2035  if (occ>occLimit)
2036  {
2037  buspatches.insert(bp->GetId());
2038 
2039  AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(bpValues.FindObject(bp->GetId()));
2040 
2041  if (!param)
2042  {
2043  param = new AliMUONCalibParamND(5, 1, bp->GetId(), 0);
2044  bpValues.Add(param);
2045 
2046  Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
2048 
2049  Int_t nchannels(0);
2050 
2051  for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
2052  {
2053  Int_t manuId = bp->GetManuId(imanu);
2054  nchannels += de->NofChannelsInManu(manuId);
2055  }
2056 
2057  param->SetValueAsDouble(0,2,sumn);
2058  param->SetValueAsDouble(0,3,nchannels);
2059  param->SetValueAsDouble(0,4,1);
2060  }
2061 
2062  Double_t sumw = sumn*(param->ValueAsDouble(0)/sumn+1.0/runnumbers.size());
2063  Double_t sumw2 = 0.0; //(sumn-1)*ey*ey+sumw*sumw/sumn;
2064 
2065  param->SetValueAsDouble(0,0,sumw);
2066  param->SetValueAsDouble(0,1,sumw2);
2067 
2068  }
2069  }
2070 
2071  outfile << Form("RUN %09d",runNumber);
2072 
2073  for ( std::set<int>::const_iterator bit = buspatches.begin(); bit != buspatches.end(); ++bit )
2074  {
2075  outfile << Form(" %4d",*bit);
2076  }
2077  outfile << endl;
2078  }
2079 
2080  outfile.close();
2081 
2082  if ( bpValues.GetSize() == 0 )
2083  {
2084  cout << Form("Great. No faulty bus patch (at the %g occupancy limit) found.",occLimit) << endl;
2085  gSystem->Exec(Form("rm %s.txt",outputBaseName));
2086  }
2087  else
2088  {
2089  const char* name = "BPfailureRate";
2090 
2091  AliMUONTrackerData* mpData = new AliMUONTrackerData(name,name,bpValues,2);
2092  mpData->SetDimensionName(0,name);
2093 
2094  TFile f(Form("%s.root",outputBaseName),"recreate");
2095  mpData->Write();
2096  f.Close();
2097 
2098  cout << Form("Results are in %s.txt and %s.root",outputBaseName,outputBaseName) << endl;
2099 
2100  gSystem->Exec(Form("cat %s.txt",outputBaseName));
2101  }
2102 }
2103 
2104 //______________________________________________________________________________
2105 Double_t MeanHVValueForDCSAlias(TMap& hvMap, const char* hvChannel)
2106 {
2107 
2108  TPair* hvPair = static_cast<TPair*>(hvMap.FindObject(hvChannel));
2109  if (!hvPair)
2110  {
2111  AliErrorGeneral("MeanHVValueForDCSAlias",Form("Did not find expected alias (%s)",hvChannel));
2112  return 0.0;
2113  }
2114  else
2115  {
2116  TObjArray* values = static_cast<TObjArray*>(hvPair->Value());
2117  if (!values)
2118  {
2119  AliErrorGeneral("MeanHVValueForDCSAlias",Form("Could not get values for alias %s",hvChannel));
2120  return 0.0;
2121  }
2122  else
2123  {
2124  // find out min value, and makes a cut
2125  Float_t hv(0.0);
2126  Float_t n(0.0);
2127  TIter next(values);
2128  AliDCSValue* val;
2129 
2130  while ( ( val = static_cast<AliDCSValue*>(next()) ) )
2131  {
2132  hv += val->GetFloat();
2133  n += 1.0;
2134  }
2135 
2136  if (n>0.0)
2137  {
2138  hv /= n;
2139  return hv;
2140  }
2141  }
2142  return 0.0;
2143  }
2144 }
2145 }
2146 
Int_t GetNofManus() const
Convert a pad status container into a pad status map container.
TBrowser b
Definition: RunAnaESD.C:12
virtual TIterator * CreateIterator() const =0
Return an iterator to loop over the whole store.
Implementation of AliMUONVTrackerData.
#define AliCodeTimerAutoGeneral(message, counter)
Definition: AliCodeTimer.h:141
TFile * Open(const char *filename, Long64_t &nevents)
The class defines the configuration of global crate.
static Float_t InvalidFloatValue()
Return 1E38 as invalid float value.
Bool_t CheckOCDB(Bool_t pathOnly)
Definition: AliMUONCDB.cxx:193
Int_t MakeBusPatchEvolution(AliMergeableCollection &hc, int timeResolution)
Definition: AliMUONCDB.cxx:723
Int_t GetRun() const
AliMUONRejectList * MakeRejectListStore(Bool_t defaultValues)
void WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
static AliMpDEStore * Instance(Bool_t warn=true)
static Bool_t WriteMpData()
Definition: AliMpCDB.cxx:364
static void SetGlobalLogLevel(EType_t type)
Definition: AliLog.cxx:447
static TString AsString(Int_t status)
static AliMpSegmentation * Instance(Bool_t warn=true)
virtual Float_t ValueAsFloat(Int_t i, Int_t j=0) const =0
TMap * HV(Bool_t patched=kTRUE) const
Get the HV values. Use patched=kFALSE to get unprocessed (i.e. "raw") values as they are in the OCDB...
#define TObjArray
High Voltage.
Definition: AliMpDCSNamer.h:84
Implementation of AliMUONVCalibParam for tuples of floats.
Bool_t IsSt1DCSAliasRemapped(const TString &name)
Definition: AliMUONCDB.cxx:456
void CheckHV_ALIROOT_6402(const char *runlist, Bool_t verbose)
Definition: AliMUONCDB.cxx:343
#define AliErrorGeneral(scope, message)
Definition: AliLog.h:601
virtual void SetValueAsFloat(Int_t i, Int_t j, Float_t value)=0
Set one value, for channel i, dimension j. Consider value is a float.
TClonesArray * LoadAlignmentData()
Definition: AliMUONCDB.cxx:572
static TString comment
Definition: ConfigCosmic.C:131
virtual Double_t BusPatch(Int_t busPatchId, Int_t dim=0) const
Get the value for a given buspatch and given dimension.
Int_t MakeLVStore(TMap &aliasMap, Bool_t defaultValues, time_t refTime)
Definition: AliMUONCDB.cxx:833
Int_t Log(const char *message)
Bool_t ReadGRPEntry()
static Bool_t WriteMpRunData()
Definition: AliMpCDB.cxx:370
Int_t GetDEfromBus(Int_t busPatchId) const
Store and give access to the trigger chamber efficiency.
TROOT * gROOT
void WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
Collection of methods usefull to DCS handling for MUON TRK and TRG.
Definition: AliMpDCSNamer.h:22
void WriteTriggerDCS(Int_t startRun, Int_t endRun)
void SetComment(const char *comment)
Int_t MakePedestalStore(AliMUONVStore &pedestalStore, Bool_t defaultValues)
const AliMpVSegmentation * GetMpSegmentationByElectronics(Int_t detElemId, Int_t elCardID, Bool_t warn=true) const
virtual void SetDimensionName(Int_t index, const char *value)
Set the name of a given dimension.
static Int_t DecodeConfig(const char *data, AliMUONVStore &confStore)
Helper functions to experience the OCDB.
AliMUONTriggerLut * MakeTriggerLUT(const char *file)
void SetResponsible(const char *yourName)
Int_t MakeLocalTriggerMaskStore(AliMUONVStore &localBoardMasks)
virtual void SetValueAsInt(Int_t i, Int_t j, Int_t value)=0
Set one value, for channel i, dimension j. Consider value is an integer.
Class with MUON reconstruction parameters.
AliMpDetElement * GetDetElement(Int_t detElemId, Bool_t warn=true) const
virtual Double_t ValueAsDouble(Int_t i, Int_t j=0) const
Int_t GetManuId(Int_t index) const
static AliMpManuStore * Instance(Bool_t warn=true)
void ShowFaultyPedestalsBusPatches(const char *runlist, double fractionLimit, double meanLimit, double sigmaLimit, double outputFractionLimit, const char *outputBaseName, const char *ocdbPath)
Bool_t LoadMapping(Bool_t segmentationOnly)
Definition: AliMUONCDB.cxx:502
The class defines the electronics properties of detection element.
void CheckHV(Int_t runNumber, Int_t verbose)
Definition: AliMUONCDB.cxx:217
Int_t MakeTriggerDCSStore(TMap &aliasMap)
Definition: AliMUONCDB.cxx:909
Float_t GetFloat() const
void PatchHV(TMap &hvMap, TList *messages, Bool_t onlySt1remapped)
Bool_t Next(TString &msg, Int_t &occurance)
static AliLog * GetRootLogger()
Definition: AliLog.cxx:71
void WriteOccupancyMap(Bool_t defaultValues, Int_t startRun, Int_t endRun)
void WriteHV(const char *inputFile, Int_t runNumber)
void WritePedestals(Bool_t defaultValues, Int_t startRun, Int_t endRun)
Bool_t LoadField()
Definition: AliMUONCDB.cxx:478
Bool_t Next(Int_t &detElemId, Int_t &manuId)
Class to loop over all manus of MUON Tracker.
TObjArray * array
Definition: AnalyzeLaser.C:12
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
AliMUONVStore * Diff(AliMUONVStore &store1, AliMUONVStore &store2, const char *opt)
Definition: AliMUONCDB.cxx:597
static TString LocalTriggerBoardMapping()
Definition: AliMpFiles.cxx:337
Int_t GetSize() const
Definition: AliMpExMap.cxx:340
void SetDetectionElementProbability(Int_t detElemId, Float_t proba=1.0)
A logger that keeps track of the number of times a message appeared.
Definition: AliMUONLogger.h:24
void WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
void AddDCSValue(TMap &aliasMap, Int_t imeas, const char *smt, const char *sInOut, Int_t rpc, Float_t value)
Definition: AliMUONCDB.cxx:892
Container of calibration values for a given number of channels.
static AliMpDDLStore * Instance(Bool_t warn=true)
static Int_t GetChamberId(Int_t detElemId, Bool_t warn=true)
AliMUONVStore * StatusMap() const
static Int_t ManuNofChannels()
Max number of channels per manu.
TObject * GetObject()
Definition: AliCDBEntry.h:56
void WriteBPEVO(Int_t startRun, Int_t endRun)
void ReadFromFile(const char *filename)
Int_t GetBusPatchId(Int_t detElemId, Int_t manuId) const
virtual TObject * FindObject(Int_t i, Int_t j) const
Find an object using 2 ids.
Implementation of AliMUONVCalibParam for tuples of ints.
void ShowFaultyBusPatches(const char *runlist, double occLimit, const char *outputBaseName, const char *ocdbPath)
Int_t MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig &rtm)
void WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
Int_t MakeHVStore(TMap &aliasMap, Bool_t defaultValues)
Definition: AliMUONCDB.cxx:776
virtual Int_t ID0() const
First id of this object.
non-bending plane
void SetAliRootVersion(const char *version)
static Bool_t PatchHVValues(TObjArray &values, TString *msg=0x0, Bool_t dryRun=kFALSE)
Implementation of AliMUONVCalibParam for tuples of double.
AliMpBusPatch * GetBusPatch(Int_t busPatchId, Bool_t warn=true) const
TObject * GetValue(Int_t keyFirst, Int_t keySecond) const
Definition: AliMpExMap.cxx:365
Int_t GetId() const
Return the unique Id.
Definition: AliMpBusPatch.h:89
Int_t DCSIndexFromDCSAlias(const char *dcsAlias) const
Bool_t Put(TObject *object, const AliCDBId &id, AliCDBMetaData *metaData, const char *mirrors="", DataType type=kPrivate)
static Int_t TotalNofLocalBoards()
Return total number of trigger local boards.
Int_t MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig &gtm)
Bool_t SetMagField()
void Add(Int_t keyFirst, Int_t keySecond, TObject *object)
Definition: AliMpExMap.cxx:292
void SetRun(Int_t run)
Helper class for sorted integer array.
Definition: AliMpArrayI.h:21
Implementation of AliMUONVStore.
static Int_t SelfDeadMask()
Return status bit map to tell a pad is bad.
Definition: AliCDBEntry.h:18
Int_t NofChannelsInManu(Int_t manuId) const
void WriteMapping(Int_t startRun, Int_t endRun)
TF1 * f
Definition: interpolTest.C:21
Basic implementation of AliMUONVStore container using AliMpExMap internally.
Definition: AliMUON2DMap.h:20
void SetDefaultStorage(const char *dbString)
void WriteLV(Bool_t defaultValues, Int_t startRun, Int_t endRun, time_t refTime)
Bool_t IsValid() const
Return validity.
Definition: AliMpPad.h:89
virtual Bool_t Add(TObject *object)=0
Add an object to the store.
The class defines the properties of BusPatch.
Definition: AliMpBusPatch.h:21
void WriteToCDB(const char *calibpath, TObject *object, Int_t startRun, Int_t endRun, const char *filename)
Single entry point to access MUON calibration data.
AliMUONTriggerEfficiencyCells * MakeTriggerEfficiency(const char *file)
TH1 ** Plot(const AliMUONVStore &store, const char *name, Int_t nbins)
Definition: AliMUONCDB.cxx:655
virtual Bool_t Add(TObject *object)
Add an object to the store.
static void UnloadAll()
Definition: AliMpCDB.cxx:520
void WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
The abstract base class for the segmentation.
Int_t MakeOccupancyMapStore(AliMUONVStore &occupancyMapStore, Bool_t defaultValues)
static TObject * CreateObject(Int_t runNumber, const char *path, Int_t *startOfValidity=0x0)
#define AliInfoGeneral(scope, message)
Definition: AliLog.h:494
Int_t GetBusPatchId(Int_t index) const
void WriteConfig(Int_t startRun, Int_t endRun)
TArrayI runlist(10000)
static TString GlobalTriggerBoardMapping()
Definition: AliMpFiles.cxx:347
void WriteTriggerLut(Int_t startRun, Int_t endRun)
TObjArray * GenerateAliases(const char *pattern="") const
Object to hold the list of elements we want to reject from the reconstruction.
static Int_t runNumber
Definition: pdc06_config.C:126
void ReadIntegers(const char *filename, std::vector< int > &integers)
Class which encapsuate all information about a pad.
Definition: AliMpPad.h:22
Int_t HVStatus(Int_t detElemId, Int_t manuId) const
static TMap * CreateHV(Int_t runNumber, Int_t *startOfValidity=0, Bool_t patched=kTRUE, TList *messages=0x0, Bool_t dryRun=kFALSE)
Create a hv map (which must be deleted) from OCDB for the given run.
const AliMpArrayI * ManusForHV(Int_t hvIndex) const
Bool_t CheckMapping(Bool_t segmentationOnly)
Definition: AliMUONCDB.cxx:434
Double_t MeanHVValueForDCSAlias(TMap &hvMap, const char *hvChannel)
UInt_t PadGoodnessMask() const
Get the goodness mask.
Int_t GetValue(Int_t index) const
Bool_t IsConnectedChannel(Int_t manuId, Int_t manuChannel) const
void WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
void ShowConfig(Bool_t withStatusMap)
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
virtual AliMpPad PadByLocation(Int_t manuId, Int_t manuChannel, Bool_t warning=true) const =0
Find pad by location.
Int_t DetElemIdFromDCSAlias(const char *dcsAlias) const
void WriteRejectList(Bool_t defaultValues, Int_t startRun, Int_t endRun)
Base class for MUON data stores.
Definition: AliMUONVStore.h:22
Bool_t IsDefaultStorageSet() const
Definition: AliCDBManager.h:60
static Bool_t LoadAll(Bool_t warn=false)
Definition: AliMpCDB.cxx:196
Int_t ReadData(const TString &fileName="")
virtual Int_t GetSize() const
The number of objects stored.
MUON trigger look up table class.
static Bool_t LoadMpSegmentation(Bool_t warn=false)
Definition: AliMpCDB.cxx:113
Int_t ReadData(const TString &fileName="")
static Int_t NofTrackingChambers()
Return number of tracking chambers.
The class defines the properties of regional trigger crate.
Make a 2DStore of pad statuses, using different sources of information.
virtual TObject * FindObject(const char *name) const
Find an object by name.
Helper class making Root persistent TExMap.
Definition: AliMpExMap.h:28
static Int_t ManuMask(AliMp::PlaneType planeType)
AliMUONRecoParam * LoadRecoParam()
Definition: AliMUONCDB.cxx:535
virtual void SetValueAsDouble(Int_t i, Int_t j, Double_t value)
void SetLimits(const AliMUONRecoParam &recoParams)
virtual void Print(Option_t *opt="") const