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 "AliMUONTriggerSubprocessor.h"
20 #include "AliCDBMetaData.h"
22 #include "AliMUON1DArray.h"
23 #include "AliMUONCalibParamNI.h"
24 #include "AliMUONPreprocessor.h"
25 #include "AliMUONTriggerIO.h"
26 #include "AliMUONTriggerLut.h"
27 #include "AliMpConstants.h"
28 #include <Riostream.h>
30 #include <TObjString.h>
33 /// \class AliMUONTriggerSubprocessor
35 /// Implementation of AliMUONVSubprocessor for MUON trigger system
37 /// Reads masks and LUT online files to feed the OCDB
39 /// \author L. Aphecetche
42 ClassImp(AliMUONTriggerSubprocessor)
45 //_____________________________________________________________________________
46 AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master)
47 : AliMUONVSubprocessor(master,
49 "Upload MUON Trigger masks and LUT to OCDB"),
58 //_____________________________________________________________________________
59 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
62 delete fRegionalMasks;
68 //_____________________________________________________________________________
70 AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
72 /// Get filename for a given id
74 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
76 TList* sources = Master()->GetFileSources(kSystem,fid);
77 if ( sources && sources->GetSize() == 1 )
79 return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
84 //_____________________________________________________________________________
86 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
88 /// When starting a new run, reads in the trigger online files.
90 // First thing to do (after cleanup, that is), is to check whether the DA
91 // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
97 TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
99 if ( exportedFiles == "" )
101 Master()->Log("exported files not specified !");
105 if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
107 Master()->Log(Form("%s is not there !",exportedFiles.Data()));
113 Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
114 Master()->Invalidate();
118 // OK. We have an exportedFiles.dat file at hand.
119 // Read it to know what other files should be there.
121 Bool_t regionalFile(kFALSE);
122 Bool_t globalFile(kFALSE);
123 Bool_t localFile(kFALSE);
124 Bool_t lutFile(kFALSE);
126 WhichFilesToRead(GetFileName("EXPORTED").Data(),
127 globalFile,regionalFile,localFile,lutFile);
129 delete fRegionalMasks; fRegionalMasks = 0x0;
130 delete fLocalMasks; fLocalMasks = 0x0;
131 delete fGlobalMasks; fGlobalMasks = 0x0;
132 delete fLUT; fLUT = 0x0;
134 Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
135 run,startTime,endTime));
138 TestFile("REGIONAL",regionalFile) +
139 TestFile("LOCAL",localFile) +
140 TestFile("GLOBAL",globalFile) +
141 TestFile("LUT",lutFile);
145 Master()->Log("Could not read some input file(s). Aborting");
146 Master()->Invalidate();
150 if ( regionalFile ) fRegionalMasks = new AliMUON1DArray(16);
151 if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
152 if ( globalFile ) fGlobalMasks = new AliMUONCalibParamNI(1,16,1,0,0);
154 AliMUONTriggerIO tio;
156 Bool_t ok = tio.ReadMasks(GetFileName("LOCAL").Data(),
157 GetFileName("REGIONAL").Data(),
158 GetFileName("GLOBAL").Data(),
159 fLocalMasks,fRegionalMasks,fGlobalMasks);
163 Master()->Log("ERROR : ReadMasks failed");
165 delete fRegionalMasks;
168 fRegionalMasks = 0x0;
174 fLUT = new AliMUONTriggerLut;
176 Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
177 run,startTime,endTime));
179 ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
183 Master()->Log("ERROR : ReadLUT failed");
190 //_____________________________________________________________________________
192 AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
194 /// Store the trigger masks into the CDB
196 if ( !fGlobalMasks && !fRegionalMasks && !fLocalMasks && !fLUT )
202 Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
203 (fGlobalMasks ? 1 : 0 ),
204 (fRegionalMasks ? fRegionalMasks->GetSize() : 0 ),
205 (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
208 AliCDBMetaData metaData;
209 metaData.SetBeamPeriod(0);
210 metaData.SetResponsible("MUON TRG");
211 metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
213 Bool_t validToInfinity = kTRUE;
215 Bool_t result1(kTRUE);
216 Bool_t result2(kTRUE);
217 Bool_t result3(kTRUE);
218 Bool_t result4(kTRUE);
222 result1 = Master()->Store("Calib", "GlobalTriggerBoardMasks", fGlobalMasks,
223 &metaData, 0, validToInfinity);
226 if ( fRegionalMasks && fRegionalMasks->GetSize() > 0 )
228 result2 = Master()->Store("Calib", "RegionalTriggerBoardMasks", fRegionalMasks,
229 &metaData, 0, validToInfinity);
232 if ( fLocalMasks && fLocalMasks->GetSize() > 0 )
234 result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
235 &metaData, 0, validToInfinity);
240 result4 = Master()->Store("Calib", "TriggerLut", fLUT,
241 &metaData, 0, validToInfinity);
244 return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.
247 //_____________________________________________________________________________
249 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
251 /// Check if required file can be accessed
252 if (!shouldBeThere) return 0; // all is ok
254 TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
256 if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
258 // mind the strange return value convention of that method !
259 Master()->Log(Form("File %s does not exist",fileName.Data()));
260 return 1; // this is an error
262 return 0; // all is ok.
265 //_____________________________________________________________________________
267 AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
269 Bool_t& regionalFile,
271 Bool_t& lutFile) const
273 /// From the exportedFiles file, determine which other files will need
275 ifstream in(gSystem->ExpandPathName(exportedFiles));
278 regionalFile = kFALSE;
284 while ( in.getline(line,1024,'\n') )
289 if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
290 if ( sline.Contains("LUT") ) lutFile = kTRUE;
291 if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
292 if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
295 if ( regionalFile || localFile || globalFile || lutFile )
297 Master()->Log(Form("Will have to read the following file types:"));
298 if ( globalFile) Master()->Log("GLOBAL");
299 if ( regionalFile ) Master()->Log("REGIONAL");
300 if ( localFile) Master()->Log("LOCAL");
301 if ( lutFile ) Master()->Log("LUT");