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 **************************************************************************/
20 #include <Riostream.h>
22 #include <TObjString.h>
25 #include "AliCDBMetaData.h"
27 #include "AliMUON2DMap.h"
28 #include "AliMUONCalibParam2F.h"
29 #include "AliMUONConstants.h"
30 #include "AliMUONObjectPair.h"
31 #include "AliMUONPedestalSubprocessor.h"
32 #include "AliMUONPreprocessor.h"
33 #include "AliMUONVDataIterator.h"
34 #include "AliMpDDLStore.h"
37 /// \class AliMUONPedestalSubprocessor
39 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
41 /// Pedestals are read in from an ascii file, with the format : \n
42 ///---------------------------------------------------------------------------\n
43 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
44 ///---------------------------------------------------------------------------\n
46 /// \author L. Aphecetche
50 ClassImp(AliMUONPedestalSubprocessor)
53 //_____________________________________________________________________________
54 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
55 : AliMUONVSubprocessor(master,
57 "Upload MUON Tracker pedestals to OCDB"),
63 //_____________________________________________________________________________
64 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
70 //_____________________________________________________________________________
72 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
74 /// When starting a new run, reads in the pedestals ASCII files.
76 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
77 const char* kId = "PEDESTALS";
80 fPedestals = new AliMUON2DMap(kTRUE);
82 Master()->Log(Form("Reading pedestal 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 pedestals");
113 //_____________________________________________________________________________
115 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
117 // Store the pedestals into the CDB
119 if (!fPedestals) return 0;
121 Master()->Log("Storing pedestals");
123 AliCDBMetaData metaData;
124 metaData.SetBeamPeriod(0);
125 metaData.SetResponsible("MUON TRK");
126 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
128 Bool_t validToInfinity = kTRUE;
129 UInt_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
134 //_____________________________________________________________________________
136 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
138 // Read the pedestals from an ASCII file.
139 // Format of that file is one line per channel :
140 //---------------------------------------------------------------------------
141 // BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA
142 //---------------------------------------------------------------------------
144 // Return kFALSE if reading was not successfull.
147 TString sFilename(gSystem->ExpandPathName(filename));
149 Master()->Log(Form("Reading %s",sFilename.Data()));
151 std::ifstream in(sFilename.Data());
157 Int_t busPatchID, manuID, manuChannel;
158 Float_t pedMean, pedSigma;
159 static const Int_t kNchannels(64);
160 static Bool_t replace(kFALSE);
163 while ( in.getline(line,80) )
165 if ( line[0] == '/' && line[1] == '/' ) continue;
166 std::istringstream sin(line);
167 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
168 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
169 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
170 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
172 AliMUONVCalibParam* ped =
173 static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
177 ped = new AliMUONCalibParam2F(kNchannels,AliMUONCalibParam2F::InvalidFloatValue());
178 fPedestals->Set(detElemID,manuID,ped,replace);
180 ped->SetValueAsFloat(manuChannel,0,pedMean);
181 ped->SetValueAsFloat(manuChannel,1,pedSigma);
189 //_____________________________________________________________________________
191 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
194 AliMUONVDataIterator* it = fPedestals->Iterator();
195 AliMUONObjectPair* p;
197 while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
199 AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());