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