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