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 "AliMUONCalibParam2F.h"
25 #include "Riostream.h"
26 #include "TObjString.h"
29 #include "AliMUONVDataIterator.h"
30 #include "AliMUONConstants.h"
31 #include "AliMUONObjectPair.h"
32 #include "AliMpBusPatch.h"
33 #include "AliMUONPreprocessor.h"
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
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 AliInfo(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
82 run,startTime,endTime));
84 TList* sources = Master()->GetFileSources(kSystem,kId);
87 while ( ( o = static_cast<TObjString*>(next()) ) )
89 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
90 Bool_t ok = ReadFile(fileName.Data());
93 AliError(Form("Could not read file %s",fileName.Data()));
99 //_____________________________________________________________________________
101 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
103 // Store the pedestals into the CDB
105 if (!fPedestals) return 0;
107 AliInfo("Validating pedestals");
108 AliMUON2DStoreValidator validator;
110 validator.Validate(*fPedestals,AliMUONCalibParam2F::InvalidFloatValue());
114 validator.Report(*missing);
115 // AliError("Will not write into CDB as some pieces are missing...");
119 AliInfo("Storing pedestals");
121 AliCDBMetaData metaData;
122 metaData.SetBeamPeriod(0);
123 metaData.SetResponsible("MUON TRK");
124 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
126 UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, 0);
131 //_____________________________________________________________________________
133 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
135 // Read the pedestals from an ASCII file.
136 // Format of that file is one line per channel :
137 //---------------------------------------------------------------------------
138 // BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA
139 //---------------------------------------------------------------------------
141 // Return kFALSE if reading was not successfull.
144 AliInfo(Form("Reading %s",filename));
146 std::ifstream in(gSystem->ExpandPathName(filename));
147 if (!in.good()) return kFALSE;
150 Int_t busPatchID, manuID, manuChannel;
151 Float_t pedMean, pedSigma;
152 AliMpBusPatch busPatch;
153 busPatch.ReadBusPatchFile();
154 static const Int_t kNchannels(64);
155 static Bool_t replace(kFALSE);
157 while ( in.getline(line,80) )
159 if ( line[0] == '/' && line[1] == '/' ) continue;
160 std::istringstream sin(line);
161 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
162 Int_t detElemID = busPatch.GetDEfromBus(busPatchID);
163 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
164 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
166 AliMUONVCalibParam* ped =
167 static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
171 ped = new AliMUONCalibParam2F(kNchannels,AliMUONCalibParam2F::InvalidFloatValue());
172 fPedestals->Set(detElemID,manuID,ped,replace);
174 ped->SetValueAsFloat(manuChannel,0,pedMean);
175 ped->SetValueAsFloat(manuChannel,1,pedSigma);
182 //_____________________________________________________________________________
184 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
187 AliMUONVDataIterator* it = fPedestals->Iterator();
188 AliMUONObjectPair* p;
190 while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
192 AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());