]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONGainSubprocessor.cxx
Ensure vacuum inside the beam pipe for upgrade (Mario)
[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"
81028269 27#include "AliMUONTrackerIO.h"
8d8e920c 28#include "AliMpConstants.h"
505bc496 29#include "AliMpDDLStore.h"
505bc496 30#include <Riostream.h>
31#include <TList.h>
32#include <TObjString.h>
8d8e920c 33#include <TObjString.h>
505bc496 34#include <TSystem.h>
505bc496 35#include <sstream>
36
3d1463c8 37//-----------------------------------------------------------------------------
505bc496 38/// \class AliMUONGainSubprocessor
39///
40/// Implementation of AliMUONVSubprocessor class to deal with MUON TRK Gains.
41///
cf27231a 42/// Gains are read in from an ascii file, with the format :
43///
44///---------------------------------------------------------------------------
45///
46///BUS_PATCH MANU CHANNEL a0 a1 thres Qual
47///
48///---------------------------------------------------------------------------
505bc496 49///
50/// \author L. Aphecetche
51///
3d1463c8 52//-----------------------------------------------------------------------------
505bc496 53
54/// \cond CLASSIMP
55ClassImp(AliMUONGainSubprocessor)
56/// \endcond
57
58//_____________________________________________________________________________
59AliMUONGainSubprocessor::AliMUONGainSubprocessor(AliMUONPreprocessor* master)
60: AliMUONVSubprocessor(master,
61 "Gains",
62 "Upload MUON Tracker Gains to OCDB"),
81028269 63fGains(0x0),
64fSkip(kFALSE),
65fComment("")
505bc496 66{
67 /// default ctor
68}
69
70//_____________________________________________________________________________
71AliMUONGainSubprocessor::~AliMUONGainSubprocessor()
72{
73 /// dtor
74 delete fGains;
75}
76
77//_____________________________________________________________________________
6c870207 78Bool_t
505bc496 79AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
80{
81 /// When starting a new run, reads in the Gains ASCII files.
82
83 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
84 const char* kId = "GAINS";
85
81028269 86 fComment = "";
87 fSkip = kFALSE;
88
505bc496 89 delete fGains;
90 fGains = new AliMUON2DMap(kTRUE);
91
1130977f 92 Master()->Log(Form("Reading Gain files for Run %d startTime %u endTime %u",
505bc496 93 run,startTime,endTime));
94
95 TList* sources = Master()->GetFileSources(kSystem,kId);
96 TIter next(sources);
97 TObjString* o(0x0);
98 Int_t n(0);
99
100 while ( ( o = static_cast<TObjString*>(next()) ) )
101 {
102 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
103 Int_t ok = ReadFile(fileName.Data());
81028269 104 if (ok>0)
505bc496 105 {
81028269 106 n += ok;
505bc496 107 }
81028269 108 else if ( ok == AliMUONTrackerIO::kDummyFile )
505bc496 109 {
81028269 110 // not an interesting file.
111 fSkip = kTRUE;
112 break;
505bc496 113 }
114 }
115
6c870207 116 delete sources;
117
81028269 118 if ( fSkip )
119 {
120 delete fGains;
121 fGains = 0x0;
122 }
123
124 if (!n && !fSkip)
505bc496 125 {
126 Master()->Log("Failed to read any Gains");
127 delete fGains;
81028269 128 fGains = 0x0;
6c870207 129 return kFALSE;
505bc496 130 }
81028269 131
6c870207 132 return kTRUE;
505bc496 133}
134
135//_____________________________________________________________________________
136UInt_t
137AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/)
138{
139 /// Store the Gains into the CDB
140
141 if (!fGains)
142 {
143 // this is the only reason to fail for the moment : getting no Gain
81028269 144 // at all, except if the input file was a dummy one
145 if ( fSkip )
146 {
147 return 0;
148 }
149 else
150 {
151 return 1;
152 }
505bc496 153 }
154
155 AliMUON2DStoreValidator validator;
156
157 Master()->Log("Validating");
158
159 TObjArray* chambers = validator.Validate(*fGains);
160
161 if (chambers)
162 {
163 // we hereby report what's missing, but this is not a reason to fail ;-)
164 // the only reason to fail would be if we got no Gain at all
165 TList lines;
166 lines.SetOwner(kTRUE);
167
168 validator.Report(lines,*chambers);
169
170 TIter next(&lines);
171 TObjString* line;
172
173 while ( ( line = static_cast<TObjString*>(next()) ) )
174 {
175 Master()->Log(line->String().Data());
176 }
177 }
178
179 Master()->Log("Storing Gains");
180
181 AliCDBMetaData metaData;
182 metaData.SetBeamPeriod(0);
183 metaData.SetResponsible("MUON TRK");
49419555 184 metaData.SetComment(Form("Computed by AliMUONGainSubprocessor "
185 "$Id$ ; %s",fComment.Data()));
505bc496 186
187 Bool_t validToInfinity = kTRUE;
d489129d 188 Bool_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
505bc496 189
d489129d 190 return ( result != kTRUE ); // return 0 if everything is ok
505bc496 191}
192
193//_____________________________________________________________________________
194Int_t
195AliMUONGainSubprocessor::ReadFile(const char* filename)
196{
cf27231a 197 /// Read the Gains from an ASCII file.
198 /// Format of that file is one line per channel :
199 ///-------------------------------------------------------------------------
200 ///BUS_PATCH MANU CHANNEL a0 a1 thres Qual
201 ///-------------------------------------------------------------------------
202 ///
203 /// Return kFALSE if reading was not successfull.
505bc496 204 ///
81028269 205
505bc496 206 TString sFilename(gSystem->ExpandPathName(filename));
207
208 Master()->Log(Form("Reading %s",sFilename.Data()));
81028269 209
210 Int_t n = AliMUONTrackerIO::ReadGains(sFilename.Data(),*fGains,fComment);
211
212 switch (n)
505bc496 213 {
81028269 214 case AliMUONTrackerIO::kCannotOpenFile:
215 Master()->Log(Form("Could not open %s",sFilename.Data()));
216 break;
217 case AliMUONTrackerIO::kFormatError:
218 Master()->Log(Form("File %s is not of the expected format",sFilename.Data()));
219 break;
220 case AliMUONTrackerIO::kDummyFile:
221 Master()->Log(Form("File %s is a dummy one. That's fine. I won't do anything then ;-)",sFilename.Data()));
222 break;
223 default:
224 break;
505bc496 225 }
505bc496 226
505bc496 227 return n;
228}