Removing validation stage, which will probably be handled in the online DA (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"
ea199e33 28#include "AliMUONCalibParam2F.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"
ea199e33 35
36///
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
47///
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{
60 // default ctor
61}
62
63//_____________________________________________________________________________
64AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
65{
66 // dtor
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());
ea199e33 94 if (!ok)
95 {
d2db856e 96 Master()->Log(Form("Could not read file %s",fileName.Data()));
ea199e33 97 }
703d8257 98 else
99 {
100 n += ok;
101 }
102 }
103
104 if (!n)
105 {
106 Master()->Log("Failed to read any pedestals");
107 delete fPedestals;
108 fPedestals = 0;
ea199e33 109 }
110 delete sources;
111}
112
113//_____________________________________________________________________________
114UInt_t
115AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
116{
117 // Store the pedestals into the CDB
118
119 if (!fPedestals) return 0;
703d8257 120
3b32651c 121 Master()->Log("Storing pedestals");
ea199e33 122
123 AliCDBMetaData metaData;
124 metaData.SetBeamPeriod(0);
125 metaData.SetResponsible("MUON TRK");
126 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
127
3b32651c 128 Bool_t validToInfinity = kTRUE;
129 UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
ea199e33 130
131 return result;
132}
133
134//_____________________________________________________________________________
703d8257 135Int_t
ea199e33 136AliMUONPedestalSubprocessor::ReadFile(const char* filename)
137{
138 // Read the pedestals from an ASCII file.
139 // Format of that file is one line per channel :
140 //---------------------------------------------------------------------------
141 // BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA
142 //---------------------------------------------------------------------------
143 //
144 // Return kFALSE if reading was not successfull.
145 //
146
d2db856e 147 TString sFilename(gSystem->ExpandPathName(filename));
ea199e33 148
d2db856e 149 Master()->Log(Form("Reading %s",sFilename.Data()));
ea199e33 150
d2db856e 151 std::ifstream in(sFilename.Data());
152 if (!in.good())
153 {
703d8257 154 return 0;
d2db856e 155 }
ea199e33 156 char line[80];
157 Int_t busPatchID, manuID, manuChannel;
158 Float_t pedMean, pedSigma;
ea199e33 159 static const Int_t kNchannels(64);
160 static Bool_t replace(kFALSE);
703d8257 161 Int_t n(0);
ea199e33 162
163 while ( in.getline(line,80) )
164 {
165 if ( line[0] == '/' && line[1] == '/' ) continue;
166 std::istringstream sin(line);
167 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
e5ced899 168 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
ea199e33 169 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
170 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
171
172 AliMUONVCalibParam* ped =
173 static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
174
175 if (!ped)
176 {
177 ped = new AliMUONCalibParam2F(kNchannels,AliMUONCalibParam2F::InvalidFloatValue());
178 fPedestals->Set(detElemID,manuID,ped,replace);
179 }
180 ped->SetValueAsFloat(manuChannel,0,pedMean);
181 ped->SetValueAsFloat(manuChannel,1,pedSigma);
703d8257 182 ++n;
ea199e33 183 }
184 in.close();
703d8257 185 return n;
ea199e33 186}
187
188
189//_____________________________________________________________________________
190void
191AliMUONPedestalSubprocessor::Print(Option_t* opt) const
192{
193 /// ouput to screen
194 AliMUONVDataIterator* it = fPedestals->Iterator();
195 AliMUONObjectPair* p;
196
197 while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
198 {
199 AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());
200 value->Print(opt);
201 }
202}