AliRoot Core  v5-06-15 (45dab64)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliMUONTriggerSubprocessor.cxx
Go to the documentation of this file.
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 
19 
20 #include "AliCDBMetaData.h"
21 #include "AliLog.h"
22 #include "AliMUON1DArray.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>
31 #include <TList.h>
32 #include <TObjString.h>
33 #include <TSystem.h>
34 #include <TClonesArray.h>
35 
43 
44 using std::ifstream;
48 
49 //_____________________________________________________________________________
51 : AliMUONVSubprocessor(master,
52  "Triggers",
53  "Upload MUON Trigger masks and LUT to OCDB"),
54 fRegionalConfig(0x0),
55 fLocalMasks(0x0),
56 fGlobalConfig(0x0),
57 fLUT(0x0),
58 fTrigScalers(0x0)
59 {
61 }
62 
63 //_____________________________________________________________________________
65 {
67  delete fRegionalConfig;
68  delete fLocalMasks;
69  delete fGlobalConfig;
70  delete fLUT;
71  delete [] fTrigScalers;
72 }
73 
74 //_____________________________________________________________________________
75 TString
77 {
79 
80  const Int_t kSystem = AliMUONPreprocessor::kDAQ;
81 
82  TList* sources = Master()->GetFileSources(kSystem,fid);
83  if ( sources && sources->GetSize() == 1 )
84  {
85  return Master()->GetFile(kSystem,fid,static_cast<TObjString*>(sources->First())->GetName());
86  }
87  return "";
88 }
89 
90 //_____________________________________________________________________________
91 Bool_t
92 AliMUONTriggerSubprocessor::Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
93 {
95 
96  // First thing to do (after cleanup, that is), is to check whether the DA
97  // was alive or not. If it was, it should have put the "MtgCurrent.dat" file
98  // on the FXS.
99  //
100 
101  Bool_t da(kTRUE);
102 
103  TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
104 
105  if ( exportedFiles == "" )
106  {
107  Master()->Log("exported files not specified !");
108  da = kFALSE;
109  }
110 
111  if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
112  {
113  Master()->Log(Form("%s is not there !",exportedFiles.Data()));
114  da = kFALSE;
115  }
116 
117  if (!da)
118  {
119  Master()->Log("FATAL ERROR : DA does not seem to have been run !!!");
120  Master()->Invalidate();
121  return kFALSE;
122  }
123 
124  // OK. We have an exportedFiles.dat file at hand.
125  // Read it to know what other files should be there.
126 
127  Bool_t regionalFile(kFALSE);
128  Bool_t globalFile(kFALSE);
129  Bool_t localFile(kFALSE);
130  Bool_t lutFile(kFALSE);
131  Bool_t trigScalFile(kFALSE);
132 
133  WhichFilesToRead(GetFileName("EXPORTED").Data(),
134  globalFile,regionalFile,localFile,lutFile,trigScalFile);
135 
136  if ((globalFile+regionalFile+localFile+lutFile+trigScalFile) == 0) {
137  Master()->Log("No file(s) to be processed for this run. Exiting.");
138  return kTRUE;
139  }
140 
141  delete fRegionalConfig; fRegionalConfig = 0x0;
142  delete fLocalMasks; fLocalMasks = 0x0;
143  delete fGlobalConfig; fGlobalConfig = 0x0;
144  delete fLUT; fLUT = 0x0;
145  delete fTrigScalers; fTrigScalers = 0x0;
146 
147  Master()->Log(Form("Reading trigger masks for Run %d startTime %u endTime %u",
148  run,startTime,endTime));
149 
150  Int_t check =
151  TestFile("REGIONAL",regionalFile) +
152  TestFile("LOCAL",localFile) +
153  TestFile("GLOBAL",globalFile) +
154  TestFile("LUT",lutFile) +
155  TestFile("TRIGSCAL",trigScalFile);
156 
157  if ( check )
158  {
159  Master()->Log("Could not read some input file(s). Exiting");
160  Master()->Invalidate();
161  return kFALSE;
162  }
163 
164  if ( regionalFile ) globalFile = kTRUE;
165 
166  if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
168  if ( globalFile ) fGlobalConfig = new AliMUONGlobalCrateConfig();
169 
170  AliMUONTriggerIO tio;
171 
172  Bool_t ok = tio.ReadConfig(localFile ? GetFileName("LOCAL").Data() : "",
173  regionalFile ? GetFileName("REGIONAL").Data() : "",
174  globalFile ? GetFileName("GLOBAL").Data() : "",
176 
177  if (!ok)
178  {
179  Master()->Log("ERROR : ReadConfig failed");
180  delete fLocalMasks;
181  delete fRegionalConfig;
182  delete fGlobalConfig;
183  fLocalMasks = 0x0;
184  fRegionalConfig = 0x0;
185  fGlobalConfig = 0x0;
186  }
187 
188  if ( lutFile )
189  {
190  fLUT = new AliMUONTriggerLut;
191 
192  Master()->Log(Form("Reading trigger LUT for Run %d startTime %u endTime %u",
193  run,startTime,endTime));
194 
195  ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
196 
197  if (!ok)
198  {
199  Master()->Log("ERROR : ReadLUT failed");
200  delete fLUT;
201  fLUT = 0x0;
202  }
203  }
204 
205  if ( trigScalFile ) {
206  fTrigScalers = new TClonesArray("AliMUONTriggerScalers",10);
207  ok = tio.ReadTrigScalers(GetFileName("TRIGSCAL").Data(),*fTrigScalers);
208  if (!ok)
209  {
210  Master()->Log("ERROR : ReadTrigScalers failed");
211  delete fTrigScalers;
212  fTrigScalers = 0x0;
213  }
214  }
215 
216  return kTRUE;
217 
218 }
219 
220 //_____________________________________________________________________________
221 UInt_t
223 {
225 
226  if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
227  {
228  // nothing to do
229  return 0;
230  }
231 
232  Master()->Log(Form("N global = %d N regional = %d N local %d N lut %d",
233  (fGlobalConfig ? 1 : 0 ),
235  (fLocalMasks ? fLocalMasks->GetSize() : 0 ),
236  (fLUT ? 1 : 0)));
237 
238  AliCDBMetaData metaData;
239  metaData.SetBeamPeriod(0);
240  metaData.SetResponsible("MUON TRG");
241  metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
242 
243  Bool_t validToInfinity = kTRUE;
244 
245  Bool_t result1(kTRUE);
246  Bool_t result2(kTRUE);
247  Bool_t result3(kTRUE);
248  Bool_t result4(kTRUE);
249  Bool_t result5(kTRUE);
250 
251  if ( fGlobalConfig )
252  {
253  result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig,
254  &metaData, 0, validToInfinity);
255  }
256 
258  {
259  result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig,
260  &metaData, 0, validToInfinity);
261  }
262 
263  if ( fLocalMasks && fLocalMasks->GetSize() > 0 )
264  {
265  result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks,
266  &metaData, 0, validToInfinity);
267  }
268 
269  if ( fLUT )
270  {
271  result4 = Master()->Store("Calib", "TriggerLut", fLUT,
272  &metaData, 0, validToInfinity);
273  }
274 
275  if ( fTrigScalers )
276  {
277  result5 = Master()->Store("Calib","TriggerScalers", fTrigScalers,
278  &metaData, 0, validToInfinity);
279  }
280 
281  return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE || result5 != kTRUE); // return 0 if everything is ok.
282 }
283 
284 //_____________________________________________________________________________
285 Int_t
286 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
287 {
289  if (!shouldBeThere) return 0; // all is ok
290 
291  TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
292 
293  if ( gSystem->AccessPathName(fileName.Data(),kFileExists) )
294  {
295  // mind the strange return value convention of that method !
296  Master()->Log(Form("File %s does not exist",fileName.Data()));
297  return 1; // this is an error
298  }
299  return 0; // all is ok.
300 }
301 
302 //_____________________________________________________________________________
303 void
305  Bool_t& globalFile,
306  Bool_t& regionalFile,
307  Bool_t& localFile,
308  Bool_t& lutFile,
309  Bool_t& trigScalFile) const
310 {
313  ifstream in(gSystem->ExpandPathName(exportedFiles));
314 
315  globalFile = kFALSE;
316  regionalFile = kFALSE;
317  localFile = kFALSE;
318  lutFile = kFALSE;
319  trigScalFile = kFALSE;
320 
321  char line[1024];
322 
323  while ( in.getline(line,1024,'\n') )
324  {
325  TString sline(line);
326  sline.ToUpper();
327 
328  if ( sline.Contains("REGIONAL") ) regionalFile = kTRUE;
329  if ( sline.Contains("LUT") ) lutFile = kTRUE;
330  if ( sline.Contains("LOCAL") && sline.Contains("MASK") ) localFile = kTRUE;
331  if ( sline.Contains("GLOBAL") ) globalFile = kTRUE;
332  if ( sline.Contains("TRIGSCAL") ) trigScalFile = kTRUE;
333  }
334 
335  if ( regionalFile || localFile || globalFile || lutFile || trigScalFile)
336  {
337  Master()->Log(Form("Will have to read the following file types:"));
338  if ( globalFile) Master()->Log("GLOBAL");
339  if ( regionalFile ) Master()->Log("REGIONAL");
340  if ( localFile) Master()->Log("LOCAL");
341  if ( lutFile ) Master()->Log("LUT");
342  if ( trigScalFile ) Master()->Log("TRIGSCAL");
343  }
344 }
345 
Bool_t ReadLUT(const char *lutFileToRead, AliMUONTriggerLut &lut)
AliMUONVStore * fLocalMasks
! local masks
The class defines the configuration of global crate.
TString GetFileName(const char *fid) const
AliMUONPreprocessor * Master() const
Return the pointer to our master.
virtual Int_t GetSize() const =0
The number of objects stored.
AliMUONRegionalTriggerConfig * fRegionalConfig
! regional config
ClassImp(TPCGenInfo)
Definition: AliTPCCmpNG.C:254
Bool_t ReadTrigScalers(const char *scfile, TClonesArray &scalers) const
Handles read/write of masks and LUT to/from online files.
Base class for a shuttle sub-task for MUON (either TRK or TRG)
TTimeStamp startTime(2009, 8, 7, 0, 0, 0)
AliMUONGlobalCrateConfig * fGlobalConfig
! global config
Implementation of AliMUONVSubprocessor for MUON TRK masks.
const char * GetFile(Int_t system, const char *id, const char *source)
Publish AliPreprocessor::GetFile function.
Bool_t Initialize(Int_t run, UInt_t startTime, UInt_t endTime)
Int_t TestFile(const char *baseName, Bool_t shouldBeThere) const
void Log(const char *message)
Publish AliPreprocessor::Log function.
static Int_t TotalNofLocalBoards()
Return total number of trigger local boards.
Implementation of AliMUONVStore.
UInt_t Process(TMap *dcsAliasMap)
Process this sub-task.
TList * GetFileSources(Int_t system, const char *id)
Publish AliPreprocessor::GetFileSources function.
TClonesArray * fTrigScalers
! trigger scalers
Bool_t Store(const char *pathLevel2, const char *pathLevel3, TObject *object, AliCDBMetaData *metaData, Int_t validityStart=0, Bool_t validityInfinite=kFALSE)
Publish AliPreprocessor::Store function.
void WhichFilesToRead(const char *exportedFiles, Bool_t &globalFile, Bool_t &regionalFile, Bool_t &localFile, Bool_t &lutFile, Bool_t &trigScalFile) const
AliMUONTriggerLut * fLUT
! look-up table(s)
Shuttle preprocessor for MUON subsystems (TRK and TRG)
void Invalidate()
Mark as invalid.
MUON trigger look up table class.
Bool_t ReadConfig(const char *localFile, const char *regionalFile, const char *globalFile, AliMUONVStore *localMasks, AliMUONRegionalTriggerConfig *regionalConfig, AliMUONGlobalCrateConfig *globalConfig)
The class defines the properties of regional trigger crate.