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 "AliMUONGainSubprocessor.h"
20 #include "AliCDBMetaData.h"
22 #include "AliMUON2DMap.h"
23 #include "AliMUON2DStoreValidator.h"
24 #include "AliMUONCalibParamNF.h"
25 #include "AliMUONConstants.h"
26 #include "AliMUONPreprocessor.h"
27 #include "AliMpConstants.h"
28 #include "AliMpDDLStore.h"
29 #include <Riostream.h>
31 #include <TObjString.h>
32 #include <TObjString.h>
36 //-----------------------------------------------------------------------------
37 /// \class AliMUONGainSubprocessor
39 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK Gains.
41 /// Gains are read in from an ascii file, with the format :
43 ///---------------------------------------------------------------------------
45 ///BUS_PATCH MANU CHANNEL a0 a1 thres Qual
47 ///---------------------------------------------------------------------------
49 /// \author L. Aphecetche
51 //-----------------------------------------------------------------------------
54 ClassImp(AliMUONGainSubprocessor)
57 //_____________________________________________________________________________
58 AliMUONGainSubprocessor::AliMUONGainSubprocessor(AliMUONPreprocessor* master)
59 : AliMUONVSubprocessor(master,
61 "Upload MUON Tracker Gains to OCDB"),
67 //_____________________________________________________________________________
68 AliMUONGainSubprocessor::~AliMUONGainSubprocessor()
74 //_____________________________________________________________________________
76 AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
78 /// When starting a new run, reads in the Gains ASCII files.
80 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
81 const char* kId = "GAINS";
84 fGains = new AliMUON2DMap(kTRUE);
86 Master()->Log(Form("Reading Gain files for Run %d startTime %ld endTime %ld",
87 run,startTime,endTime));
89 TList* sources = Master()->GetFileSources(kSystem,kId);
94 while ( ( o = static_cast<TObjString*>(next()) ) )
96 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
97 Int_t ok = ReadFile(fileName.Data());
100 Master()->Log(Form("Could not read file %s",fileName.Data()));
110 Master()->Log("Failed to read any Gains");
117 //_____________________________________________________________________________
119 AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/)
121 /// Store the Gains into the CDB
125 // this is the only reason to fail for the moment : getting no Gain
130 AliMUON2DStoreValidator validator;
132 Master()->Log("Validating");
134 TObjArray* chambers = validator.Validate(*fGains);
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
141 lines.SetOwner(kTRUE);
143 validator.Report(lines,*chambers);
148 while ( ( line = static_cast<TObjString*>(next()) ) )
150 Master()->Log(line->String().Data());
154 Master()->Log("Storing Gains");
156 AliCDBMetaData metaData;
157 metaData.SetBeamPeriod(0);
158 metaData.SetResponsible("MUON TRK");
159 metaData.SetComment("Computed by AliMUONGainSubprocessor $Id$");
161 Bool_t validToInfinity = kTRUE;
162 Bool_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
164 return ( result != kTRUE ); // return 0 if everything is ok
167 //_____________________________________________________________________________
169 AliMUONGainSubprocessor::ReadFile(const char* filename)
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 ///-------------------------------------------------------------------------
177 /// Return kFALSE if reading was not successfull.
180 TString sFilename(gSystem->ExpandPathName(filename));
182 Master()->Log(Form("Reading %s",sFilename.Data()));
184 std::ifstream in(sFilename.Data());
190 Int_t busPatchID, manuID, manuChannel;
194 const Int_t kSaturation(3000); // FIXME: how to get this number ?
196 static const Int_t kNchannels(AliMpConstants::ManuNofChannels());
199 while ( in.getline(line,1024) )
201 if ( strlen(line) < 10 ) continue;
202 if ( line[0] == '/' && line[1] == '/' ) continue;
204 sscanf(line,"%d %d %d %f %f %d %x",&busPatchID,&manuID,&manuChannel,
205 &a0,&a1,&thres,&qual);
206 AliDebug(3,Form("line=%s",line));
207 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
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;
213 AliMUONVCalibParam* gain =
214 static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemID,manuID));
218 gain = new AliMUONCalibParamNF(5,kNchannels,detElemID,manuID,0);
221 gain->SetValueAsFloat(manuChannel,0,a0);
222 gain->SetValueAsFloat(manuChannel,1,a1);
223 gain->SetValueAsInt(manuChannel,2,thres);
224 gain->SetValueAsInt(manuChannel,3,qual);
225 gain->SetValueAsInt(manuChannel,4,kSaturation);