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