]>
Commit | Line | Data |
---|---|---|
2ab3623b | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | #include "AliMUONTriggerSubprocessor.h" | |
19 | ||
20 | #include "AliCDBMetaData.h" | |
21 | #include "AliLog.h" | |
22 | #include "AliMUON1DArray.h" | |
92c23b09 | 23 | #include "AliMUONGlobalCrateConfig.h" |
24 | #include "AliMUONRegionalTriggerConfig.h" | |
2ab3623b | 25 | #include "AliMUONCalibParamNI.h" |
26 | #include "AliMUONPreprocessor.h" | |
27 | #include "AliMUONTriggerIO.h" | |
28 | #include "AliMUONTriggerLut.h" | |
29 | #include "AliMpConstants.h" | |
30 | #include <Riostream.h> | |
31 | #include <TList.h> | |
32 | #include <TObjString.h> | |
33 | #include <TSystem.h> | |
34 | ||
35 | /// \class AliMUONTriggerSubprocessor | |
36 | /// | |
37 | /// Implementation of AliMUONVSubprocessor for MUON trigger system | |
38 | /// | |
39 | /// Reads masks and LUT online files to feed the OCDB | |
40 | /// | |
41 | /// \author L. Aphecetche | |
42 | ||
43 | /// \cond CLASSIMP | |
44 | ClassImp(AliMUONTriggerSubprocessor) | |
45 | /// \endcond | |
46 | ||
47 | //_____________________________________________________________________________ | |
48 | AliMUONTriggerSubprocessor::AliMUONTriggerSubprocessor(AliMUONPreprocessor* master) | |
49 | : AliMUONVSubprocessor(master, | |
50 | "Triggers", | |
51 | "Upload MUON Trigger masks and LUT to OCDB"), | |
92c23b09 | 52 | fRegionalConfig(0x0), |
2ab3623b | 53 | fLocalMasks(0x0), |
92c23b09 | 54 | fGlobalConfig(0x0), |
2ab3623b | 55 | fLUT(0x0) |
56 | { | |
57 | /// default ctor | |
58 | } | |
59 | ||
60 | //_____________________________________________________________________________ | |
61 | AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor() | |
62 | { | |
63 | /// dtor | |
92c23b09 | 64 | delete fRegionalConfig; |
2ab3623b | 65 | delete fLocalMasks; |
92c23b09 | 66 | delete fGlobalConfig; |
2ab3623b | 67 | delete fLUT; |
68 | } | |
69 | ||
70 | //_____________________________________________________________________________ | |
71 | TString | |
72 | AliMUONTriggerSubprocessor::GetFileName(const char* fid) const | |
73 | { | |
74 | /// Get filename for a given id | |
75 | ||
76 | const Int_t kSystem = AliMUONPreprocessor::kDAQ; | |
77 | ||
78 | TList* sources = Master()->GetFileSources(kSystem,fid); | |
79 | if ( sources && sources->GetSize() == 1 ) | |
80 | { | |
81 | return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName()); | |
82 | } | |
83 | return ""; | |
84 | } | |
85 | ||
86 | //_____________________________________________________________________________ | |
6c870207 | 87 | Bool_t |
2ab3623b | 88 | AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime) |
89 | { | |
90 | /// When starting a new run, reads in the trigger online files. | |
91 | ||
ca6cee23 | 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 | |
94 | // on the FXS. | |
95 | // | |
96 | ||
97 | Bool_t da(kTRUE); | |
98 | ||
c2d0667a | 99 | TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data())); |
ca6cee23 | 100 | |
c2d0667a | 101 | if ( exportedFiles == "" ) |
ca6cee23 | 102 | { |
c2d0667a | 103 | Master()->Log("exported files not specified !"); |
ca6cee23 | 104 | da = kFALSE; |
105 | } | |
106 | ||
c2d0667a | 107 | if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method ! |
ca6cee23 | 108 | { |
c2d0667a | 109 | Master()->Log(Form("%s is not there !",exportedFiles.Data())); |
ca6cee23 | 110 | da = kFALSE; |
111 | } | |
112 | ||
113 | if (!da) | |
114 | { | |
115 | Master()->Log("FATAL ERROR : DA does not seem to have been run !!!"); | |
116 | Master()->Invalidate(); | |
6c870207 | 117 | return kFALSE; |
ca6cee23 | 118 | } |
119 | ||
c2d0667a | 120 | // OK. We have an exportedFiles.dat file at hand. |
121 | // Read it to know what other files should be there. | |
122 | ||
123 | Bool_t regionalFile(kFALSE); | |
124 | Bool_t globalFile(kFALSE); | |
125 | Bool_t localFile(kFALSE); | |
126 | Bool_t lutFile(kFALSE); | |
127 | ||
128 | WhichFilesToRead(GetFileName("EXPORTED").Data(), | |
129 | globalFile,regionalFile,localFile,lutFile); | |
130 | ||
04ad734f | 131 | if ((globalFile+regionalFile+localFile+lutFile) == 0) { |
132 | Master()->Log("No file(s) to be processed for this run. Exiting."); | |
6c870207 | 133 | return kTRUE; |
04ad734f | 134 | } |
135 | ||
92c23b09 | 136 | delete fRegionalConfig; fRegionalConfig = 0x0; |
ca6cee23 | 137 | delete fLocalMasks; fLocalMasks = 0x0; |
92c23b09 | 138 | delete fGlobalConfig; fGlobalConfig = 0x0; |
ca6cee23 | 139 | delete fLUT; fLUT = 0x0; |
140 | ||
1130977f | 141 | Master()->Log(Form("Reading trigger masks for Run %d startTime %u endTime %u", |
2ab3623b | 142 | run,startTime,endTime)); |
143 | ||
c2d0667a | 144 | Int_t check = |
145 | TestFile("REGIONAL",regionalFile) + | |
146 | TestFile("LOCAL",localFile) + | |
147 | TestFile("GLOBAL",globalFile) + | |
148 | TestFile("LUT",lutFile); | |
149 | ||
150 | if ( check ) | |
151 | { | |
9ee1d6ff | 152 | Master()->Log("Could not read some input file(s). Exiting"); |
c2d0667a | 153 | Master()->Invalidate(); |
6c870207 | 154 | return kFALSE; |
c2d0667a | 155 | } |
156 | ||
5a26af27 | 157 | if ( regionalFile ) globalFile = kTRUE; |
158 | ||
92c23b09 | 159 | if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig(); |
c2d0667a | 160 | if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1); |
92c23b09 | 161 | if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig(); |
2ab3623b | 162 | |
163 | AliMUONTriggerIO tio; | |
164 | ||
11ee2085 | 165 | Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "", |
166 | regionalFile ? GetFileName("REGIONAL").Data() : "", | |
167 | globalFile ? GetFileName("GLOBAL").Data() : "", | |
5cf57a25 | 168 | fLocalMasks,fRegionalConfig,fGlobalConfig); |
890cc210 | 169 | |
170 | if (!ok) | |
171 | { | |
5cf57a25 | 172 | Master()->Log("ERROR : ReadConfig failed"); |
890cc210 | 173 | delete fLocalMasks; |
92c23b09 | 174 | delete fRegionalConfig; |
175 | delete fGlobalConfig; | |
890cc210 | 176 | fLocalMasks = 0x0; |
92c23b09 | 177 | fRegionalConfig = 0x0; |
178 | fGlobalConfig = 0x0; | |
890cc210 | 179 | } |
2ab3623b | 180 | |
c2d0667a | 181 | if ( lutFile ) |
182 | { | |
183 | fLUT = new AliMUONTriggerLut; | |
2ab3623b | 184 | |
1130977f | 185 | Master()->Log(Form("Reading trigger LUT for Run %d startTime %u endTime %u", |
c2d0667a | 186 | run,startTime,endTime)); |
890cc210 | 187 | |
c2d0667a | 188 | ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT); |
890cc210 | 189 | |
c2d0667a | 190 | if (!ok) |
191 | { | |
192 | Master()->Log("ERROR : ReadLUT failed"); | |
193 | delete fLUT; | |
194 | fLUT = 0x0; | |
195 | } | |
890cc210 | 196 | } |
6c870207 | 197 | return kTRUE; |
2ab3623b | 198 | } |
199 | ||
200 | //_____________________________________________________________________________ | |
201 | UInt_t | |
202 | AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/) | |
203 | { | |
204 | /// Store the trigger masks into the CDB | |
205 | ||
92c23b09 | 206 | if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT ) |
2ab3623b | 207 | { |
208 | // nothing to do | |
209 | return 0; | |
210 | } | |
211 | ||
d08fea67 | 212 | Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d", |
92c23b09 | 213 | (fGlobalConfig ? 1 : 0 ), |
214 | (fRegionalConfig ? fRegionalConfig->GetNofTriggerCrates() : 0 ), | |
d08fea67 | 215 | (fLocalMasks ? fLocalMasks->GetSize() : 0 ), |
216 | (fLUT ? 1 : 0))); | |
2ab3623b | 217 | |
218 | AliCDBMetaData metaData; | |
219 | metaData.SetBeamPeriod(0); | |
220 | metaData.SetResponsible("MUON TRG"); | |
221 | metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$"); | |
222 | ||
223 | Bool_t validToInfinity = kTRUE; | |
224 | ||
225 | Bool_t result1(kTRUE); | |
226 | Bool_t result2(kTRUE); | |
227 | Bool_t result3(kTRUE); | |
228 | Bool_t result4(kTRUE); | |
229 | ||
92c23b09 | 230 | if ( fGlobalConfig ) |
2ab3623b | 231 | { |
ea6d7574 | 232 | result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig, |
2ab3623b | 233 | &metaData, 0, validToInfinity); |
234 | } | |
235 | ||
92c23b09 | 236 | if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 ) |
2ab3623b | 237 | { |
ea6d7574 | 238 | result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig, |
2ab3623b | 239 | &metaData, 0, validToInfinity); |
240 | } | |
241 | ||
242 | if ( fLocalMasks && fLocalMasks->GetSize() > 0 ) | |
243 | { | |
244 | result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks, | |
245 | &metaData, 0, validToInfinity); | |
246 | } | |
247 | ||
248 | if ( fLUT ) | |
249 | { | |
250 | result4 = Master()->Store("Calib", "TriggerLut", fLUT, | |
251 | &metaData, 0, validToInfinity); | |
252 | } | |
253 | ||
d08fea67 | 254 | return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok. |
2ab3623b | 255 | } |
c2d0667a | 256 | |
257 | //_____________________________________________________________________________ | |
258 | Int_t | |
259 | AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const | |
260 | { | |
261 | /// Check if required file can be accessed | |
262 | if (!shouldBeThere) return 0; // all is ok | |
263 | ||
264 | TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data())); | |
265 | ||
266 | if ( gSystem->AccessPathName(fileName.Data(),kFileExists) ) | |
267 | { | |
268 | // mind the strange return value convention of that method ! | |
269 | Master()->Log(Form("File %s does not exist",fileName.Data())); | |
270 | return 1; // this is an error | |
271 | } | |
272 | return 0; // all is ok. | |
273 | } | |
274 | ||
275 | //_____________________________________________________________________________ | |
276 | void | |
277 | AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles, | |
278 | Bool_t& globalFile, | |
279 | Bool_t& regionalFile, | |
280 | Bool_t& localFile, | |
281 | Bool_t& lutFile) const | |
282 | { | |
283 | /// From the exportedFiles file, determine which other files will need | |
284 | /// to be read in | |
285 | ifstream in(gSystem->ExpandPathName(exportedFiles)); | |
286 | ||
287 | globalFile = kFALSE; | |
288 | regionalFile = kFALSE; | |
289 | localFile = kFALSE; | |
290 | lutFile = kFALSE; | |
291 | ||
292 | char line[1024]; | |
293 | ||
294 | while ( in.getline(line,1024,'\n') ) | |
295 | { | |
296 | TString sline(line); | |
297 | sline.ToUpper(); | |
298 | ||
299 | if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE; | |
300 | if ( sline.Contains("LUT") ) lutFile = kTRUE; | |
301 | if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE; | |
302 | if ( sline.Contains("GLOBAL") ) globalFile = kTRUE; | |
303 | } | |
304 | ||
305 | if ( regionalFile || localFile || globalFile || lutFile ) | |
306 | { | |
307 | Master()->Log(Form("Will have to read the following file types:")); | |
308 | if ( globalFile) Master()->Log("GLOBAL"); | |
309 | if ( regionalFile ) Master()->Log("REGIONAL"); | |
310 | if ( localFile) Master()->Log("LOCAL"); | |
311 | if ( lutFile ) Master()->Log("LUT"); | |
312 | } | |
313 | } | |
314 |