]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPedestalSubprocessor.cxx
Adding handling of Capacitances (Laurent)
[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
7ca4655f 18#include <sstream>
19
20#include <Riostream.h>
21#include <TList.h>
22#include <TObjString.h>
23#include <TSystem.h>
ea199e33 24
25#include "AliCDBMetaData.h"
26#include "AliLog.h"
27#include "AliMUON2DMap.h"
a8f77ca0 28#include "AliMUONCalibParamNF.h"
ea199e33 29#include "AliMUONConstants.h"
30#include "AliMUONObjectPair.h"
7ca4655f 31#include "AliMUONPedestalSubprocessor.h"
ea199e33 32#include "AliMUONPreprocessor.h"
7ca4655f 33#include "AliMUONVDataIterator.h"
34#include "AliMpDDLStore.h"
a8f77ca0 35#include "AliMUON2DStoreValidator.h"
36#include "TObjString.h"
ea199e33 37
38///
39/// \class AliMUONPedestalSubprocessor
40///
41/// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
42///
43/// Pedestals are read in from an ascii file, with the format : \n
44///---------------------------------------------------------------------------\n
45/// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
46///---------------------------------------------------------------------------\n
47///
48/// \author L. Aphecetche
49///
50
51/// \cond CLASSIMP
52ClassImp(AliMUONPedestalSubprocessor)
53/// \endcond
54
55//_____________________________________________________________________________
56AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
57: AliMUONVSubprocessor(master,
58 "Pedestals",
59 "Upload MUON Tracker pedestals to OCDB"),
60fPedestals(0x0)
61{
71a2d3aa 62 /// default ctor
ea199e33 63}
64
65//_____________________________________________________________________________
66AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
67{
71a2d3aa 68 /// dtor
ea199e33 69 delete fPedestals;
70}
71
72//_____________________________________________________________________________
73void
74AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
75{
76 /// When starting a new run, reads in the pedestals ASCII files.
77
78 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
79 const char* kId = "PEDESTALS";
80
81 delete fPedestals;
82 fPedestals = new AliMUON2DMap(kTRUE);
83
d2db856e 84 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
85 run,startTime,endTime));
ea199e33 86
87 TList* sources = Master()->GetFileSources(kSystem,kId);
88 TIter next(sources);
89 TObjString* o(0x0);
703d8257 90 Int_t n(0);
91
ea199e33 92 while ( ( o = static_cast<TObjString*>(next()) ) )
93 {
94 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
703d8257 95 Int_t ok = ReadFile(fileName.Data());
ea199e33 96 if (!ok)
97 {
d2db856e 98 Master()->Log(Form("Could not read file %s",fileName.Data()));
ea199e33 99 }
703d8257 100 else
101 {
102 n += ok;
103 }
104 }
105
106 if (!n)
107 {
108 Master()->Log("Failed to read any pedestals");
109 delete fPedestals;
110 fPedestals = 0;
ea199e33 111 }
112 delete sources;
113}
114
115//_____________________________________________________________________________
116UInt_t
117AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
118{
71a2d3aa 119 /// Store the pedestals into the CDB
ea199e33 120
a8f77ca0 121 if (!fPedestals)
122 {
123 // this is the only reason to fail for the moment : getting no pedestal
124 // at all.
125 return 0;
126 }
703d8257 127
a8f77ca0 128 AliMUON2DStoreValidator validator;
129
130 Master()->Log("Validating");
131
132 TObjArray* chambers = validator.Validate(*fPedestals);
133
134 if (chambers)
135 {
136 // we hereby report what's missing, but this is not a reason to fail ;-)
137 // the only reason to fail would be if we got no pedestal at all
138 TList lines;
139 lines.SetOwner(kTRUE);
140
141 validator.Report(lines,*chambers);
142
143 TIter next(&lines);
144 TObjString* line;
145
146 while ( ( line = static_cast<TObjString*>(next()) ) )
147 {
148 Master()->Log(line->String().Data());
149 }
150 }
151
3b32651c 152 Master()->Log("Storing pedestals");
ea199e33 153
154 AliCDBMetaData metaData;
155 metaData.SetBeamPeriod(0);
156 metaData.SetResponsible("MUON TRK");
157 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
158
3b32651c 159 Bool_t validToInfinity = kTRUE;
160 UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
ea199e33 161
162 return result;
163}
164
165//_____________________________________________________________________________
703d8257 166Int_t
ea199e33 167AliMUONPedestalSubprocessor::ReadFile(const char* filename)
168{
71a2d3aa 169 /// Read the pedestals from an ASCII file. \n
170 /// Format of that file is one line per channel : \n
171 ///-------------------------------------------------------------------------\n
172 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
173 ///-------------------------------------------------------------------------\n
174 /// \n
175 /// Return kFALSE if reading was not successfull. \n
176 ///
ea199e33 177
d2db856e 178 TString sFilename(gSystem->ExpandPathName(filename));
ea199e33 179
d2db856e 180 Master()->Log(Form("Reading %s",sFilename.Data()));
ea199e33 181
d2db856e 182 std::ifstream in(sFilename.Data());
183 if (!in.good())
184 {
703d8257 185 return 0;
d2db856e 186 }
ea199e33 187 char line[80];
188 Int_t busPatchID, manuID, manuChannel;
189 Float_t pedMean, pedSigma;
ea199e33 190 static const Int_t kNchannels(64);
191 static Bool_t replace(kFALSE);
703d8257 192 Int_t n(0);
ea199e33 193
194 while ( in.getline(line,80) )
195 {
196 if ( line[0] == '/' && line[1] == '/' ) continue;
197 std::istringstream sin(line);
198 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
e5ced899 199 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
ea199e33 200 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
201 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
202
203 AliMUONVCalibParam* ped =
204 static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
205
206 if (!ped)
207 {
a8f77ca0 208 ped = new AliMUONCalibParamNF(2,kNchannels,AliMUONVCalibParam::InvalidFloatValue());
ea199e33 209 fPedestals->Set(detElemID,manuID,ped,replace);
210 }
211 ped->SetValueAsFloat(manuChannel,0,pedMean);
212 ped->SetValueAsFloat(manuChannel,1,pedSigma);
703d8257 213 ++n;
ea199e33 214 }
215 in.close();
703d8257 216 return n;
ea199e33 217}
218
219
220//_____________________________________________________________________________
221void
222AliMUONPedestalSubprocessor::Print(Option_t* opt) const
223{
224 /// ouput to screen
225 AliMUONVDataIterator* it = fPedestals->Iterator();
226 AliMUONObjectPair* p;
227
228 while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
229 {
230 AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());
231 value->Print(opt);
232 }
233}