]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/TestMUONPreprocessor.C
Update of GMS subprocessor to take into account incremental computation of alignement...
[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 /// </pre>
33 ///
34 /// Having $ALICE_ROOT/SHUTTLE/TestShuttle directory in your LD_LIBRARY_PATH
35 /// (or DYLD_LIBRARY_PATH on Mac OS X) won't hurt either...
36 ///
37 /// You must also make a link of some OCDB entries to have the mapping loaded 
38 /// correctly :
39 ///
40 /// cd $ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB
41 /// mkdir -p MUON/Calib
42 /// cd MUON/Calib
43 /// ln -si $ALICE_ROOT/OCDB/MUON/Calib/MappingData .
44 ///
45 /// and Align/Baseline if you'd like to test GMS subprocessor :
46 ///
47 /// cd $ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB
48 /// mkdir -p MUON/Align/Baseline
49 /// cd MUON/Align
50 /// ln -si $ALICE_ROOT/OCDB/MUON/Align/Baseline .
51 ///
52 /// The input data has to be created first by other processes (or is created
53 /// here by CreateDCSAliasMap() for tracker HV).
54 ///
55 /// To play with it, you'll have to set/modify several lines, to
56 /// - a) select input files, using shuttle->AddInputFile()
57 /// - b) select run type, using shuttle->AddInputRunParameter() (the run type
58 ///      dictates which task is really performed by the MUONPreprocessor
59 ///
60 /// The sourceDirectory is there to "emulate" what the real preprocessor will
61 /// find on the FXS, and is assumed to have the following structure :
62 /// <pre>
63 /// GAINS/
64 ///    LDC0.gain
65 ///    LDC1.gain
66 ///    LDC2.gain
67 ///    LDC3.gain
68 /// GMS/
69 ///    GMS.root
70 /// PEDESTALS/
71 ///    LDC0.ped
72 ///    LDC1.ped
73 ///    LDC2.ped
74 ///    LDC3.ped
75 /// TRIGGER/
76 ///    ExportedFiles.dat (mandatory)
77 ///    MtgGlobalCrate-1.dat
78 ///    MtgLocalLut-1.dat
79 ///    MtgLocalMask-1.dat
80 ///    MtgRegionalCrate-1.dat
81 /// </pre>
82 ///
83 /// IMPORTANT:
84 /// The trigger files have to be present in order for the algorithm to work correctly.
85 /// If you want to test the Trigger DCS maps only, but you don't have the .dat trigger files,
86 /// you have to create dummy files through :
87 /// <pre>
88 /// cd sourceDirectory/TRIGGER
89 /// echo -e "MtgLocalMask-1.dat\nMtgRegionalCrate-1.dat\nMtgGlobalCrate-1.dat\nMtgLocalLut-1.dat" > ExportedFiles.dat
90 /// touch MtgLocalMask-1.dat MtgRegionalCrate-1.dat MtgGlobalCrate-1.dat MtgLocalLut-1.dat
91 /// </pre>
92 ///
93 /// For more information on usage, please see the \ref README_shuttle page.
94 ///
95 /// \author Laurent Aphecetche, SUBATECH Nantes; \n
96 ///         Diego Stocco, SUBATECH Nantes
97
98 #include "TestMUONPreprocessor.h"
99
100 #include "AliMUONTrackerPreprocessor.h"
101 #include "AliMUONTriggerPreprocessor.h"
102
103 #include "AliLog.h"
104
105 #include "AliMpExMap.h"
106 #include "AliMpHelper.h"
107 #include "AliMpDCSNamer.h"
108 #include "AliMpCDB.h"
109
110 #include "AliCDBManager.h"
111 #include "AliCDBEntry.h"
112 #include "AliCDBId.h"
113 #include "AliShuttleInterface.h"
114 #include "AliTestShuttle.h"
115 #include "AliDCSValue.h"
116
117 #include "Riostream.h"
118 #include "TSystem.h"
119 #include "TMap.h"
120 #include "TObjArray.h"
121 #include "TObjString.h"
122 #include "TString.h"
123 #include "TRandom.h"
124 #endif
125
126 void TestMUONPreprocessor(Int_t runNumber=80, 
127                           const char* runType="CALIBRATION",
128                           const char* sourceDirectory="/afs/cern.ch/user/l/laphecet/public")
129 {
130   // runType can be :
131   //
132   // PEDESTAL -> pedestals
133   // CALIBRATION -> gains
134   // PHYSICS -> HV
135   // GMS
136
137   // create AliTestShuttle instance
138   // The parameters are run, startTime, endTime
139   AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
140   
141   const char* inputCDB = "local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB";
142   //const char* inputCDB = "alien://folder=/alice/testdata/2008/TS08a/OCDB";
143   
144   AliTestShuttle::SetMainCDB(inputCDB);
145   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
146
147   TString rt(runType);
148   rt.ToUpper();
149   
150   if ( rt.Contains("PHYSICS") )
151   {
152     // Create DCS aliases
153     TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB, runNumber);
154
155     if ( dcsAliasMap ) 
156     {
157       // now give the alias map to the shuttle
158       shuttle->SetDCSInput(dcsAliasMap);
159     }
160   }
161   
162   printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
163   printf("Test Shuttle log dir: %s\n", AliShuttleInterface::GetShuttleLogDir());
164   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
165   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
166   
167   // The shuttle can process files that originate from DCS, DAQ and HLT.
168   // To test it, we provide some local files and locations where these would be found when
169   // the online machinery would be there.
170   // In real life this functions would be produces by the sub-detectors
171   // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
172   //
173   // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
174   // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
175   // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
176
177   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC0",Form("%s/PEDESTALS/LDC0.ped",sourceDirectory));
178   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC1",Form("%s/PEDESTALS/LDC1.ped",sourceDirectory));
179   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC2",Form("%s/PEDESTALS/LDC2.ped",sourceDirectory));
180   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC3",Form("%s/PEDESTALS/LDC3.ped",sourceDirectory));
181
182   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC0",Form("%s/GAINS/LDC0.gain",sourceDirectory));
183   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC1",Form("%s/GAINS/LDC1.gain",sourceDirectory));
184   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC2",Form("%s/GAINS/LDC2.gain",sourceDirectory));
185   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC3",Form("%s/GAINS/LDC3.gain",sourceDirectory));
186
187   // and GMS file
188   shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS",Form("%s/GMS/GMS.root",sourceDirectory));
189
190   // and then the trigger stuff
191   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LOCAL","LDC0",Form("%s/TRIGGER/MtgLocalMask-1.dat",sourceDirectory));
192   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","REGIONAL","LDC0",Form("%s/TRIGGER/MtgRegionalCrate-1.dat",sourceDirectory));
193   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","GLOBAL","LDC0",Form("%s/TRIGGER/MtgGlobalCrate-1.dat",sourceDirectory));
194   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LUT","LDC0",Form("%s/TRIGGER/MtgLocalLut-1.dat",sourceDirectory));
195   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","EXPORTED","LDC0",Form("%s/TRIGGER/ExportedFiles.dat",sourceDirectory));
196
197   // The shuttle can read run parameters stored in the DAQ run logbook.
198   // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
199   // using GetRunParameter function.
200   // In real life the parameters will be retrieved automatically from the run logbook;
201   shuttle->SetInputRunType(runType);
202   
203   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
204   new AliMUONTrackerPreprocessor(shuttle);
205   new AliMUONTriggerPreprocessor(shuttle);
206   
207   shuttle->Print();
208   
209   // Test the preprocessor
210   shuttle->Process();
211 }
212
213 TMap* CreateDCSAliasMap(const char* inputCDB, Int_t runNumber)
214 {
215   /// Creates a DCS structure for MUON Tracker HV and Trigger DCS and Currents
216   ///
217   /// The structure is the following:
218   ///   TMap (key --> value)
219   ///     <DCSAlias> --> <valueList>
220   ///     <DCSAlias> is a string
221   ///     <valueList> is a TObjArray of AliDCSValue
222   ///     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
223   
224   Bool_t undefStorage(kFALSE);
225   
226   AliCDBManager* man = AliCDBManager::Instance();
227   if (!man->IsDefaultStorageSet())
228   {
229     undefStorage = kTRUE;
230     man->SetDefaultStorage(inputCDB);
231     man->SetRun(runNumber);
232   }
233   
234   // Load mapping
235   Bool_t ok = AliMpCDB::LoadDDLStore();
236   
237   if (undefStorage)
238   {
239     man->UnsetDefaultStorage();
240   }
241   
242   if (!ok)
243   {
244     AliErrorGeneral("CreateDCSAliasMap","Could not load DDLStore from OCDB");
245     return 0x0;
246   }
247
248   TMap* aliasMap = new TMap;
249   aliasMap->SetOwner(kTRUE);
250   
251   TRandom random(0);
252
253   const Char_t* detName[2] = { "TRACKER", "TRIGGER" };
254
255   for(Int_t idet=0; idet<2; idet++){
256
257     TString sDetName(detName[idet]);
258     sDetName.ToUpper();
259   
260     AliMpDCSNamer dcsNamer(detName[idet]);
261   
262     TObjArray* aliases = dcsNamer.GenerateAliases();
263   
264     for ( Int_t i = 0; i < aliases->GetEntries(); ++i ) 
265     {
266       TObjString* alias = static_cast<TObjString*>(aliases->At(i));
267       TString& aliasName = alias->String();
268       if ( aliasName.Contains("sw") && sDetName.Contains("TRACKER")) 
269       {
270         // HV Switch (St345 only)
271         TObjArray* valueSet = new TObjArray;
272         valueSet->SetOwner(kTRUE);
273         Bool_t value = kTRUE;
274 //      Float_t r = random.Uniform();
275 //      if ( r < 0.007 ) value = kFALSE;      
276 //      if ( aliasName.Contains("DE513sw2") ) value = kFALSE;
277       
278         for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
279         {
280           AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
281           valueSet->Add(dcsValue);
282         }
283         aliasMap->Add(new TObjString(*alias),valueSet);
284       }
285       else
286       {
287         TObjArray* valueSet = new TObjArray;
288         valueSet->SetOwner(kTRUE);
289         for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
290         {
291           Float_t value = 0;
292           if(sDetName.Contains("TRACKER")){
293             value = random.Gaus(1750,62.5);
294             if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.vMon") value = 500;
295           }
296           else if(aliasName.Contains("iMon")){
297             value = random.Gaus(2.,0.4);
298           }
299           else {
300             value = random.Gaus(8000.,16.);
301           }
302         
303           AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
304           valueSet->Add(dcsValue);
305         }
306         if ( aliasName == "MchHvLvLeft/Chamber04Left/Slat06.actual.vMon" ) continue;
307         if ( aliasName == "MTR_INSIDE_MT22_RPC3_HV.vEff" ) continue;
308         if ( aliasName == "MTR_OUTSIDE_MT21_RPC4_HV.actual.iMon" ) continue;
309         aliasMap->Add(new TObjString(*alias),valueSet);
310       }
311     } // loop on aliases
312
313     delete aliases;
314   } // loop on detectors (tracker and trigger)
315   
316
317     
318   AliMpCDB::UnloadAll();
319   
320   return aliasMap;
321 }
322