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>
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
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 Bool_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
163 return ( result != kTRUE ); // return 0 if everything is ok
166 //_____________________________________________________________________________
168 AliMUONGainSubprocessor::ReadFile(const char* filename)
170 /// Read the Gains from an ASCII file.
171 /// Format of that file is one line per channel :
172 ///-------------------------------------------------------------------------
173 ///BUS_PATCH MANU CHANNEL a0 a1 thres Qual
174 ///-------------------------------------------------------------------------
176 /// Return kFALSE if reading was not successfull.
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;
193 const Int_t kSaturation(3000); // FIXME: how to get this number ?
195 static const Int_t kNchannels(AliMpConstants::ManuNofChannels());
198 while ( in.getline(line,256) )
200 if ( strlen(line) < 10 ) continue;
201 if ( line[0] == '/' && line[1] == '/' ) continue;
203 sscanf(line,"%d %d %d %f %f %d %x",&busPatchID,&manuID,&manuChannel,
204 &a0,&a1,&thres,&qual);
205 AliDebug(3,Form("line=%s",line));
206 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
207 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d A0 %7.2f "
208 "A1 %e THRES %5d QUAL %x",
209 busPatchID,detElemID,manuID,manuChannel,a0,a1,thres,qual));
210 if ( qual == 0 ) continue;
212 AliMUONVCalibParam* gain =
213 static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemID,manuID));
217 gain = new AliMUONCalibParamNF(5,kNchannels,detElemID,manuID,0);
220 gain->SetValueAsFloat(manuChannel,0,a0);
221 gain->SetValueAsFloat(manuChannel,1,a1);
222 gain->SetValueAsInt(manuChannel,2,thres);
223 gain->SetValueAsInt(manuChannel,3,qual);
224 gain->SetValueAsInt(manuChannel,4,kSaturation);