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