]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/MUONCDB.C
67f72d97ad6c1d4a39627e19fd1c541aa37bb0eb
[u/mrichter/AliRoot.git] / MUON / MUONCDB.C
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 /// By Laurent Aphecetche
19
20 #if !defined(__CINT__) || defined(__MAKECINT__)
21
22 #include "MUONCDB.h"
23
24 #include "AliCDBEntry.h"
25 #include "AliCDBManager.h"
26 #include "AliMUON1DArray.h"
27 #include "AliMUON2DMap.h"
28 #include "AliMUONCalibParam1I.h"
29 #include "AliMUONCalibParam2F.h"
30 #include "AliMUONConstants.h"
31 #include "AliMUONObjectPair.h"
32 #include "AliMUONTriggerEfficiencyCells.h"
33 #include "AliMUONTriggerLut.h"
34 #include "AliMUONV2DStore.h"
35 #include "AliMUONVCalibParam.h"
36 #include "AliMUONVDataIterator.h"
37 #include "AliMpDEIterator.h"
38 #include "AliMpDEManager.h"
39 #include "AliMpManuList.h"
40 #include "AliMpSegmentation.h"
41 #include "AliMpVSegmentation.h"
42 #include "AliMpStationType.h"
43 #include "Riostream.h"
44 #include "TH1F.h"
45 #include "TList.h"
46 #include "TRandom.h"
47 #include "TStopwatch.h"
48 #include "TSystem.h"
49 #endif
50
51 //_____________________________________________________________________________
52 Int_t countChannels(const AliMpVSegmentation& seg)
53 {
54   Int_t n(0);
55   
56   for ( Int_t ix = 0; ix < seg.MaxPadIndexX(); ++ix )
57   {
58     for ( Int_t iy = 0; iy < seg.MaxPadIndexY(); ++iy )
59     {
60       if ( seg.HasPad(AliMpIntPair(ix,iy)) ) ++n;
61     }
62   }
63   return n;
64 }
65
66 //_____________________________________________________________________________
67 void countChannels()
68 {
69   AliMpDEIterator it;
70   Int_t ntotal(0);
71   Int_t ntracker(0);
72   Int_t ntrigger(0);
73   
74   for ( Int_t station = 0; station < AliMUONConstants::NCh(); ++station )
75   {
76     Int_t n(0);
77     it.First(station);
78     while (!it.IsDone())
79     {
80       Int_t de = it.CurrentDE();
81       for ( Int_t cathode = 0; cathode < 2; ++cathode )
82       {
83         const AliMpVSegmentation* seg 
84           = AliMpSegmentation::Instance()->GetMpSegmentation(de,cathode);
85         n += countChannels(*seg);
86       }
87       it.Next();
88     }
89     cout << "Station " << station << " has " << n << " channels" << endl;
90     if ( station < AliMUONConstants::NTrackingCh() )
91     {
92       ntracker += n;
93     }
94     else
95     {
96       ntrigger += n;
97     }
98     ntotal += n;
99   }
100   cout << "Tracker channels = " << ntracker << endl;
101   cout << "Trigger channels = " << ntrigger << endl;
102   cout << "Total channels =" << ntotal << endl;
103 }
104
105 //_____________________________________________________________________________
106 AliMUONV2DStore* read2D(const char* calibType, Int_t runNumber)
107 {
108   AliCDBManager* man = AliCDBManager::Instance();
109   man->SetDefaultStorage(CDBPath);
110
111   AliCDBEntry* entry = man->Get(calibType,runNumber);
112
113   if (entry)
114     {
115       return (AliMUONV2DStore*)entry->GetObject();
116     }
117   return 0;
118 }
119
120 //_____________________________________________________________________________
121 AliMUONV1DStore* read1D(const char* calibType, Int_t runNumber)
122 {
123   AliCDBManager* man = AliCDBManager::Instance();
124   man->SetDefaultStorage(CDBPath);
125   
126   AliCDBEntry* entry = man->Get(calibType,runNumber);
127   
128   if (entry)
129   {
130     return (AliMUONV1DStore*)entry->GetObject();
131   }
132   return 0;
133 }
134
135 //_____________________________________________________________________________
136 void checkCDB(const char* calibType)
137 {
138   TString c(calibType);
139   Float_t refValue(0);
140   
141   if ( c == "MUON/Calib/DeadChannels" )
142   {
143     refValue=5;
144   }
145    
146   AliMUONV2DStore* store = read2D(calibType);
147   if (!store) return;
148   
149   TList* list = AliMpManuList::ManuList();
150   TIter next(list);
151   AliMpIntPair* p;
152   
153   while ( ( p = (AliMpIntPair*)next() ) )
154   {
155     Int_t detElemId = p->GetFirst();
156     Int_t manuId = p->GetSecond();
157     
158     AliMUONVCalibParam* value = 
159       dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
160     
161     if (value)
162     {
163       for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
164       {
165         Float_t testValue = value->ValueAsFloat(manuChannel,0);
166         if ( testValue && testValue != refValue )
167         {
168           cout << "Got a strange value for DE=" << detElemId << " manuId="
169           << manuId << " manuChannel=" << manuChannel << " was expecting "
170           << refValue << " and I got " << testValue << endl;
171         }
172       }
173     }
174     else
175     {
176       cout << "Got a null value for DE=" << detElemId << " manuId="
177       << manuId << endl;
178     }
179   }
180   
181   delete list;
182   delete store;
183 }
184
185 //_____________________________________________________________________________
186 //void testDump(AliMUONV2DStore& store, int n)
187 //{  
188 //  AliMUONObjectPair* p;
189 //  
190 //  Int_t c(0);
191 //  
192 //  for ( Int_t i = 0; i < n; ++i )
193 //  {
194 //    AliMUONVDataIterator* it = store.Iterator();
195 //    
196 //    while ( ( p = dynamic_cast<AliMUONObjectPair*>(it->Next() ) ) )
197 //    {
198 //      AliMpIntPair* dm = dynamic_cast<AliMpIntPair*>(p->Key());
199 //      if (dm)
200 //      {
201 //        Int_t a(dm->GetFirst()+dm->GetSecond());
202 //        a=2;
203 //        ++c;
204 //        AliMUONVCalibParam* param = dynamic_cast<AliMUONVCalibParam*>(p->Value());
205 //      }
206 //      delete p;
207 //    }
208 //    delete it;
209 //  }
210 //    
211 //  cout << c << endl;
212 //}
213
214 //_____________________________________________________________________________
215 AliMUONV2DStore* diff(AliMUONV2DStore& store1, AliMUONV2DStore& store2, 
216                       const char* /* opt */)
217 {
218   // creates a store which contains store1-store2
219   // if opt="abs" the difference is absolute one,
220   // if opt="rel" then what is stored is (store1-store2)/store1
221   
222   AliMUONV2DStore* d = static_cast<AliMUONV2DStore*>(store1.Clone());
223
224   AliMUONVDataIterator* it = d->Iterator();
225   
226   AliMUONObjectPair* p;
227   
228   while ( ( p = dynamic_cast<AliMUONObjectPair*>(it->Next() ) ) )
229   {
230     AliMpIntPair* dm = dynamic_cast<AliMpIntPair*>(p->Key());
231     //FIXME: this might happen (if a full manu is missing, for instance)
232     //handle it.
233     assert(dm!=0);
234     AliMUONVCalibParam* param = dynamic_cast<AliMUONVCalibParam*>(p->Value());
235     //FIXMENOT: this should *not* happen
236     assert(param!=0);
237
238     AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.Get(dm->GetFirst(),dm->GetSecond()));
239     //FIXME: this might happen. Handle it.
240     assert(param2!=0);
241     
242     for ( Int_t i = 0; i < param->Size(); ++i )
243     {
244       for ( Int_t j = 0; j < param->Dimension(); ++j )
245       {
246         param->SetValueAsFloat(i,j,param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j));
247       }      
248     }
249   }
250   return d;
251 }
252
253 //_____________________________________________________________________________
254 void getBoundaries(const AliMUONV2DStore& store,
255                    Float_t& x0min, Float_t& x0max,
256                    Float_t& x1min, Float_t& x1max)
257 {
258   x0min=1E30;
259   x0max=-1E30;
260   x1min=1E30;
261   x1max=-1E30;
262   
263   TList* list = AliMpManuList::ManuList();
264   TIter next(list);
265   AliMpIntPair* p;
266   
267   while ( ( p = (AliMpIntPair*)next() ) )
268   {
269     Int_t detElemId = p->GetFirst();
270     Int_t manuId = p->GetSecond();
271         
272     const AliMpVSegmentation* seg = 
273       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
274           
275     AliMUONVCalibParam* value = 
276       dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
277     
278     if (!value) continue;
279
280     for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
281     {
282       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
283       if (!pad.IsValid()) continue;
284
285       Float_t x0 = value->ValueAsFloat(manuChannel,0);
286       
287       x0min = TMath::Min(x0min,x0);
288       x0max = TMath::Max(x0max,x0);
289       if ( value->Dimension()>1 )
290       {
291         Float_t x1 = value->ValueAsFloat(manuChannel,1);
292         x1min = TMath::Min(x1min,x1);
293         x1max = TMath::Max(x1max,x1);
294       }
295     }
296   }  
297   delete list;
298 }
299
300 //_____________________________________________________________________________
301 void plot(const AliMUONV2DStore& store, const char* name, Int_t nbins)
302 {
303   Float_t x0min, x0max, x1min, x1max;
304   
305   getBoundaries(store,x0min,x0max,x1min,x1max);
306   
307   if ( x0min > x0max ) 
308   {
309     cerr << Form("Something is wrong with boundaries : x0(min,max)=%e,%e",
310                  x0min,x0max) << endl;
311     return;
312   }
313
314   if ( TMath::Abs(x0min-x0max) < 1E-3 ) 
315   {
316     x0min -= 1;
317     x0max += 1;
318   }
319   
320   TH1* h0 = new TH1F(Form("%s_0",name),Form("%s_0",name),
321                     nbins,x0min,x0max);
322   
323   TH1* h1(0);
324   
325   if ( x1max > x1min )
326   {
327     h1 = new TH1F(Form("%s_1",name),Form("%s_1",name),
328                   nbins,x1min,x1max);
329   }
330   
331   TList* list = AliMpManuList::ManuList();
332   TIter next(list);
333   AliMpIntPair* p;
334   Int_t n(0);
335   Int_t nPerStation[7];
336   
337   for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
338   
339   while ( ( p = (AliMpIntPair*)next() ) )
340   {
341     Int_t detElemId = p->GetFirst();
342     Int_t manuId = p->GetSecond();
343     Int_t station = AliMpDEManager::GetChamberId(detElemId);
344     
345     const AliMpVSegmentation* seg = 
346       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
347     
348     AliMUONVCalibParam* value = 
349       dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId));
350     
351     if (value)
352     {
353       for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
354       {
355         AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
356         if (!pad.IsValid()) continue;
357
358         ++n;
359         ++nPerStation[station];
360         Float_t x = value->ValueAsFloat(manuChannel,0);
361         h0->Fill(x);
362         if (h1)
363         {
364           h1->Fill(value->ValueAsFloat(manuChannel,1));
365         }
366       }
367     }
368     else
369     {
370       cout << "Got a null value for DE=" << detElemId << " manuId="
371       << manuId << endl;
372     }
373   }
374   
375   cout << "Number of channels = " << n << endl;
376   for ( Int_t i = 0; i < 7; ++i )
377   {
378     cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
379   }
380   
381   delete list;
382 }
383
384 //_____________________________________________________________________________
385 void plotCDB(const char* calibType, Int_t runNumber)
386 {
387   AliMUONV2DStore* store = read2D(calibType,runNumber);
388   if (!store) return;
389
390   TString c(calibType);
391   c.ReplaceAll("/","_");
392   
393   plot(*store,c.Data());
394   
395   delete store;
396 }
397
398 //_____________________________________________________________________________
399 void testReadStore(const AliMUONV2DStore& store, Int_t n)
400 {
401   TList* list = AliMpManuList::ManuList();
402   TIter next(list);
403   AliMpIntPair* p;
404   
405   while ( ( p = (AliMpIntPair*)next() ) )
406   {
407     for ( Int_t i = 0; i < n; ++i )
408     {
409       store.Get(p->GetFirst(),p->GetSecond());
410     }
411   }
412   delete list;
413
414
415 //_____________________________________________________________________________
416 Int_t makePedestalStore(AliMUONV2DStore& pedestalStore, Bool_t defaultValues)
417 {
418   TList* list = AliMpManuList::ManuList();
419   TIter next(list);
420   
421   AliMpIntPair* p;
422   
423   Int_t nchannels(0);
424   Int_t nmanus(0);
425   
426   Bool_t replace = kFALSE;
427   
428   const Int_t nChannels(64);
429   const Float_t kPedestalMeanMean(150);
430   const Float_t kPedestalMeanSigma(10);
431   const Float_t kPedestalSigmaMean(1.0);
432   const Float_t kPedestalSigmaSigma(0.2);
433   
434   while ( ( p = (AliMpIntPair*)next() ) )
435   {
436     ++nmanus;
437     AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels,AliMUONVCalibParam::InvalidFloatValue());
438     
439     Int_t detElemId = p->GetFirst();
440         
441     Int_t manuId = p->GetSecond();
442     
443     const AliMpVSegmentation* seg = 
444       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
445     
446     for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
447     {
448       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
449       if (!pad.IsValid()) continue;
450       
451       ++nchannels;
452       
453       Float_t meanPedestal;
454       Float_t sigmaPedestal;
455       
456       if ( defaultValues ) 
457       {
458         meanPedestal = 0.0;
459         sigmaPedestal = 1.0;
460       }
461       else
462       {
463         meanPedestal = -1;
464         while ( meanPedestal < 0 )
465         {
466           meanPedestal = gRandom->Gaus(kPedestalMeanMean,kPedestalMeanSigma);
467         }
468         sigmaPedestal = -1;
469         while ( sigmaPedestal < 0 )
470         {
471           sigmaPedestal = gRandom->Gaus(kPedestalSigmaMean,kPedestalSigmaSigma);
472         }
473       }
474       ped->SetValueAsFloat(manuChannel,0,meanPedestal);
475       ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
476       
477     }
478     Bool_t ok = pedestalStore.Set(detElemId,manuId,ped,replace);
479     if (!ok)
480     {
481       cout << "Could not set DetElemId=" << detElemId << " manuId="
482       << manuId << endl;
483     }
484   }
485   
486   delete list;
487   cout << nmanus << " Manus and " << nchannels << " channels." << endl;
488   return nchannels;
489   
490 }
491
492 //_____________________________________________________________________________
493 Int_t makeGainStore(AliMUONV2DStore& gainStore, Bool_t defaultValues)
494 {  
495   TList* list = AliMpManuList::ManuList();
496   TIter next(list);
497   
498   AliMpIntPair* p;
499   
500   Int_t nchannels(0);
501   Int_t nmanus(0);
502   
503   Bool_t replace = kFALSE;
504   
505   const Int_t nChannels(64);
506   const Double_t kSaturation(3000);
507   const Double_t kGainMean(1.0);
508   const Double_t kGainSigma(0.05);
509   
510   while ( ( p = (AliMpIntPair*)next() ) )
511   {
512     ++nmanus;
513     AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels,AliMUONVCalibParam::InvalidFloatValue());
514
515     Int_t detElemId = p->GetFirst();
516     Int_t manuId = p->GetSecond();
517
518     const AliMpVSegmentation* seg = 
519       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
520
521     for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
522     {
523       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
524       if (!pad.IsValid()) continue;
525       
526       ++nchannels;
527       
528       Float_t meanGain;
529       Float_t saturation(kSaturation);
530     
531       if ( defaultValues ) 
532       {
533         meanGain = 1.0;
534       }
535       else
536       {
537         meanGain = -1;
538         while ( meanGain < 0 )
539         {
540           meanGain = gRandom->Gaus(kGainMean,kGainSigma);
541         }
542       }
543       gain->SetValueAsFloat(manuChannel,0,meanGain);
544       gain->SetValueAsFloat(manuChannel,1,saturation);
545       
546     }
547     Bool_t ok = gainStore.Set(detElemId,manuId,gain,replace);
548     if (!ok)
549     {
550       cout << "Could not set DetElemId=" << detElemId << " manuId="
551         << manuId << endl;
552     }
553   }
554   
555   delete list;
556   cout << nmanus << " Manus and " << nchannels << " channels." << endl;
557   return nchannels;
558 }
559
560 //_____________________________________________________________________________
561 Int_t makeDeadStore(AliMUONV2DStore& deadStore, Bool_t defaultValues)
562 {  
563   TList* list = AliMpManuList::ManuList();
564   TIter next(list);
565   
566   AliMpIntPair* p;
567   
568   Int_t nchannels(0);
569   Int_t nmanus(0);
570   
571   Bool_t replace = kFALSE;
572   
573   const Int_t nChannels(64);
574   const Double_t deadProba = 1.0; // 1%
575   
576   while ( ( p = (AliMpIntPair*)next() ) )
577   {
578     ++nmanus;
579     AliMUONVCalibParam* dead = new AliMUONCalibParam1I(nChannels,-9999);
580     
581     Int_t detElemId = p->GetFirst();
582     Int_t manuId = p->GetSecond();
583     
584     const AliMpVSegmentation* seg = 
585       AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
586     
587     for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
588     {
589       AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
590       if (!pad.IsValid()) continue;
591       
592       ++nchannels;
593             
594       if (!defaultValues)
595       {
596         // probability that this channel is dead ~ 1%
597         if ( gRandom->Uniform(100.0) < deadProba ) 
598         {
599           Int_t reason = 5; // that value could be used to distinguish
600                             // why the channel is dead or how it was flagged bad (online,
601                             // offline, by chance...). 5 is of course a fake number.
602           dead->SetValueAsInt(manuChannel,0,reason);
603         }
604       }
605     }
606     Bool_t ok = deadStore.Set(detElemId,manuId,dead,replace);
607     if (!ok)
608     {
609       cout << "Could not set DetElemId=" << detElemId << " manuId="
610       << manuId << endl;
611     }
612   }
613   
614   delete list;
615   cout << nmanus << " Manus and " << nchannels << " channels." << endl;
616   return nchannels;
617 }
618
619 //_____________________________________________________________________________
620 void testMakeStores(Int_t readLoop)
621 {
622   AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
623   AliMUONV2DStore* gainStore = new AliMUON2DMap;
624   AliMUONV2DStore* deadStore = new AliMUON2DMap;
625   
626   TStopwatch timer;
627   
628   cout << "Creating" << endl;
629   
630   Bool_t defaultValues = kTRUE;
631   
632   timer.Start(kTRUE);
633   makePedestalStore(*pedestalStore,defaultValues);
634   makeGainStore(*gainStore,defaultValues);
635   makeDeadStore(*deadStore,defaultValues);
636   timer.Print();
637   
638   cout << "Reading..." << endl;
639   timer.Start(kTRUE);
640   testReadStore(*pedestalStore,readLoop);
641   testReadStore(*gainStore,readLoop);
642   testReadStore(*deadStore,readLoop);
643   cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop 
644     <<" samples." << endl;
645   
646   delete pedestalStore;
647   delete gainStore;
648   delete deadStore;
649 }
650
651 //_____________________________________________________________________________
652 void generateTrigger(const char* cdbpath)
653 {
654   // 
655   // Generate trigger related conditions :
656   //
657   // - trigger masks for board (locals, regionals, global)
658   // - trigger lut
659   // - trigger efficiency
660   // - trigger switches (to be implemented FIXME)
661   //
662   const Int_t nlboards = 234;
663   AliMUONV1DStore* localBoardMasks = new AliMUON1DArray(nlboards+1);
664   
665   // Generate fake mask values for 234 localboards and put that into
666   // one single container (localBoardMasks)
667   for ( Int_t i = 1; i <= nlboards; ++i )
668   {
669     AliMUONVCalibParam* localBoard = new AliMUONCalibParam1I(8);
670     for ( Int_t x = 0; x < 2; ++x )
671     {
672       for ( Int_t y = 0; y < 4; ++y )
673       {
674         Int_t index = x*4+y;
675         localBoard->SetValueAsInt(index,0,0xFFFF);
676       }
677     }
678     localBoardMasks->Set(i,localBoard,kFALSE);
679   }
680   
681   // Generate values for regional boards
682   const Int_t nrboards = 16;
683   AliMUONV1DStore* regionalBoardMasks = new AliMUON1DArray(16);
684   
685   for ( Int_t i = 0; i < nrboards; ++i )
686   {
687     AliMUONVCalibParam* regionalBoard = new AliMUONCalibParam1I(16);
688     for ( Int_t j = 0; j < 16; ++j )
689     {
690       regionalBoard->SetValueAsInt(j,0,0x3F);
691     }
692     regionalBoardMasks->Set(i,regionalBoard,kFALSE);
693   }
694   
695   // Generate values for global board
696   AliMUONVCalibParam* globalBoardMasks = new AliMUONCalibParam1I(16);
697   
698   for ( Int_t j = 0; j < 16; ++j )
699   {
700     globalBoardMasks->SetValueAsInt(j,0,0xFFF);
701   }
702     
703   AliMUONTriggerLut lut;
704   lut.ReadFromFile("$(ALICE_ROOT)/MUON/data/lutAptLpt1Hpt1p7.root");
705   
706   AliMUONTriggerEfficiencyCells cells("$ALICE_ROOT/MUON/data/efficiencyCells.dat");
707   
708   //--------------------------------------------
709   // Store the resulting containers into the CDB
710   Int_t ever = 99999999;
711   
712   AliCDBId id("MUON/Calib/LocalTriggerBoardMasks",0,ever);
713   
714   AliCDBMetaData md;
715   md.SetBeamPeriod(1);
716   md.SetAliRootVersion(gROOT->GetVersion());
717   md.SetComment("Test with default values");
718   md.SetResponsible("Rachid Guernane");
719   
720   AliCDBManager* man = AliCDBManager::Instance();
721   man->SetDefaultStorage(cdbpath);
722   man->Put(localBoardMasks,id,&md);
723   
724   id.SetPath("MUON/Calib/RegionalTriggerBoardMasks");
725   
726   man->Put(regionalBoardMasks,id,(AliCDBMetaData*)md.Clone());
727   
728   id.SetPath("MUON/Calib/GlobalTriggerBoardMasks");
729   
730   man->Put(globalBoardMasks,id,(AliCDBMetaData*)md.Clone());
731
732   id.SetPath("MUON/Calib/TriggerLut");
733   
734   man->Put(&lut,id,(AliCDBMetaData*)md.Clone());
735   
736   id.SetPath("MUON/Calib/TriggerEfficiency");
737   md.SetResponsible("Diego Stocco");
738   
739   man->Put(&cells,id,(AliCDBMetaData*)md.Clone());
740   
741   delete localBoardMasks;
742   delete regionalBoardMasks;
743   delete globalBoardMasks;
744 }
745
746
747 //_____________________________________________________________________________
748 void writeToCDB(const char* cdbpath, const char* calibpath, TObject* object, 
749                 Int_t startRun, Int_t endRun, Bool_t defaultValues)
750 {
751   AliCDBId id(calibpath,startRun,endRun);
752   AliCDBMetaData md;
753   md.SetBeamPeriod(1);
754   md.SetAliRootVersion(gROOT->GetVersion());
755   if ( defaultValues )
756   {
757     md.SetComment("Test with default values");
758   }
759   else
760   {
761     md.SetComment("Test with random values");
762   }
763   md.SetResponsible("Laurent Aphecetche");
764   
765   AliCDBManager* man = AliCDBManager::Instance();
766   man->SetDefaultStorage(cdbpath);
767   man->Put(object,id,&md);
768 }
769
770 //_____________________________________________________________________________
771 void writePedestals(const char* cdbpath, Bool_t defaultValues,
772                     Int_t startRun, Int_t endRun)
773 {
774   AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
775   Int_t ngenerated = makePedestalStore(*pedestalStore,defaultValues);
776   cout << "Ngenerated = " << ngenerated << endl;
777   
778   writeToCDB(cdbpath,"MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
779 }
780
781 //_____________________________________________________________________________
782 void writeGains(const char* cdbpath, Bool_t defaultValues,
783                     Int_t startRun, Int_t endRun)
784 {
785   AliMUONV2DStore* gainStore = new AliMUON2DMap;
786   Int_t ngenerated = makeGainStore(*gainStore,defaultValues);
787   cout << "Ngenerated = " << ngenerated << endl;
788   
789   writeToCDB(cdbpath,"MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
790 }
791
792 //_____________________________________________________________________________
793 void writeDeadChannels(const char* cdbpath, Bool_t defaultValues,
794                        Int_t startRun, Int_t endRun)
795 {
796   AliMUONV2DStore* deadStore = new AliMUON2DMap;
797   Int_t ngenerated = makeDeadStore(*deadStore,defaultValues);
798   cout << "Ngenerated = " << ngenerated << endl;
799   
800   writeToCDB(cdbpath,"MUON/Calib/DeadChannels",deadStore,startRun,endRun,defaultValues);
801 }
802
803