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 "AliMUONGlobalCrateConfig.h"
24 #include "AliMUONRegionalTriggerConfig.h"
25 #include "AliMUONCalibParamNI.h"
26 #include "AliMUONPreprocessor.h"
27 #include "AliMUONTriggerIO.h"
28 #include "AliMUONTriggerLut.h"
29 #include "AliMpConstants.h"
30 #include <Riostream.h>
32 #include <TObjString.h>
35 /// \class AliMUONTriggerSubprocessor
37 /// Implementation of AliMUONVSubprocessor for MUON trigger system
39 /// Reads masks and LUT online files to feed the OCDB
41 /// \author L. Aphecetche
44 ClassImp(AliMUONTriggerSubprocessor)
47 //_____________________________________________________________________________
48 AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master)
49 : AliMUONVSubprocessor(master,
51 "Upload MUON Trigger masks and LUT to OCDB"),
60 //_____________________________________________________________________________
61 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
64 delete fRegionalConfig;
70 //_____________________________________________________________________________
72 AliMUONTriggerSubprocessor::GetFileName(const char* fid) const
74 /// Get filename for a given id
76 const Int_t kSystem = AliMUONPreprocessor::kDAQ;
78 TList* sources = Master()->GetFileSources(kSystem,fid);
79 if ( sources && sources->GetSize() == 1 )
81 return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
86 //_____________________________________________________________________________
88 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
90 /// When starting a new run, reads in the trigger online files.
92 // First thing to do (after cleanup, that is), is to check whether the DA
93 // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
99 TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
101 if ( exportedFiles == "" )
103 Master()->Log("exported files not specified !");
107 if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
109 Master()->Log(Form("%s is not there !",exportedFiles.Data()));
115 Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
116 Master()->Invalidate();
120 // OK. We have an exportedFiles.dat file at hand.
121 // Read it to know what other files should be there.
123 Bool_t regionalFile(kFALSE);
124 Bool_t globalFile(kFALSE);
125 Bool_t localFile(kFALSE);
126 Bool_t lutFile(kFALSE);
128 WhichFilesToRead(GetFileName("EXPORTED").Data(),
129 globalFile,regionalFile,localFile,lutFile);
131 delete fRegionalConfig; fRegionalConfig = 0x0;
132 delete fLocalMasks; fLocalMasks = 0x0;
133 delete fGlobalConfig; fGlobalConfig = 0x0;
134 delete fLUT; fLUT = 0x0;
136 Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
137 run,startTime,endTime));
140 TestFile("REGIONAL",regionalFile) +
141 TestFile("LOCAL",localFile) +
142 TestFile("GLOBAL",globalFile) +
143 TestFile("LUT",lutFile);
147 Master()->Log("Could not read some input file(s). Aborting");
148 Master()->Invalidate();
152 if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
153 if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
154 if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
156 AliMUONTriggerIO tio;
158 Bool_t ok = tio.ReadConfig(GetFileName("LOCAL").Data(),
159 GetFileName("REGIONAL").Data(),
160 GetFileName("GLOBAL").Data(),
161 fLocalMasks,fRegionalConfig,fGlobalConfig);
165 Master()->Log("ERROR : ReadMasks failed");
167 delete fRegionalConfig;
168 delete fGlobalConfig;
170 fRegionalConfig = 0x0;
176 fLUT = new AliMUONTriggerLut;
178 Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
179 run,startTime,endTime));
181 ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
185 Master()->Log("ERROR : ReadLUT failed");
192 //_____________________________________________________________________________
194 AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
196 /// Store the trigger masks into the CDB
198 if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
204 Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
205 (fGlobalConfig ? 1 : 0 ),
206 (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ),
207 (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
210 AliCDBMetaData metaData;
211 metaData.SetBeamPeriod(0);
212 metaData.SetResponsible("MUON TRG");
213 metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
215 Bool_t validToInfinity = kTRUE;
217 Bool_t result1(kTRUE);
218 Bool_t result2(kTRUE);
219 Bool_t result3(kTRUE);
220 Bool_t result4(kTRUE);
224 result1 = Master()->Store("Calib", "GlobalTriggerBoardMasks", fGlobalConfig,
225 &metaData, 0, validToInfinity);
228 if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 )
230 result2 = Master()->Store("Calib", "RegionalTriggerBoardMasks", fRegionalConfig,
231 &metaData, 0, validToInfinity);
234 if ( fLocalMasks && fLocalMasks->GetSize() > 0 )
236 result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
237 &metaData, 0, validToInfinity);
242 result4 = Master()->Store("Calib", "TriggerLut", fLUT,
243 &metaData, 0, validToInfinity);
246 return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.
249 //_____________________________________________________________________________
251 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
253 /// Check if required file can be accessed
254 if (!shouldBeThere) return 0; // all is ok
256 TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
258 if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
260 // mind the strange return value convention of that method !
261 Master()->Log(Form("File %s does not exist",fileName.Data()));
262 return 1; // this is an error
264 return 0; // all is ok.
267 //_____________________________________________________________________________
269 AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
271 Bool_t& regionalFile,
273 Bool_t& lutFile) const
275 /// From the exportedFiles file, determine which other files will need
277 ifstream in(gSystem->ExpandPathName(exportedFiles));
280 regionalFile = kFALSE;
286 while ( in.getline(line,1024,'\n') )
291 if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
292 if ( sline.Contains("LUT") ) lutFile = kTRUE;
293 if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
294 if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
297 if ( regionalFile || localFile || globalFile || lutFile )
299 Master()->Log(Form("Will have to read the following file types:"));
300 if ( globalFile) Master()->Log("GLOBAL");
301 if ( regionalFile ) Master()->Log("REGIONAL");
302 if ( localFile) Master()->Log("LOCAL");
303 if ( lutFile ) Master()->Log("LUT");