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 : \n
42 ///---------------------------------------------------------------------------\n
43 ///BUS_PATCH MANU CHANNEL Ped. a0 a1 a2 xlim P(chi2) P(chi2)_2 \n
44 ///---------------------------------------------------------------------------\n
46 /// \author L. Aphecetche
50 ClassImp(AliMUONGainSubprocessor)
53 //_____________________________________________________________________________
54 AliMUONGainSubprocessor::AliMUONGainSubprocessor(AliMUONPreprocessor* master)
55 : AliMUONVSubprocessor(master,
57 "Upload MUON Tracker Gains to OCDB"),
63 //_____________________________________________________________________________
64 AliMUONGainSubprocessor::~AliMUONGainSubprocessor()
70 //_____________________________________________________________________________
72 AliMUONGainSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
74 /// When starting a new run, reads in the Gains ASCII files.
76 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
77 const char* kId = "GAINS";
80 fGains = new AliMUON2DMap(kTRUE);
82 Master()->Log(Form("Reading Gain files for Run %d startTime %ld endTime %ld",
83 run,startTime,endTime));
85 TList* sources = Master()->GetFileSources(kSystem,kId);
90 while ( ( o = static_cast<TObjString*>(next()) ) )
92 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
93 Int_t ok = ReadFile(fileName.Data());
96 Master()->Log(Form("Could not read file %s",fileName.Data()));
106 Master()->Log("Failed to read any Gains");
113 //_____________________________________________________________________________
115 AliMUONGainSubprocessor::Process(TMap* /*dcsAliasMap*/)
117 /// Store the Gains into the CDB
121 // this is the only reason to fail for the moment : getting no Gain
126 AliMUON2DStoreValidator validator;
128 Master()->Log("Validating");
130 TObjArray* chambers = validator.Validate(*fGains);
134 // we hereby report what's missing, but this is not a reason to fail ;-)
135 // the only reason to fail would be if we got no Gain at all
137 lines.SetOwner(kTRUE);
139 validator.Report(lines,*chambers);
144 while ( ( line = static_cast<TObjString*>(next()) ) )
146 Master()->Log(line->String().Data());
150 Master()->Log("Storing Gains");
152 AliCDBMetaData metaData;
153 metaData.SetBeamPeriod(0);
154 metaData.SetResponsible("MUON TRK");
155 metaData.SetComment("Computed by AliMUONGainSubprocessor $Id$");
157 Bool_t validToInfinity = kTRUE;
158 Bool_t result = Master()->Store("Calib", "Gains", fGains, &metaData, 0, validToInfinity);
160 return ( result != kTRUE ); // return 0 if everything is ok
163 //_____________________________________________________________________________
165 AliMUONGainSubprocessor::ReadFile(const char* filename)
167 /// Read the Gains from an ASCII file. \n
168 /// Format of that file is one line per channel : \n
169 ///-------------------------------------------------------------------------\n
170 ///BUS_PATCH MANU CHANNEL Ped. a0 a1 a2 xlim P(chi2) P(chi2)_2 \n
171 ///-------------------------------------------------------------------------\n
173 /// Return kFALSE if reading was not successfull. \n
176 TString sFilename(gSystem->ExpandPathName(filename));
178 Master()->Log(Form("Reading %s",sFilename.Data()));
180 std::ifstream in(sFilename.Data());
186 Int_t busPatchID, manuID, manuChannel;
192 static const Int_t kNchannels(AliMpConstants::ManuNofChannels());
195 while ( in.getline(line,256) )
197 if ( strlen(line) < 10 ) continue;
198 if ( line[0] == '/' && line[1] == '/' ) continue;
199 std::istringstream sin(line);
200 AliDebug(3,Form("line=%s",line));
201 sin >> busPatchID >> manuID >> manuChannel >> ped >> a0 >> a1 >> a2 >> xlim >> chi2 >> chi22;
202 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
203 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d PED %7.2f A0 %7.2f A1 %7.2f A2 %7.2f"
204 " XLIM %7.2f CHI2 %7.2f CHI22 %7.2f",
205 busPatchID,detElemID,manuID,manuChannel,ped,a0,a1,a2,xlim,chi2,chi22));
206 if ( a0==a1 && a1==a2 && a0==-2) continue;
208 AliMUONVCalibParam* gain =
209 static_cast<AliMUONVCalibParam*>(fGains->FindObject(detElemID,manuID));
213 gain = new AliMUONCalibParamNF(6,detElemID,manuID,kNchannels,0);
216 gain->SetValueAsFloat(manuChannel,0,a0);
217 gain->SetValueAsFloat(manuChannel,1,a1);
218 gain->SetValueAsFloat(manuChannel,2,a2);
219 gain->SetValueAsFloat(manuChannel,3,xlim);
220 gain->SetValueAsFloat(manuChannel,4,chi2);
221 gain->SetValueAsFloat(manuChannel,5,chi22);