AliRoot Core  3abf5b4 (3abf5b4)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TestMUONPreprocessor.C
Go to the documentation of this file.
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 
109 
110 #include "TestMUONPreprocessor.h"
111 
114 
115 #include "AliLog.h"
116 
117 #include "AliMpBusPatch.h"
118 #include "AliMpExMap.h"
119 #include "AliMpHelper.h"
120 #include "AliMpDDLStore.h"
121 #include "AliMpDCSNamer.h"
122 #include "AliMpCDB.h"
123 
124 #include "AliCDBManager.h"
125 #include "AliCDBEntry.h"
126 #include "AliCDBId.h"
127 #include "AliShuttleInterface.h"
128 #include "AliTestShuttle.h"
129 #include "AliDCSValue.h"
130 
131 #include "Riostream.h"
132 #include "TSystem.h"
133 #include "TMap.h"
134 #include "TObjArray.h"
135 #include "TObjString.h"
136 #include "TString.h"
137 #include "TRandom.h"
138 
139 #endif
140 
141 //______________________________________________________________________________
142 void TestMUONPreprocessor(Int_t runNumber=80,
143  const char* runType="PHYSICS",
144  const char* sourceDirectory="$HOME/Downloads/muontestshuttle")
145 {
146  // runType can be :
147  //
148  // PEDESTAL -> pedestals
149  // PHYSICS -> HV
150  // GMS
151 
152  // create AliTestShuttle instance
153  // The parameters are run, startTime, endTime
154 
155  AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
156 
157  const char* inputCDB = "local://$ALICE_ROOT/../src/SHUTTLE/TestShuttle/TestCDB";
158 
159  AliTestShuttle::SetMainCDB(inputCDB);
160  AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
161 
162  TString rt(runType);
163  rt.ToUpper();
164 
165  if ( rt.Contains("PHYSICS") || rt.Contains("CALIBRATION") )
166  {
167  // Create DCS aliases
168  TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB, runNumber);
169 
170  if ( dcsAliasMap )
171  {
172  // now give the alias map to the shuttle
173  shuttle->SetDCSInput(dcsAliasMap);
174  }
175  }
176 
177  printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
178  printf("Test Shuttle log dir: %s\n", AliShuttleInterface::GetShuttleLogDir());
179  printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
180  printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
181 
182  // The shuttle can process files that originate from DCS, DAQ and HLT.
183  // To test it, we provide some local files and locations where these would be found when
184  // the online machinery would be there.
185  // In real life this functions would be produces by the sub-detectors
186  // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
187  //
188  // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
189  // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
190  // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
191 
192  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC0",Form("%s/PEDESTALS/LDC0.ped",sourceDirectory));
193  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC1",Form("%s/PEDESTALS/LDC1.ped",sourceDirectory));
194  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC2",Form("%s/PEDESTALS/LDC2.ped",sourceDirectory));
195  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC3",Form("%s/PEDESTALS/LDC3.ped",sourceDirectory));
196  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC4",Form("%s/PEDESTALS/LDC4.ped",sourceDirectory));
197 
198  if ( rt.Contains("PHYSICS") )
199  {
200  // simulate a change of configuration during the run
201  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC0",Form("%s/CONFIGPAR/LDC0.conf",sourceDirectory));
202  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC1",Form("%s/CONFIGPAR/LDC1.conf",sourceDirectory));
203  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC2",Form("%s/CONFIGPAR/LDC2.conf",sourceDirectory));
204  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC3",Form("%s/CONFIGPAR/LDC3.conf",sourceDirectory));
205  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC4",Form("%s/CONFIGPAR/LDC4.conf",sourceDirectory));
206  }
207  else
208  {
209  // configuration as done by the pedestal run
210  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC0",Form("%s/CONFIG/LDC0.conf",sourceDirectory));
211  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC1",Form("%s/CONFIG/LDC1.conf",sourceDirectory));
212  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC2",Form("%s/CONFIG/LDC2.conf",sourceDirectory));
213  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC3",Form("%s/CONFIG/LDC3.conf",sourceDirectory));
214  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC4",Form("%s/CONFIG/LDC4.conf",sourceDirectory));
215  }
216 
217  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","OCCUPANCY","MON",Form("%s/OCCUPANCY/mch.occupancy",sourceDirectory));
218 
219  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","BPEVO","MON",Form("%s/BPEVO/mchbpevo.root",sourceDirectory));
220 
221  // and GMS file
222  shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS",Form("%s/GMS/GMS.root",sourceDirectory));
223 
224  // and then the trigger stuff
225  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LOCAL","LDC0",Form("%s/TRIGGER/MtgLocalMask-1.dat",sourceDirectory));
226  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","REGIONAL","LDC0",Form("%s/TRIGGER/MtgRegionalCrate-1.dat",sourceDirectory));
227  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","GLOBAL","LDC0",Form("%s/TRIGGER/MtgGlobalCrate-1.dat",sourceDirectory));
228  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LUT","LDC0",Form("%s/TRIGGER/MtgLocalLut-1.dat",sourceDirectory));
229  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","EXPORTED","LDC0",Form("%s/TRIGGER/ExportedFiles.dat",sourceDirectory));
230  shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","TRIGSCAL","LDC0",Form("%s/TRIGGER/MtgTrigScalers.dat",sourceDirectory));
231 
232  // The shuttle can read run parameters stored in the DAQ run logbook.
233  // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
234  // using GetRunParameter function.
235  // In real life the parameters will be retrieved automatically from the run logbook;
236  shuttle->SetInputRunType(runType);
237 
238  shuttle->AddInputRunParameter("totalEvents","20");
239 
240  // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
241  new AliMUONTrackerPreprocessor(shuttle);
242  new AliMUONTriggerPreprocessor(shuttle);
243 
244  shuttle->Print();
245 
246  // Test the preprocessor
247  shuttle->Process();
248 }
249 
250 //______________________________________________________________________________
252 {
254 
255  Bool_t undefStorage(kFALSE);
256 
257  AliCDBManager* man = AliCDBManager::Instance();
258  if (!man->IsDefaultStorageSet())
259  {
260  undefStorage = kTRUE;
261  man->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
262  man->SetRun(0);
263  }
264 
265  // Load mapping
266  Bool_t ok = AliMpCDB::LoadDDLStore();
267 
268  if (undefStorage)
269  {
270  man->UnsetDefaultStorage();
271  }
272 
273  if (!ok)
274  {
275  AliErrorGeneral("GenerateConfig","Could not load DDLStore from OCDB");
276  return;
277  }
278 
279  ofstream* files[5];
280  for ( Int_t i = 0; i < 5; ++i )
281  {
282  files[i]=0;
283  }
284 
285  TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
286  AliMpBusPatch* bp;
287 
288  while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
289  {
290  Int_t ddl = bp->GetDdlId();
291 
292  Int_t ldc = ddl/4;
293 
294  if (!files[ldc])
295  {
296  files[ldc] = new ofstream(Form("LDC%d.conf",ldc));
297  *(files[ldc]) << "# changed" << endl;
298  }
299 
300  for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
301  {
302  *(files[ldc]) << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
303  }
304  }
305 
306  for ( Int_t i = 0; i < 5; ++i )
307  {
308  if ( files[i] ) files[i]->close();
309  delete files[i];
310  }
311 }
312 
313 //______________________________________________________________________________
314 TMap* CreateDCSAliasMap(const char* inputCDB, Int_t runNumber)
315 {
324 
325  Bool_t undefStorage(kFALSE);
326 
327  AliCDBManager* man = AliCDBManager::Instance();
328  if (!man->IsDefaultStorageSet())
329  {
330  undefStorage = kTRUE;
331  man->SetDefaultStorage(inputCDB);
332  man->SetRun(runNumber);
333  }
334 
335  // Load mapping
336  Bool_t ok = AliMpCDB::LoadDDLStore();
337 
338  if (undefStorage)
339  {
340  man->UnsetDefaultStorage();
341  }
342 
343  if (!ok)
344  {
345  AliErrorGeneral("CreateDCSAliasMap","Could not load DDLStore from OCDB");
346  return 0x0;
347  }
348 
349  TMap* aliasMap = new TMap;
350  aliasMap->SetOwner(kTRUE);
351 
352  TRandom random(0);
353 
354  const Char_t* detName[2] = { "TRACKER", "TRIGGER" };
355 
356  for(Int_t idet=0; idet<2; idet++){
357 
358  TString sDetName(detName[idet]);
359  sDetName.ToUpper();
360 
361  AliMpDCSNamer dcsNamer(detName[idet]);
362 
363  TObjArray* aliases = dcsNamer.GenerateAliases();
364 
365  for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
366  {
367  TObjString* alias = static_cast<TObjString*>(aliases->At(i));
368  TString& aliasName = alias->String();
369  if ( aliasName.Contains("sw") && sDetName.Contains("TRACKER"))
370  {
371  // HV Switch (St345 only)
372  TObjArray* valueSet = new TObjArray;
373  valueSet->SetOwner(kTRUE);
374  Bool_t bvalue = kTRUE;
375  // Float_t r = random.Uniform();
376  // if ( r < 0.007 ) value = kFALSE;
377  // if ( aliasName.Contains("DE513sw2") ) value = kFALSE;
378 
379  for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
380  {
381  AliDCSValue* dcsValue = new AliDCSValue(bvalue,timeStamp);
382  valueSet->Add(dcsValue);
383  }
384  aliasMap->Add(new TObjString(*alias),valueSet);
385  }
386  else
387  {
388  TObjArray* valueSet = new TObjArray;
389  valueSet->SetOwner(kTRUE);
390  for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
391  {
392  Float_t value = 0;
393  if(sDetName.Contains("TRACKER")){
394  if ( aliasName.Contains("vMon"))
395  {
396  value = random.Gaus(1750,62.5);
397  if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.vMon") value = 500;
398  }
399  else if ( aliasName.Contains("iMon") )
400  {
401  value = random.Gaus(10,2);
402  if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.iMon") value = 50;
403  }
404  else if ( aliasName.Contains("ann"))
405  {
406  value = random.Gaus(2.62,0.05);
407  }
408  else if ( aliasName.Contains("anp"))
409  {
410  value = random.Gaus(2.72,0.05);
411  }
412  else if ( aliasName.Contains("dig"))
413  {
414  value = random.Gaus(3.4,0.05);
415  }
416  else if ( aliasName.Contains("Crocu"))
417  {
418  value = random.Gaus(3.35,0.05);
419  }
420  }
421  else if(aliasName.Contains("iMon")){
422  value = random.Gaus(2.,0.4);
423  }
424  else {
425  value = random.Gaus(8000.,16.);
426  }
427 
428  AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
429  valueSet->Add(dcsValue);
430  }
431  if ( aliasName == "MchHvLvLeft/Chamber04Left/Slat06.actual.vMon" ) continue;
432  if ( aliasName == "MTR_INSIDE_MT22_RPC3_HV.vEff" ) continue;
433  if ( aliasName == "MTR_OUTSIDE_MT21_RPC4_HV.actual.iMon" ) continue;
434  aliasMap->Add(new TObjString(*alias),valueSet);
435  }
436  } // loop on aliases
437 
438  delete aliases;
439  } // loop on detectors (tracker and trigger)
440 
442 
443  return aliasMap;
444 }
Int_t GetNofManus() const
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
void GenerateConfig()
#define TObjArray
void TestMUONPreprocessor(Int_t runNumber=80, const char *runType="PHYSICS", const char *sourceDirectory="$HOME/Downloads/muontestshuttle")
Collection of methods usefull to DCS handling for MUON TRK and TRG.
Definition: AliMpDCSNamer.h:22
static Bool_t LoadDDLStore(Bool_t warn=false)
Definition: AliMpCDB.cxx:149
The definitions for the macro TestMUONPreprocessor.C.
Int_t GetManuId(Int_t index) const
static AliMpDDLStore * Instance(Bool_t warn=true)
Int_t GetDdlId() const
Return the Ddl Id.
Definition: AliMpBusPatch.h:97
Int_t GetId() const
Return the unique Id.
Definition: AliMpBusPatch.h:89
The class defines the properties of BusPatch.
Definition: AliMpBusPatch.h:21
static void UnloadAll()
Definition: AliMpCDB.cxx:520
Shuttle preprocessor for MUON trigger.
TObjArray * GenerateAliases(const char *pattern="") const
TMap * CreateDCSAliasMap(const char *inputCDB, Int_t runNumber)
Create a fake DCS alias map.
Shuttle preprocessor for MUON tracker.