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