]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/TestMUONPreprocessor.C
Fix plus small changes
[u/mrichter/AliRoot.git] / MUON / TestMUONPreprocessor.C
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
20 /// \ingroup macros
21 /// \file TestMUONPreprocessor.C
22 /// \brief The macro for testing the shuttle preprocessors 
23 ///
24 /// This macro runs the test preprocessor for MUON.
25 /// It uses AliTestShuttle to simulate a full Shuttle process
26 ///
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 :
30 /// <pre>
31 /// gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle");
32 /// gSystem->Load("libMUONshuttle");
33 /// </pre>
34 /// Last line above assume you have $ALICE_ROOT/MUON/lib/tgt_[arch] (where
35 /// libMUONshuttle is located) in your LD_LIBRARY_PATH
36 ///
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 /// <pre>
44 /// cd $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB
45 /// mkdir -p MUON/Calib
46 /// cd MUON/Calib
47 /// ln -si $ALICE_ROOT/OCDB/MUON/Calib/MappingData .
48 /// </pre>
49 ///
50 /// and Align/Baseline if you'd like to test GMS subprocessor :
51 ///
52 /// <pre>
53 /// cd $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB
54 /// mkdir -p MUON/Align
55 /// cd MUON/Align
56 /// ln -si $ALICE_ROOT/OCDB/MUON/Align/Baseline .
57 /// </pre>
58 ///
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
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
66 ///
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 :
69 /// <pre>
70 /// CONFIG/
71 ///    LDC0.config
72 ///    LDC1.config
73 ///    LDC2.config
74 ///    LDC3.config
75 /// GAINS/
76 ///    LDC0.gain
77 ///    LDC1.gain
78 ///    LDC2.gain
79 ///    LDC3.gain
80 /// GMS/
81 ///    GMS.root
82 /// OCCUPANCY/
83 ///    mch.occupancy
84 /// PEDESTALS/
85 ///    LDC0.ped
86 ///    LDC1.ped
87 ///    LDC2.ped
88 ///    LDC3.ped
89 ///    LDC4.conf
90 /// CONFIG/
91 ///    LDC0.conf
92 ///    LDC1.conf
93 ///    LDC2.conf
94 ///    LDC3.conf
95 ///    LDC4.conf
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
112 /// </pre>
113 ///
114 /// For more information on usage, please see the \ref README_shuttle page.
115 ///
116 /// \author Laurent Aphecetche, SUBATECH Nantes; \n
117 ///         Diego Stocco, SUBATECH Nantes
118
119 #include "TestMUONPreprocessor.h"
120
121 #include "AliMUONTrackerPreprocessor.h"
122 #include "AliMUONTriggerPreprocessor.h"
123
124 #include "AliLog.h"
125
126 #include "AliMpBusPatch.h"
127 #include "AliMpExMap.h"
128 #include "AliMpHelper.h"
129 #include "AliMpDDLStore.h"
130 #include "AliMpDCSNamer.h"
131 #include "AliMpCDB.h"
132
133 #include "AliCDBManager.h"
134 #include "AliCDBEntry.h"
135 #include "AliCDBId.h"
136 #include "AliShuttleInterface.h"
137 #include "AliTestShuttle.h"
138 #include "AliDCSValue.h"
139
140 #include "Riostream.h"
141 #include "TSystem.h"
142 #include "TMap.h"
143 #include "TObjArray.h"
144 #include "TObjString.h"
145 #include "TString.h"
146 #include "TRandom.h"
147 #endif
148
149 //______________________________________________________________________________
150 void TestMUONPreprocessor(Int_t runNumber=80, 
151                           const char* runType="CALIBRATION",
152                           const char* sourceDirectory="/afs/cern.ch/user/l/laphecet/public")
153 {
154   // runType can be :
155   //
156   // PEDESTAL -> pedestals
157   // CALIBRATION -> gains
158   // PHYSICS -> HV
159   // GMS
160
161   // create AliTestShuttle instance
162   // The parameters are run, startTime, endTime
163   
164   gSystem->Load("libTestShuttle.so");
165
166   AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
167   
168   const char* inputCDB = "local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB";
169   
170   AliTestShuttle::SetMainCDB(inputCDB);
171   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
172
173   TString rt(runType);
174   rt.ToUpper();
175   
176   if ( rt.Contains("PHYSICS") )
177   {
178     // Create DCS aliases
179     TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB, runNumber);
180
181     if ( dcsAliasMap ) 
182     {
183       // now give the alias map to the shuttle
184       shuttle->SetDCSInput(dcsAliasMap);
185     }
186   }
187   
188   printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
189   printf("Test Shuttle log dir: %s\n", AliShuttleInterface::GetShuttleLogDir());
190   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
191   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
192   
193   // The shuttle can process files that originate from DCS, DAQ and HLT.
194   // To test it, we provide some local files and locations where these would be found when
195   // the online machinery would be there.
196   // In real life this functions would be produces by the sub-detectors
197   // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
198   //
199   // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
200   // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
201   // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
202
203   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC0",Form("%s/PEDESTALS/LDC0.ped",sourceDirectory));
204   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC1",Form("%s/PEDESTALS/LDC1.ped",sourceDirectory));
205   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC2",Form("%s/PEDESTALS/LDC2.ped",sourceDirectory));
206   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC3",Form("%s/PEDESTALS/LDC3.ped",sourceDirectory));
207   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC4",Form("%s/PEDESTALS/LDC4.ped",sourceDirectory));
208
209   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC0",Form("%s/CONFIG/LDC0.conf",sourceDirectory));
210   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC1",Form("%s/CONFIG/LDC1.conf",sourceDirectory));
211   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC2",Form("%s/CONFIG/LDC2.conf",sourceDirectory));
212   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC3",Form("%s/CONFIG/LDC3.conf",sourceDirectory));
213   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","CONFIG","LDC4",Form("%s/CONFIG/LDC4.conf",sourceDirectory));
214   
215   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC0",Form("%s/GAINS/LDC0.gain",sourceDirectory));
216   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC1",Form("%s/GAINS/LDC1.gain",sourceDirectory));
217   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC2",Form("%s/GAINS/LDC2.gain",sourceDirectory));
218   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC3",Form("%s/GAINS/LDC3.gain",sourceDirectory));
219
220   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","OCCUPANCY","MON",Form("%s/OCCUPANCY/mch.occupancy",sourceDirectory));
221
222   // and GMS file
223   shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS",Form("%s/GMS/GMS.root",sourceDirectory));
224
225   // and then the trigger stuff
226   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LOCAL","LDC0",Form("%s/TRIGGER/MtgLocalMask-1.dat",sourceDirectory));
227   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","REGIONAL","LDC0",Form("%s/TRIGGER/MtgRegionalCrate-1.dat",sourceDirectory));
228   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","GLOBAL","LDC0",Form("%s/TRIGGER/MtgGlobalCrate-1.dat",sourceDirectory));
229   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LUT","LDC0",Form("%s/TRIGGER/MtgLocalLut-1.dat",sourceDirectory));
230   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","EXPORTED","LDC0",Form("%s/TRIGGER/ExportedFiles.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 //______________________________________________________________________________
251 void GenerateConfig()
252 {
253   /// Generate "fake" configuration files for the tracker. One per LDC.
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 {
316   /// Creates a DCS structure for MUON Tracker HV and Trigger DCS and Currents
317   ///
318   /// The structure is the following:
319   ///   TMap (key --> value)
320   ///     <DCSAlias> --> <valueList>
321   ///     <DCSAlias> is a string
322   ///     <valueList> is a TObjArray of AliDCSValue
323   ///     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
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
400             {
401               value = random.Gaus(10,2);
402               if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.iMon") value = 50;
403             }
404           }
405           else if(aliasName.Contains("iMon")){
406             value = random.Gaus(2.,0.4);
407           }
408           else {
409             value = random.Gaus(8000.,16.);
410           }
411           
412           AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
413           valueSet->Add(dcsValue);
414         }
415         if ( aliasName == "MchHvLvLeft/Chamber04Left/Slat06.actual.vMon" ) continue;
416         if ( aliasName == "MTR_INSIDE_MT22_RPC3_HV.vEff" ) continue;
417         if ( aliasName == "MTR_OUTSIDE_MT21_RPC4_HV.actual.iMon" ) continue;
418         aliasMap->Add(new TObjString(*alias),valueSet);
419       }
420     } // loop on aliases
421     
422     delete aliases;
423   } // loop on detectors (tracker and trigger)
424   
425   AliMpCDB::UnloadAll();
426   
427   return aliasMap;
428 }
429