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