]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONTriggerSubprocessor.cxx
Minor changes
[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 /// \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"),
52 fRegionalConfig(0x0),
53 fLocalMasks(0x0),
54 fGlobalConfig(0x0),
55 fLUT(0x0)
56 {
57   /// default ctor
58 }
59
60 //_____________________________________________________________________________
61 AliMUONTriggerSubprocessor::~AliMUONTriggerSubprocessor()
62 {
63   /// dtor
64   delete fRegionalConfig;
65   delete fLocalMasks;
66   delete fGlobalConfig;
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 //_____________________________________________________________________________
87 void 
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   
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   
99   TString exportedFiles(gSystem->ExpandPathName(GetFileName("EXPORTED").Data()));
100   
101   if ( exportedFiles == "" ) 
102   {
103     Master()->Log("exported files not specified !");
104     da = kFALSE;
105   }
106   
107   if ( gSystem->AccessPathName(exportedFiles.Data(),kFileExists) ) // mind the strange return value convention of that method !
108   {
109     Master()->Log(Form("%s is not there !",exportedFiles.Data()));
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();
117     return;
118   }
119   
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   
131   delete fRegionalConfig; fRegionalConfig = 0x0;
132   delete fLocalMasks; fLocalMasks = 0x0;
133   delete fGlobalConfig; fGlobalConfig = 0x0;
134   delete fLUT; fLUT = 0x0;
135   
136   Master()->Log(Form("Reading trigger masks for Run %d startTime %ld endTime %ld",
137                      run,startTime,endTime));
138     
139   Int_t check = 
140     TestFile("REGIONAL",regionalFile) + 
141     TestFile("LOCAL",localFile) + 
142     TestFile("GLOBAL",globalFile) +
143     TestFile("LUT",lutFile);
144
145   if ( check ) 
146   {
147     Master()->Log("Could not read some input file(s). Aborting");
148     Master()->Invalidate();
149     return;
150   }
151   
152   if ( regionalFile ) fRegionalConfig = new AliMUONRegionalTriggerConfig();
153   if ( localFile ) fLocalMasks = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
154   if ( globalFile )   fGlobalConfig   = new AliMUONGlobalCrateConfig();
155
156   AliMUONTriggerIO tio;
157   
158   Bool_t ok = tio.ReadConfig(GetFileName("LOCAL").Data(),
159                              GetFileName("REGIONAL").Data(),
160                              GetFileName("GLOBAL").Data(),
161                              fLocalMasks,fRegionalConfig,fGlobalConfig);
162   
163   if (!ok)
164   {
165     Master()->Log("ERROR : ReadConfig failed");
166     delete fLocalMasks;
167     delete fRegionalConfig;
168     delete fGlobalConfig;
169     fLocalMasks = 0x0;
170     fRegionalConfig = 0x0;
171     fGlobalConfig = 0x0;
172   }
173
174   if ( lutFile ) 
175   {
176     fLUT = new AliMUONTriggerLut;
177     
178     Master()->Log(Form("Reading trigger LUT for Run %d startTime %ld endTime %ld",
179                        run,startTime,endTime));
180   
181     ok = tio.ReadLUT(GetFileName("LUT").Data(),*fLUT);
182
183     if (!ok)
184     {
185       Master()->Log("ERROR : ReadLUT failed");
186       delete fLUT;
187       fLUT = 0x0;
188     }
189   }
190 }
191
192 //_____________________________________________________________________________
193 UInt_t 
194 AliMUONTriggerSubprocessor::Process(TMap* /*dcsAliasMap*/)
195 {
196   /// Store the trigger masks into the CDB
197   
198   if ( !fGlobalConfig && !fRegionalConfig && !fLocalMasks && !fLUT )
199   {
200     // nothing to do
201     return 0;
202   }
203   
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 ),
208                      (fLUT ? 1 : 0)));
209   
210   AliCDBMetaData metaData;
211         metaData.SetBeamPeriod(0);
212         metaData.SetResponsible("MUON TRG");
213         metaData.SetComment("Computed by AliMUONTriggerSubprocessor $Id$");
214   
215   Bool_t validToInfinity = kTRUE;
216
217         Bool_t result1(kTRUE);
218   Bool_t result2(kTRUE);
219   Bool_t result3(kTRUE);
220   Bool_t result4(kTRUE);
221   
222   if ( fGlobalConfig ) 
223   {
224     result1 = Master()->Store("Calib", "GlobalTriggerCrateConfig", fGlobalConfig, 
225                               &metaData, 0, validToInfinity);
226   }
227   
228   if ( fRegionalConfig && fRegionalConfig->GetNofTriggerCrates() > 0 )
229   {
230     result2 = Master()->Store("Calib", "RegionalTriggerConfig", fRegionalConfig, 
231                               &metaData, 0, validToInfinity);
232   }
233   
234   if ( fLocalMasks && fLocalMasks->GetSize() > 0 ) 
235   {
236     result3 = Master()->Store("Calib", "LocalTriggerBoardMasks", fLocalMasks, 
237                               &metaData, 0, validToInfinity);
238   }
239
240   if ( fLUT )
241   {
242     result4 = Master()->Store("Calib", "TriggerLut", fLUT, 
243                               &metaData, 0, validToInfinity);
244   }
245   
246   return ( result1 != kTRUE || result2 != kTRUE || result3 != kTRUE || result4 != kTRUE ); // return 0 if everything is ok.  
247 }
248
249 //_____________________________________________________________________________
250 Int_t
251 AliMUONTriggerSubprocessor::TestFile(const char* baseName, Bool_t shouldBeThere) const
252 {
253   /// Check if required file can be accessed 
254   if (!shouldBeThere) return 0; // all is ok
255   
256   TString fileName(gSystem->ExpandPathName(GetFileName(baseName).Data()));
257   
258   if ( gSystem->AccessPathName(fileName.Data(),kFileExists) ) 
259   {
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
263   }
264   return 0; // all is ok.
265 }
266
267 //_____________________________________________________________________________
268 void
269 AliMUONTriggerSubprocessor::WhichFilesToRead(const char* exportedFiles,
270                                              Bool_t& globalFile,
271                                              Bool_t& regionalFile,
272                                              Bool_t& localFile,
273                                              Bool_t& lutFile) const
274 {
275   /// From the exportedFiles file, determine which other files will need
276   /// to be read in
277   ifstream in(gSystem->ExpandPathName(exportedFiles));
278   
279   globalFile = kFALSE;
280   regionalFile = kFALSE;
281   localFile = kFALSE;
282   lutFile = kFALSE;
283   
284   char line[1024];
285   
286   while ( in.getline(line,1024,'\n') )
287   {
288     TString sline(line);
289     sline.ToUpper();
290     
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;
295   }
296     
297   if ( regionalFile || localFile || globalFile || lutFile ) 
298   {
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");
304   }
305 }
306