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