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