1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #if !defined(__CINT__) || defined(__MAKECINT__)
21 /// \file TestMUONPreprocessor.C
22 /// \brief The macro for testing the shuttle preprocessors
24 /// This macro runs the test preprocessor for MUON.
25 /// It uses AliTestShuttle to simulate a full Shuttle process
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 :
31 /// gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle");
32 /// gSystem->Load("libMUONshuttle");
34 /// Last line above assume you have $ALICE_ROOT/MUON/lib/tgt_[arch] (where
35 /// libMUONshuttle is located) in your LD_LIBRARY_PATH
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...
40 /// You must also make a link of some OCDB entries to have the mapping loaded
44 /// cd $ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB
45 /// mkdir -p MUON/Calib
47 /// ln -si $ALICE_ROOT/OCDB/MUON/Calib/MappingData .
50 /// and Align/Baseline if you'd like to test GMS subprocessor :
53 /// cd $ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB
54 /// mkdir -p MUON/Align
56 /// ln -si $ALICE_ROOT/OCDB/MUON/Align/Baseline .
59 /// The input data has to be created first by other processes (or is created
60 /// here by CreateDCSAliasMap() for tracker HV).
62 /// To play with it, you'll have to set/modify several lines, to
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
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 :
97 /// ExportedFiles.dat (mandatory)
98 /// MtgGlobalCrate-1.dat
100 /// MtgLocalMask-1.dat
101 /// MtgRegionalCrate-1.dat
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 :
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
114 /// For more information on usage, please see the \ref README_shuttle page.
116 /// \author Laurent Aphecetche, SUBATECH Nantes; \n
117 /// Diego Stocco, SUBATECH Nantes
119 #include "TestMUONPreprocessor.h"
121 #include "AliMUONTrackerPreprocessor.h"
122 #include "AliMUONTriggerPreprocessor.h"
126 #include "AliMpBusPatch.h"
127 #include "AliMpExMap.h"
128 #include "AliMpHelper.h"
129 #include "AliMpDDLStore.h"
130 #include "AliMpDCSNamer.h"
131 #include "AliMpCDB.h"
133 #include "AliCDBManager.h"
134 #include "AliCDBEntry.h"
135 #include "AliCDBId.h"
136 #include "AliShuttleInterface.h"
137 #include "AliTestShuttle.h"
138 #include "AliDCSValue.h"
140 #include "Riostream.h"
143 #include "TObjArray.h"
144 #include "TObjString.h"
149 //______________________________________________________________________________
150 void TestMUONPreprocessor(Int_t runNumber=80,
151 const char* runType="CALIBRATION",
152 const char* sourceDirectory="/afs/cern.ch/user/l/laphecet/public")
156 // PEDESTAL -> pedestals
157 // CALIBRATION -> gains
161 // create AliTestShuttle instance
162 // The parameters are run, startTime, endTime
164 gSystem->Load("libTestShuttle.so");
166 AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
168 const char* inputCDB = "local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB";
169 //const char* inputCDB = "alien://folder=/alice/testdata/2008/TS08a/OCDB";
171 AliTestShuttle::SetMainCDB(inputCDB);
172 AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
177 if ( rt.Contains("PHYSICS") )
179 // Create DCS aliases
180 UInt_t startTime, endTime;
182 TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB, runNumber);
186 // now give the alias map to the shuttle
187 shuttle->SetDCSInput(dcsAliasMap);
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());
196 // The shuttle can process files that originate from DCS, DAQ and HLT.
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.
202 // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
203 // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
204 // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
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));
210 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC4",Form("%s/PEDESTALS/LDC4.ped",sourceDirectory));
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));
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));
223 shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","OCCUPANCY","MON",Form("%s/OCCUPANCY/mch.occupancy",sourceDirectory));
226 shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS",Form("%s/GMS/GMS.root",sourceDirectory));
228 // and then the trigger stuff
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));
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;
239 shuttle->SetInputRunType(runType);
241 shuttle->AddInputRunParameter("totalEvents","20");
243 // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
244 new AliMUONTrackerPreprocessor(shuttle);
245 new AliMUONTriggerPreprocessor(shuttle);
249 // Test the preprocessor
253 //______________________________________________________________________________
254 void GenerateConfig()
256 /// Generate "fake" configuration files for the tracker. One per LDC.
258 Bool_t undefStorage(kFALSE);
260 AliCDBManager* man = AliCDBManager::Instance();
261 if (!man->IsDefaultStorageSet())
263 undefStorage = kTRUE;
264 man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
269 Bool_t ok = AliMpCDB::LoadDDLStore();
273 man->UnsetDefaultStorage();
278 AliErrorGeneral("GenerateConfig","Could not load DDLStore from OCDB");
283 for ( Int_t i = 0; i < 5; ++i )
288 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
291 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
293 Int_t ddl = bp->GetDdlId();
299 files[ldc] = new ofstream(Form("LDC%d.conf",ldc));
300 *(files[ldc]) << "# changed" << endl;
303 for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
305 *(files[ldc]) << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
309 for ( Int_t i = 0; i < 5; ++i )
311 if ( files[i] ) files[i]->close();
316 //______________________________________________________________________________
317 TMap* CreateDCSAliasMap(const char* inputCDB, Int_t runNumber)
319 /// Creates a DCS structure for MUON Tracker HV and Trigger DCS and Currents
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
328 Bool_t undefStorage(kFALSE);
330 AliCDBManager* man = AliCDBManager::Instance();
331 if (!man->IsDefaultStorageSet())
333 undefStorage = kTRUE;
334 man->SetDefaultStorage(inputCDB);
335 man->SetRun(runNumber);
339 Bool_t ok = AliMpCDB::LoadDDLStore();
343 man->UnsetDefaultStorage();
348 AliErrorGeneral("CreateDCSAliasMap","Could not load DDLStore from OCDB");
352 TMap* aliasMap = new TMap;
353 aliasMap->SetOwner(kTRUE);
357 const Char_t* detName[2] = { "TRACKER", "TRIGGER" };
359 for(Int_t idet=0; idet<2; idet++){
361 TString sDetName(detName[idet]);
364 AliMpDCSNamer dcsNamer(detName[idet]);
366 TObjArray* aliases = dcsNamer.GenerateAliases();
368 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
370 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
371 TString& aliasName = alias->String();
372 if ( aliasName.Contains("sw") && sDetName.Contains("TRACKER"))
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;
382 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
384 AliDCSValue* dcsValue = new AliDCSValue(bvalue,timeStamp);
385 valueSet->Add(dcsValue);
387 aliasMap->Add(new TObjString(*alias),valueSet);
391 TObjArray* valueSet = new TObjArray;
392 valueSet->SetOwner(kTRUE);
393 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
396 if(sDetName.Contains("TRACKER")){
397 value = random.Gaus(1750,62.5);
398 if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.vMon") value = 500;
400 else if(aliasName.Contains("iMon")){
401 value = random.Gaus(2.,0.4);
404 value = random.Gaus(8000.,16.);
407 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
408 valueSet->Add(dcsValue);
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);
418 } // loop on detectors (tracker and trigger)
420 AliMpCDB::UnloadAll();