remoe duplicate QA initialisation and do ESD QA for same detectors as RecPoint QA
[u/mrichter/AliRoot.git] / MUON / AliMUONPedestalSubprocessor.cxx
CommitLineData
ea199e33 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
8d8e920c 18#include "AliMUONPedestalSubprocessor.h"
ea199e33 19
20#include "AliCDBMetaData.h"
21#include "AliLog.h"
22#include "AliMUON2DMap.h"
8d8e920c 23#include "AliMUON2DStoreValidator.h"
a8f77ca0 24#include "AliMUONCalibParamNF.h"
ea199e33 25#include "AliMUONPreprocessor.h"
81028269 26#include "AliMUONTrackerIO.h"
8d8e920c 27#include "AliMpConstants.h"
7ca4655f 28#include "AliMpDDLStore.h"
a8f77ca0 29#include "TObjString.h"
8d8e920c 30#include <Riostream.h>
31#include <TList.h>
32#include <TObjString.h>
33#include <TSystem.h>
34#include <sstream>
ea199e33 35
3d1463c8 36//-----------------------------------------------------------------------------
ea199e33 37/// \class AliMUONPedestalSubprocessor
38///
39/// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
40///
41/// Pedestals are read in from an ascii file, with the format : \n
42///---------------------------------------------------------------------------\n
43/// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
44///---------------------------------------------------------------------------\n
45///
46/// \author L. Aphecetche
3d1463c8 47//-----------------------------------------------------------------------------
ea199e33 48
49/// \cond CLASSIMP
50ClassImp(AliMUONPedestalSubprocessor)
51/// \endcond
52
53//_____________________________________________________________________________
54AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
55: AliMUONVSubprocessor(master,
56 "Pedestals",
57 "Upload MUON Tracker pedestals to OCDB"),
58fPedestals(0x0)
59{
71a2d3aa 60 /// default ctor
ea199e33 61}
62
63//_____________________________________________________________________________
64AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
65{
71a2d3aa 66 /// dtor
ea199e33 67 delete fPedestals;
68}
69
70//_____________________________________________________________________________
71void
72AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
73{
74 /// When starting a new run, reads in the pedestals ASCII files.
75
76 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
77 const char* kId = "PEDESTALS";
78
79 delete fPedestals;
80 fPedestals = new AliMUON2DMap(kTRUE);
81
d2db856e 82 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
83 run,startTime,endTime));
ea199e33 84
85 TList* sources = Master()->GetFileSources(kSystem,kId);
86 TIter next(sources);
87 TObjString* o(0x0);
703d8257 88 Int_t n(0);
89
ea199e33 90 while ( ( o = static_cast<TObjString*>(next()) ) )
91 {
92 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
703d8257 93 Int_t ok = ReadFile(fileName.Data());
81028269 94 if (ok>0)
703d8257 95 {
96 n += ok;
97 }
98 }
99
100 if (!n)
101 {
102 Master()->Log("Failed to read any pedestals");
103 delete fPedestals;
104 fPedestals = 0;
ea199e33 105 }
106 delete sources;
107}
108
109//_____________________________________________________________________________
110UInt_t
111AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
112{
71a2d3aa 113 /// Store the pedestals into the CDB
ea199e33 114
a8f77ca0 115 if (!fPedestals)
116 {
117 // this is the only reason to fail for the moment : getting no pedestal
118 // at all.
d489129d 119 return 1;
a8f77ca0 120 }
703d8257 121
a8f77ca0 122 AliMUON2DStoreValidator validator;
123
124 Master()->Log("Validating");
125
126 TObjArray* chambers = validator.Validate(*fPedestals);
127
128 if (chambers)
129 {
130 // we hereby report what's missing, but this is not a reason to fail ;-)
131 // the only reason to fail would be if we got no pedestal at all
132 TList lines;
133 lines.SetOwner(kTRUE);
134
135 validator.Report(lines,*chambers);
136
137 TIter next(&lines);
138 TObjString* line;
139
140 while ( ( line = static_cast<TObjString*>(next()) ) )
141 {
142 Master()->Log(line->String().Data());
143 }
144 }
145
3b32651c 146 Master()->Log("Storing pedestals");
ea199e33 147
148 AliCDBMetaData metaData;
149 metaData.SetBeamPeriod(0);
150 metaData.SetResponsible("MUON TRK");
151 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
152
3b32651c 153 Bool_t validToInfinity = kTRUE;
d489129d 154 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
ea199e33 155
d489129d 156 return ( result != kTRUE ); // return 0 if everything is ok.
ea199e33 157}
158
159//_____________________________________________________________________________
703d8257 160Int_t
ea199e33 161AliMUONPedestalSubprocessor::ReadFile(const char* filename)
162{
71a2d3aa 163 /// Read the pedestals from an ASCII file. \n
164 /// Format of that file is one line per channel : \n
165 ///-------------------------------------------------------------------------\n
166 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
167 ///-------------------------------------------------------------------------\n
168 /// \n
169 /// Return kFALSE if reading was not successfull. \n
170 ///
ea199e33 171
d2db856e 172 TString sFilename(gSystem->ExpandPathName(filename));
ea199e33 173
d2db856e 174 Master()->Log(Form("Reading %s",sFilename.Data()));
ea199e33 175
81028269 176 Int_t n = AliMUONTrackerIO::ReadPedestals(sFilename.Data(),*fPedestals);
ea199e33 177
81028269 178 switch (n)
ea199e33 179 {
81028269 180 case -1:
181 Master()->Log(Form("Could not open %s",sFilename.Data()));
182 break;
ea199e33 183 }
2a7274d9 184
703d8257 185 return n;
ea199e33 186}
187
188
189//_____________________________________________________________________________
190void
191AliMUONPedestalSubprocessor::Print(Option_t* opt) const
192{
193 /// ouput to screen
8d8e920c 194 if (fPedestals) fPedestals->Print("",opt);
ea199e33 195}