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 "AliMUONPedestalSubprocessor.h"
20 #include "AliCDBMetaData.h"
22 #include "AliMUON2DMap.h"
23 #include "AliMUON2DStoreValidator.h"
24 #include "AliMUONCalibParamNF.h"
25 #include "AliMUONPreprocessor.h"
26 #include "AliMpConstants.h"
27 #include "AliMpDDLStore.h"
28 #include "TObjString.h"
29 #include <Riostream.h>
31 #include <TObjString.h>
35 //-----------------------------------------------------------------------------
36 /// \class AliMUONPedestalSubprocessor
38 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
40 /// Pedestals are read in from an ascii file, with the format : \n
41 ///---------------------------------------------------------------------------\n
42 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
43 ///---------------------------------------------------------------------------\n
45 /// \author L. Aphecetche
46 //-----------------------------------------------------------------------------
49 ClassImp(AliMUONPedestalSubprocessor)
52 //_____________________________________________________________________________
53 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
54 : AliMUONVSubprocessor(master,
56 "Upload MUON Tracker pedestals to OCDB"),
62 //_____________________________________________________________________________
63 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
69 //_____________________________________________________________________________
71 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
73 /// When starting a new run, reads in the pedestals ASCII files.
75 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
76 const char* kId = "PEDESTALS";
79 fPedestals = new AliMUON2DMap(kTRUE);
81 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
82 run,startTime,endTime));
84 TList* sources = Master()->GetFileSources(kSystem,kId);
89 while ( ( o = static_cast<TObjString*>(next()) ) )
91 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
92 Int_t ok = ReadFile(fileName.Data());
95 Master()->Log(Form("Could not read file %s",fileName.Data()));
105 Master()->Log("Failed to read any pedestals");
112 //_____________________________________________________________________________
114 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
116 /// Store the pedestals into the CDB
120 // this is the only reason to fail for the moment : getting no pedestal
125 AliMUON2DStoreValidator validator;
127 Master()->Log("Validating");
129 TObjArray* chambers = validator.Validate(*fPedestals);
133 // we hereby report what's missing, but this is not a reason to fail ;-)
134 // the only reason to fail would be if we got no pedestal at all
136 lines.SetOwner(kTRUE);
138 validator.Report(lines,*chambers);
143 while ( ( line = static_cast<TObjString*>(next()) ) )
145 Master()->Log(line->String().Data());
149 Master()->Log("Storing pedestals");
151 AliCDBMetaData metaData;
152 metaData.SetBeamPeriod(0);
153 metaData.SetResponsible("MUON TRK");
154 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
156 Bool_t validToInfinity = kTRUE;
157 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
159 return ( result != kTRUE ); // return 0 if everything is ok.
162 //_____________________________________________________________________________
164 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
166 /// Read the pedestals from an ASCII file. \n
167 /// Format of that file is one line per channel : \n
168 ///-------------------------------------------------------------------------\n
169 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
170 ///-------------------------------------------------------------------------\n
172 /// Return kFALSE if reading was not successfull. \n
175 TString sFilename(gSystem->ExpandPathName(filename));
177 Master()->Log(Form("Reading %s",sFilename.Data()));
179 std::ifstream in(sFilename.Data());
182 Master()->Log(Form("Could not open %s",sFilename.Data()));
186 Int_t busPatchID, manuID, manuChannel;
187 Float_t pedMean, pedSigma;
188 static const Int_t kNchannels(AliMpConstants::ManuNofChannels());
191 while ( in.getline(line,1024) )
193 AliDebug(3,Form("line=%s",line));
194 if ( line[0] == '/' && line[1] == '/' ) continue;
195 std::istringstream sin(line);
196 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
197 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
198 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
199 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
201 AliMUONVCalibParam* ped =
202 static_cast<AliMUONVCalibParam*>(fPedestals->FindObject(detElemID,manuID));
206 ped = new AliMUONCalibParamNF(2,kNchannels,
208 AliMUONVCalibParam::InvalidFloatValue());
209 fPedestals->Add(ped);
211 ped->SetValueAsFloat(manuChannel,0,pedMean);
212 ped->SetValueAsFloat(manuChannel,1,pedSigma);
217 Master()->Log("File closed");
223 //_____________________________________________________________________________
225 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
228 if (fPedestals) fPedestals->Print("",opt);