Fixing bugs
[u/mrichter/AliRoot.git] / MUON / TestMUONPreprocessor.C
CommitLineData
ea199e33 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#if !defined(__CINT__) || defined(__MAKECINT__)
19
e54bf126 20/// \ingroup macros
21/// \file TestMUONPreprocessor.C
22/// \brief The macro for testing the shuttle preprocessors
23///
608c3123 24/// This macro runs the test preprocessor for MUON.
25/// It uses AliTestShuttle to simulate a full Shuttle process
49e110ec 26///
2c1e4958 27/// You must load relevant libraries (besides normal MUON ones -which is done
28/// easily by executing root from the $ALICE_ROOT/MUON directory to use
29/// the rootlogon.C there) before compiling this macro :
49e110ec 30/// <pre>
31/// gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle");
6c870207 32/// gSystem->Load("libMUONshuttle");
49e110ec 33/// </pre>
6c870207 34/// Last line above assume you have $ALICE_ROOT/MUON/lib/tgt_[arch] (where
35/// libMUONshuttle is located) in your LD_LIBRARY_PATH
608c3123 36///
2c1e4958 37/// Having $ALICE_ROOT/SHUTTLE/TestShuttle directory in your LD_LIBRARY_PATH
38/// (or DYLD_LIBRARY_PATH on Mac OS X) won't hurt either...
39///
40/// You must also make a link of some OCDB entries to have the mapping loaded
41/// correctly :
42///
43/// cd $ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB
44/// mkdir -p MUON/Calib
45/// cd MUON/Calib
46/// ln -si $ALICE_ROOT/OCDB/MUON/Calib/MappingData .
47///
48/// and Align/Baseline if you'd like to test GMS subprocessor :
49///
50/// cd $ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB
51/// mkdir -p MUON/Align/Baseline
52/// cd MUON/Align
53/// ln -si $ALICE_ROOT/OCDB/MUON/Align/Baseline .
54///
608c3123 55/// The input data has to be created first by other processes (or is created
56/// here by CreateDCSAliasMap() for tracker HV).
57///
58/// To play with it, you'll have to set/modify several lines, to
e54bf126 59/// - a) select input files, using shuttle->AddInputFile()
60/// - b) select run type, using shuttle->AddInputRunParameter() (the run type
61/// dictates which task is really performed by the MUONPreprocessor
608c3123 62///
49e110ec 63/// The sourceDirectory is there to "emulate" what the real preprocessor will
64/// find on the FXS, and is assumed to have the following structure :
e54bf126 65/// <pre>
49e110ec 66/// GAINS/
67/// LDC0.gain
68/// LDC1.gain
69/// LDC2.gain
70/// LDC3.gain
71/// GMS/
72/// GMS.root
7eafe398 73/// OCCUPANCY/
74/// mch.occupancy
49e110ec 75/// PEDESTALS/
76/// LDC0.ped
77/// LDC1.ped
78/// LDC2.ped
79/// LDC3.ped
6c870207 80/// LDC4.conf
81/// CONFIG/
82/// LDC0.conf
83/// LDC1.conf
84/// LDC2.conf
85/// LDC3.conf
86/// LDC4.conf
49e110ec 87/// TRIGGER/
88/// ExportedFiles.dat (mandatory)
89/// MtgGlobalCrate-1.dat
90/// MtgLocalLut-1.dat
91/// MtgLocalMask-1.dat
92/// MtgRegionalCrate-1.dat
93/// </pre>
94///
95/// IMPORTANT:
96/// The trigger files have to be present in order for the algorithm to work correctly.
97/// If you want to test the Trigger DCS maps only, but you don't have the .dat trigger files,
98/// you have to create dummy files through :
99/// <pre>
100/// cd sourceDirectory/TRIGGER
101/// echo -e "MtgLocalMask-1.dat\nMtgRegionalCrate-1.dat\nMtgGlobalCrate-1.dat\nMtgLocalLut-1.dat" > ExportedFiles.dat
102/// touch MtgLocalMask-1.dat MtgRegionalCrate-1.dat MtgGlobalCrate-1.dat MtgLocalLut-1.dat
e54bf126 103/// </pre>
5699c0e6 104///
e54bf126 105/// For more information on usage, please see the \ref README_shuttle page.
5699c0e6 106///
49e110ec 107/// \author Laurent Aphecetche, SUBATECH Nantes; \n
108/// Diego Stocco, SUBATECH Nantes
ea199e33 109
608c3123 110#include "TestMUONPreprocessor.h"
8a2055e0 111
112#include "AliMUONTrackerPreprocessor.h"
2ab3623b 113#include "AliMUONTriggerPreprocessor.h"
5699c0e6 114
115#include "AliLog.h"
8a2055e0 116
6c870207 117#include "AliMpBusPatch.h"
8a2055e0 118#include "AliMpExMap.h"
119#include "AliMpHelper.h"
6c870207 120#include "AliMpDDLStore.h"
49e110ec 121#include "AliMpDCSNamer.h"
8a2055e0 122#include "AliMpCDB.h"
123
ea199e33 124#include "AliCDBManager.h"
8a2055e0 125#include "AliCDBEntry.h"
ea199e33 126#include "AliCDBId.h"
8a2055e0 127#include "AliShuttleInterface.h"
ea199e33 128#include "AliTestShuttle.h"
8a2055e0 129#include "AliDCSValue.h"
130
ea199e33 131#include "Riostream.h"
132#include "TSystem.h"
ea199e33 133#include "TMap.h"
ea199e33 134#include "TObjArray.h"
ea199e33 135#include "TObjString.h"
8a2055e0 136#include "TString.h"
ea199e33 137#include "TRandom.h"
ea199e33 138#endif
139
6c870207 140//______________________________________________________________________________
49e110ec 141void TestMUONPreprocessor(Int_t runNumber=80,
142 const char* runType="CALIBRATION",
143 const char* sourceDirectory="/afs/cern.ch/user/l/laphecet/public")
ea199e33 144{
f37df338 145 // runType can be :
146 //
7103cd04 147 // PEDESTAL -> pedestals
49419555 148 // CALIBRATION -> gains
f37df338 149 // PHYSICS -> HV
150 // GMS
49e110ec 151
ea199e33 152 // create AliTestShuttle instance
153 // The parameters are run, startTime, endTime
6c870207 154
155 gSystem->Load("libTestShuttle.so");
156
608c3123 157 AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
9e62d05d 158
162637e4 159 const char* inputCDB = "local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB";
3dd0ddc5 160 //const char* inputCDB = "alien://folder=/alice/testdata/2008/TS08a/OCDB";
161
5699c0e6 162 AliTestShuttle::SetMainCDB(inputCDB);
162637e4 163 AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
9e62d05d 164
c2d0667a 165 TString rt(runType);
166 rt.ToUpper();
5699c0e6 167
c2d0667a 168 if ( rt.Contains("PHYSICS") )
5699c0e6 169 {
49e110ec 170 // Create DCS aliases
6c870207 171 UInt_t startTime, endTime;
172
6498767e 173 TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB, runNumber);
49e110ec 174
c2d0667a 175 if ( dcsAliasMap )
176 {
177 // now give the alias map to the shuttle
178 shuttle->SetDCSInput(dcsAliasMap);
179 }
180 }
5699c0e6 181
9e62d05d 182 printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
183 printf("Test Shuttle log dir: %s\n", AliShuttleInterface::GetShuttleLogDir());
184 printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
185 printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
186
608c3123 187 // The shuttle can process files that originate from DCS, DAQ and HLT.
ea199e33 188 // To test it, we provide some local files and locations where these would be found when
189 // the online machinery would be there.
190 // In real life this functions would be produces by the sub-detectors
191 // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
192 //
193 // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
194 // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
608c3123 195 // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
ea199e33 196
49e110ec 197 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC0",Form("%s/PEDESTALS/LDC0.ped",sourceDirectory));
198 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC1",Form("%s/PEDESTALS/LDC1.ped",sourceDirectory));
199 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC2",Form("%s/PEDESTALS/LDC2.ped",sourceDirectory));
200 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC3",Form("%s/PEDESTALS/LDC3.ped",sourceDirectory));
6c870207 201 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC4",Form("%s/PEDESTALS/LDC4.ped",sourceDirectory));
49419555 202
6c870207 203 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC0",Form("%s/CONFIG/LDC0.conf",sourceDirectory));
204 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC1",Form("%s/CONFIG/LDC1.conf",sourceDirectory));
205 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC2",Form("%s/CONFIG/LDC2.conf",sourceDirectory));
206 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC3",Form("%s/CONFIG/LDC3.conf",sourceDirectory));
207 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC4",Form("%s/CONFIG/LDC4.conf",sourceDirectory));
208
49e110ec 209 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC0",Form("%s/GAINS/LDC0.gain",sourceDirectory));
210 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC1",Form("%s/GAINS/LDC1.gain",sourceDirectory));
211 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC2",Form("%s/GAINS/LDC2.gain",sourceDirectory));
212 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC3",Form("%s/GAINS/LDC3.gain",sourceDirectory));
49419555 213
7eafe398 214 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","OCCUPANCY","MON",Form("%s/OCCUPANCY/mch.occupancy",sourceDirectory));
215
608c3123 216 // and GMS file
49e110ec 217 shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS",Form("%s/GMS/GMS.root",sourceDirectory));
038d1637 218
2ab3623b 219 // and then the trigger stuff
49e110ec 220 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LOCAL","LDC0",Form("%s/TRIGGER/MtgLocalMask-1.dat",sourceDirectory));
221 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","REGIONAL","LDC0",Form("%s/TRIGGER/MtgRegionalCrate-1.dat",sourceDirectory));
222 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","GLOBAL","LDC0",Form("%s/TRIGGER/MtgGlobalCrate-1.dat",sourceDirectory));
223 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LUT","LDC0",Form("%s/TRIGGER/MtgLocalLut-1.dat",sourceDirectory));
224 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","EXPORTED","LDC0",Form("%s/TRIGGER/ExportedFiles.dat",sourceDirectory));
225
608c3123 226 // The shuttle can read run parameters stored in the DAQ run logbook.
227 // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
228 // using GetRunParameter function.
229 // In real life the parameters will be retrieved automatically from the run logbook;
f37df338 230 shuttle->SetInputRunType(runType);
608c3123 231
ea199e33 232 // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
9e62d05d 233 new AliMUONTrackerPreprocessor(shuttle);
2ab3623b 234 new AliMUONTriggerPreprocessor(shuttle);
235
ea199e33 236 shuttle->Print();
237
238 // Test the preprocessor
239 shuttle->Process();
608c3123 240}
ea199e33 241
6c870207 242//______________________________________________________________________________
243void GenerateConfig()
244{
245 /// Generate "fake" configuration files for the tracker. One per LDC.
246
247 Bool_t undefStorage(kFALSE);
248
249 AliCDBManager* man = AliCDBManager::Instance();
250 if (!man->IsDefaultStorageSet())
251 {
252 undefStorage = kTRUE;
253 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
254 man->SetRun(0);
255 }
256
257 // Load mapping
258 Bool_t ok = AliMpCDB::LoadDDLStore();
259
260 if (undefStorage)
261 {
262 man->UnsetDefaultStorage();
263 }
264
265 if (!ok)
266 {
267 AliErrorGeneral("GenerateConfig","Could not load DDLStore from OCDB");
268 return;
269 }
270
271 ofstream* files[5];
272 for ( Int_t i = 0; i < 5; ++i )
273 {
274 files[i]=0;
275 }
276
277 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
278 AliMpBusPatch* bp;
279
280 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
281 {
282 Int_t ddl = bp->GetDdlId();
283
284 Int_t ldc = ddl/4;
285
286 if (!files[ldc])
287 {
288 files[ldc] = new ofstream(Form("LDC%d.conf",ldc));
289 *(files[ldc]) << "# changed" << endl;
290 }
291
292 for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
293 {
294 *(files[ldc]) << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
295 }
296 }
297
298 for ( Int_t i = 0; i < 5; ++i )
299 {
300 if ( files[i] ) files[i]->close();
301 delete files[i];
302 }
303}
304
305//______________________________________________________________________________
6498767e 306TMap* CreateDCSAliasMap(const char* inputCDB, Int_t runNumber)
608c3123 307{
49e110ec 308 /// Creates a DCS structure for MUON Tracker HV and Trigger DCS and Currents
608c3123 309 ///
310 /// The structure is the following:
311 /// TMap (key --> value)
312 /// <DCSAlias> --> <valueList>
313 /// <DCSAlias> is a string
314 /// <valueList> is a TObjArray of AliDCSValue
315 /// An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
316
5699c0e6 317 Bool_t undefStorage(kFALSE);
318
319 AliCDBManager* man = AliCDBManager::Instance();
320 if (!man->IsDefaultStorageSet())
321 {
322 undefStorage = kTRUE;
323 man->SetDefaultStorage(inputCDB);
6498767e 324 man->SetRun(runNumber);
5699c0e6 325 }
326
331a617a 327 // Load mapping
5699c0e6 328 Bool_t ok = AliMpCDB::LoadDDLStore();
329
330 if (undefStorage)
331 {
332 man->UnsetDefaultStorage();
333 }
334
335 if (!ok)
336 {
337 AliErrorGeneral("CreateDCSAliasMap","Could not load DDLStore from OCDB");
338 return 0x0;
339 }
ba55f1e6 340
608c3123 341 TMap* aliasMap = new TMap;
342 aliasMap->SetOwner(kTRUE);
343
344 TRandom random(0);
49e110ec 345
346 const Char_t* detName[2] = { "TRACKER", "TRIGGER" };
347
348 for(Int_t idet=0; idet<2; idet++){
349
350 TString sDetName(detName[idet]);
351 sDetName.ToUpper();
608c3123 352
49e110ec 353 AliMpDCSNamer dcsNamer(detName[idet]);
608c3123 354
49e110ec 355 TObjArray* aliases = dcsNamer.GenerateAliases();
608c3123 356
49e110ec 357 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
608c3123 358 {
49e110ec 359 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
360 TString& aliasName = alias->String();
361 if ( aliasName.Contains("sw") && sDetName.Contains("TRACKER"))
362 {
6c870207 363 // HV Switch (St345 only)
364 TObjArray* valueSet = new TObjArray;
365 valueSet->SetOwner(kTRUE);
366 Bool_t bvalue = kTRUE;
367 // Float_t r = random.Uniform();
368 // if ( r < 0.007 ) value = kFALSE;
369 // if ( aliasName.Contains("DE513sw2") ) value = kFALSE;
370
371 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
372 {
373 AliDCSValue* dcsValue = new AliDCSValue(bvalue,timeStamp);
374 valueSet->Add(dcsValue);
375 }
376 aliasMap->Add(new TObjString(*alias),valueSet);
608c3123 377 }
49e110ec 378 else
608c3123 379 {
6c870207 380 TObjArray* valueSet = new TObjArray;
381 valueSet->SetOwner(kTRUE);
382 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
383 {
384 Float_t value = 0;
385 if(sDetName.Contains("TRACKER")){
386 value = random.Gaus(1750,62.5);
387 if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.vMon") value = 500;
388 }
389 else if(aliasName.Contains("iMon")){
390 value = random.Gaus(2.,0.4);
391 }
392 else {
393 value = random.Gaus(8000.,16.);
394 }
395
396 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
397 valueSet->Add(dcsValue);
398 }
399 if ( aliasName == "MchHvLvLeft/Chamber04Left/Slat06.actual.vMon" ) continue;
400 if ( aliasName == "MTR_INSIDE_MT22_RPC3_HV.vEff" ) continue;
401 if ( aliasName == "MTR_OUTSIDE_MT21_RPC4_HV.actual.iMon" ) continue;
402 aliasMap->Add(new TObjString(*alias),valueSet);
608c3123 403 }
49e110ec 404 } // loop on aliases
6c870207 405
49e110ec 406 delete aliases;
407 } // loop on detectors (tracker and trigger)
608c3123 408
2fbe202b 409 AliMpCDB::UnloadAll();
410
608c3123 411 return aliasMap;
ea199e33 412}
608c3123 413