1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUON2DMap.h"
19 #include "AliMUONCalibParamNF.h"
20 #include "AliMUONConstants.h"
21 #include "AliMUONObjectPair.h"
22 #include "AliMUONGainSubprocessor.h"
23 #include "AliMUONPreprocessor.h"
24 #include "AliMUONVDataIterator.h"
25 #include "AliMpDDLStore.h"
26 #include "AliMUON2DStoreValidator.h"
28 #include "AliCDBMetaData.h"
31 #include <TObjString.h>
32 #include <Riostream.h>
34 #include <TObjString.h>
40 /// \class AliMUONGainSubprocessor
42 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK Gains.
44 /// Gains are read in from an ascii file, with the format : \n
45 ///---------------------------------------------------------------------------\n
46 ///BUS_PATCH MANU CHANNEL Ped. a0 a1 a2 xlim P(chi2) P(chi2)_2 \n
47 ///---------------------------------------------------------------------------\n
49 /// \author L. Aphecetche
53 ClassImp(AliMUONGainSubprocessor)
56 //_____________________________________________________________________________
57 AliMUONGainSubprocessor::AliMUONGainSubprocessor(AliMUONPreprocessor* master)
58 : AliMUONVSubprocessor(master,
60 "Upload MUON Tracker Gains to OCDB"),
66 //_____________________________________________________________________________
67 AliMUONGainSubprocessor::~AliMUONGainSubprocessor()
73 //_____________________________________________________________________________
75 AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
77 /// When starting a new run, reads in the Gains ASCII files.
79 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
80 const char* kId = "GAINS";
83 fGains = new AliMUON2DMap(kTRUE);
85 Master()->Log(Form("Reading Gain files for Run %d startTime %ld endTime %ld",
86 run,startTime,endTime));
88 TList* sources = Master()->GetFileSources(kSystem,kId);
93 while ( ( o = static_cast<TObjString*>(next()) ) )
95 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
96 Int_t ok = ReadFile(fileName.Data());
99 Master()->Log(Form("Could not read file %s",fileName.Data()));
109 Master()->Log("Failed to read any Gains");
116 //_____________________________________________________________________________
118 AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/)
120 /// Store the Gains into the CDB
124 // this is the only reason to fail for the moment : getting no Gain
129 AliMUON2DStoreValidator validator;
131 Master()->Log("Validating");
133 TObjArray* chambers = validator.Validate(*fGains);
137 // we hereby report what's missing, but this is not a reason to fail ;-)
138 // the only reason to fail would be if we got no Gain at all
140 lines.SetOwner(kTRUE);
142 validator.Report(lines,*chambers);
147 while ( ( line = static_cast<TObjString*>(next()) ) )
149 Master()->Log(line->String().Data());
153 Master()->Log("Storing Gains");
155 AliCDBMetaData metaData;
156 metaData.SetBeamPeriod(0);
157 metaData.SetResponsible("MUON TRK");
158 metaData.SetComment("Computed by AliMUONGainSubprocessor $Id$");
160 Bool_t validToInfinity = kTRUE;
161 UInt_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
166 //_____________________________________________________________________________
168 AliMUONGainSubprocessor::ReadFile(const char* filename)
170 /// Read the Gains from an ASCII file. \n
171 /// Format of that file is one line per channel : \n
172 ///-------------------------------------------------------------------------\n
173 ///BUS_PATCH MANU CHANNEL Ped. a0 a1 a2 xlim P(chi2) P(chi2)_2 \n
174 ///-------------------------------------------------------------------------\n
176 /// Return kFALSE if reading was not successfull. \n
179 TString sFilename(gSystem->ExpandPathName(filename));
181 Master()->Log(Form("Reading %s",sFilename.Data()));
183 std::ifstream in(sFilename.Data());
189 Int_t busPatchID, manuID, manuChannel;
195 static const Int_t kNchannels(64);
196 static Bool_t replace(kFALSE);
199 while ( in.getline(line,256) )
201 if ( strlen(line) < 10 ) continue;
202 if ( line[0] == '/' && line[1] == '/' ) continue;
203 std::istringstream sin(line);
204 AliDebug(3,Form("line=%s",line));
205 sin >> busPatchID >> manuID >> manuChannel >> ped >> a0 >> a1 >> a2 >> xlim >> chi2 >> chi22;
206 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
207 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d PED %7.2f A0 %7.2f A1 %7.2f A2 %7.2f"
208 " XLIM %7.2f CHI2 %7.2f CHI22 %7.2f",
209 busPatchID,detElemID,manuID,manuChannel,ped,a0,a1,a2,xlim,chi2,chi22));
210 if ( a0==a1 && a1==a2 && a0==-2) continue;
212 AliMUONVCalibParam* gain =
213 static_cast<AliMUONVCalibParam*>(fGains->Get(detElemID,manuID));
217 gain = new AliMUONCalibParamNF(6,kNchannels,0);//AliMUONVCalibParam::InvalidFloatValue());
218 fGains->Set(detElemID,manuID,gain,replace);
220 gain->SetValueAsFloat(manuChannel,0,a0);
221 gain->SetValueAsFloat(manuChannel,1,a1);
222 gain->SetValueAsFloat(manuChannel,2,a2);
223 gain->SetValueAsFloat(manuChannel,3,xlim);
224 gain->SetValueAsFloat(manuChannel,4,chi2);
225 gain->SetValueAsFloat(manuChannel,5,chi22);
233 //_____________________________________________________________________________
235 AliMUONGainSubprocessor::Print(Option_t* opt) const
238 AliMUONVDataIterator* it = fGains->Iterator();
239 AliMUONObjectPair* p;
241 while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
243 AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());