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 "AliMUONCalibParamNF.h"
29 #include "AliMUONObjectPair.h"
30 #include "AliMUONPedestalSubprocessor.h"
31 #include "AliMUONPreprocessor.h"
32 #include "AliMUONVDataIterator.h"
33 #include "AliMpDDLStore.h"
34 #include "AliMUON2DStoreValidator.h"
35 #include "TObjString.h"
38 /// \class AliMUONPedestalSubprocessor
40 /// Implementation of AliMUONVSubprocessor class to deal with MUON TRK pedestals.
42 /// Pedestals are read in from an ascii file, with the format : \n
43 ///---------------------------------------------------------------------------\n
44 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
45 ///---------------------------------------------------------------------------\n
47 /// \author L. Aphecetche
51 ClassImp(AliMUONPedestalSubprocessor)
54 //_____________________________________________________________________________
55 AliMUONPedestalSubprocessor::AliMUONPedestalSubprocessor(AliMUONPreprocessor* master)
56 : AliMUONVSubprocessor(master,
58 "Upload MUON Tracker pedestals to OCDB"),
64 //_____________________________________________________________________________
65 AliMUONPedestalSubprocessor::~AliMUONPedestalSubprocessor()
71 //_____________________________________________________________________________
73 AliMUONPedestalSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
75 /// When starting a new run, reads in the pedestals ASCII files.
77 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
78 const char* kId = "PEDESTALS";
81 fPedestals = new AliMUON2DMap(kTRUE);
83 Master()->Log(Form("Reading pedestal files for Run %d startTime %ld endTime %ld",
84 run,startTime,endTime));
86 TList* sources = Master()->GetFileSources(kSystem,kId);
91 while ( ( o = static_cast<TObjString*>(next()) ) )
93 TString fileName(Master()->GetFile(kSystem,kId,o->GetName()));
94 Int_t ok = ReadFile(fileName.Data());
97 Master()->Log(Form("Could not read file %s",fileName.Data()));
107 Master()->Log("Failed to read any pedestals");
114 //_____________________________________________________________________________
116 AliMUONPedestalSubprocessor::Process(TMap* /*dcsAliasMap*/)
118 /// Store the pedestals into the CDB
122 // this is the only reason to fail for the moment : getting no pedestal
127 AliMUON2DStoreValidator validator;
129 Master()->Log("Validating");
131 TObjArray* chambers = validator.Validate(*fPedestals);
135 // we hereby report what's missing, but this is not a reason to fail ;-)
136 // the only reason to fail would be if we got no pedestal at all
138 lines.SetOwner(kTRUE);
140 validator.Report(lines,*chambers);
145 while ( ( line = static_cast<TObjString*>(next()) ) )
147 Master()->Log(line->String().Data());
151 Master()->Log("Storing pedestals");
153 AliCDBMetaData metaData;
154 metaData.SetBeamPeriod(0);
155 metaData.SetResponsible("MUON TRK");
156 metaData.SetComment("Computed by AliMUONPedestalSubprocessor $Id$");
158 Bool_t validToInfinity = kTRUE;
159 Bool_t result = Master()->Store("Calib", "Pedestals", fPedestals, &metaData, 0, validToInfinity);
161 return ( result != kTRUE ); // return 0 if everything is ok.
164 //_____________________________________________________________________________
166 AliMUONPedestalSubprocessor::ReadFile(const char* filename)
168 /// Read the pedestals from an ASCII file. \n
169 /// Format of that file is one line per channel : \n
170 ///-------------------------------------------------------------------------\n
171 /// BUS_PATCH MANU_ADDR CHANNEL MEAN SIGMA \n
172 ///-------------------------------------------------------------------------\n
174 /// Return kFALSE if reading was not successfull. \n
177 TString sFilename(gSystem->ExpandPathName(filename));
179 Master()->Log(Form("Reading %s",sFilename.Data()));
181 std::ifstream in(sFilename.Data());
187 Int_t busPatchID, manuID, manuChannel;
188 Float_t pedMean, pedSigma;
189 static const Int_t kNchannels(64);
190 static Bool_t replace(kFALSE);
193 while ( in.getline(line,80) )
195 if ( line[0] == '/' && line[1] == '/' ) continue;
196 std::istringstream sin(line);
197 sin >> busPatchID >> manuID >> manuChannel >> pedMean >> pedSigma;
198 Int_t detElemID = AliMpDDLStore::Instance()->GetDEfromBus(busPatchID);
199 AliDebug(3,Form("BUSPATCH %3d DETELEMID %4d MANU %3d CH %3d MEAN %7.2f SIGMA %7.2f",
200 busPatchID,detElemID,manuID,manuChannel,pedMean,pedSigma));
202 AliMUONVCalibParam* ped =
203 static_cast<AliMUONVCalibParam*>(fPedestals->Get(detElemID,manuID));
207 ped = new AliMUONCalibParamNF(2,kNchannels,AliMUONVCalibParam::InvalidFloatValue());
208 fPedestals->Set(detElemID,manuID,ped,replace);
210 ped->SetValueAsFloat(manuChannel,0,pedMean);
211 ped->SetValueAsFloat(manuChannel,1,pedSigma);
219 //_____________________________________________________________________________
221 AliMUONPedestalSubprocessor::Print(Option_t* opt) const
224 AliMUONVDataIterator* it = fPedestals->Iterator();
225 AliMUONObjectPair* p;
227 while ( ( p = static_cast<AliMUONObjectPair*>(it->Next() ) ) )
229 AliMUONVCalibParam* value = static_cast<AliMUONVCalibParam*>(p->Value());
231 if (it->IsOwner()) delete p;