]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/TestMUONPreprocessor.C
Adding MtgCurrent.dat input file for trigger
[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 /// This macro runs the test preprocessor for MUON.
21 /// It uses AliTestShuttle to simulate a full Shuttle process
22 ///
23 /// The input data has to be created first by other processes (or is created
24 /// here by CreateDCSAliasMap() for tracker HV).
25 ///
26 /// To play with it, you'll have to set/modify several lines, to
27 /// a) select input files, using shuttle->AddInputFile()
28 /// b) select run type, using shuttle->AddInputRunParameter() (the run type
29 ///    dictates which task is really performed by the MUONPreprocessor
30 ///
31 /// You must load relevant libraries (besides normal MUON ones) before
32 /// compiling this macro :
33 ///
34 /// gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle");
35 /// gSystem->Load("libMUONshuttle.so");
36 ///
37 ///
38 /// For more information on usage, please see READMEshuttle.
39 ///
40 // By Laurent Aphecetche, SUBATECH Nantes
41
42 #include "TestMUONPreprocessor.h"
43
44 #include "AliMUONTrackerPreprocessor.h"
45 #include "AliMUONTriggerPreprocessor.h"
46
47 #include "AliLog.h"
48
49 #include "AliMpExMap.h"
50 #include "AliMpHelper.h"
51 #include "AliMpHVNamer.h"
52 #include "AliMpCDB.h"
53
54 #include "AliCDBManager.h"
55 #include "AliCDBEntry.h"
56 #include "AliCDBId.h"
57 #include "AliShuttleInterface.h"
58 #include "AliTestShuttle.h"
59 #include "AliDCSValue.h"
60
61 #include "Riostream.h"
62 #include "TSystem.h"
63 #include "TMap.h"
64 #include "TObjArray.h"
65 #include "TObjString.h"
66 #include "TString.h"
67 #include "TRandom.h"
68 #endif
69
70 void TestMUONPreprocessor(Int_t runNumber=80, const char* runType="PEDESTAL_RUN")
71 {
72   // runType can be :
73   //
74   // PEDESTAL_RUN -> pedestals
75   // ELECTRONICS_CALIBRATION_RUN -> gains
76   // PHYSICS -> HV
77   // GMS
78   
79   // create AliTestShuttle instance
80   // The parameters are run, startTime, endTime
81   AliTestShuttle* shuttle = new AliTestShuttle(runNumber, 0, 1);
82   
83   const char* inputCDB = "local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB";
84     
85   AliTestShuttle::SetMainCDB(inputCDB);
86   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
87
88   // Create DCS HV aliases
89   TMap* dcsAliasMap = CreateDCSAliasMap(inputCDB);
90   
91   if ( dcsAliasMap ) 
92   {
93     // now give the alias map to the shuttle
94     shuttle->SetDCSInput(dcsAliasMap);
95   }
96   
97   
98   printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
99   printf("Test Shuttle log dir: %s\n", AliShuttleInterface::GetShuttleLogDir());
100   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
101   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
102   
103   // The shuttle can process files that originate from DCS, DAQ and HLT.
104   // To test it, we provide some local files and locations where these would be found when
105   // the online machinery would be there.
106   // In real life this functions would be produces by the sub-detectors
107   // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
108   //
109   // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
110   // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
111   // In this example we add 4 files originating from different LDCs but with the same id (PEDESTALS)
112
113   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC0","$ALICE_ROOT/MUON/data/LDC0.ped");
114   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC1","$ALICE_ROOT/MUON/data/LDC1.ped");
115   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC2","$ALICE_ROOT/MUON/data/LDC2.ped");
116   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","PEDESTALS","LDC3","$ALICE_ROOT/MUON/data/LDC3.ped");
117   
118   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC0","$ALICE_ROOT/MUON/data/LDC0.gain");
119   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC1","$ALICE_ROOT/MUON/data/LDC1.gain");
120   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC2","$ALICE_ROOT/MUON/data/LDC2.gain");
121   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MCH","GAINS","LDC3","$ALICE_ROOT/MUON/data/LDC3.gain");
122   
123   // and GMS file
124   shuttle->AddInputFile(AliTestShuttle::kDCS,"MCH","GMS","GMS","$ALICE_ROOT/MUON/data/GMS.root");
125
126   // and then the trigger stuff
127   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LOCAL","LDC0","$ALICE_ROOT/MUON/data/MtgLocalMask-1.dat");
128   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","REGIONAL","LDC0","$ALICE_ROOT/MUON/data/MtgRegionalCrate-1.dat");
129   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","GLOBAL","LDC0","$ALICE_ROOT/MUON/data/MtgGlobalCrate-1.dat");
130   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","LUT","LDC0","$ALICE_ROOT/MUON/data/MtgLocalLut-1.dat");
131   shuttle->AddInputFile(AliTestShuttle::kDAQ,"MTR","CURRENT","LDC0","$ALICE_ROOT/MUON/data/MtgCurrent.dat");
132   
133   // The shuttle can read run parameters stored in the DAQ run logbook.
134   // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
135   // using GetRunParameter function.
136   // In real life the parameters will be retrieved automatically from the run logbook;
137   shuttle->SetInputRunType(runType);
138   
139   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
140   new AliMUONTrackerPreprocessor(shuttle);
141   new AliMUONTriggerPreprocessor(shuttle);
142   
143   shuttle->Print();
144   
145   // Test the preprocessor
146   shuttle->Process();
147 }
148
149 TMap* CreateDCSAliasMap(const char* inputCDB)
150 {
151   /// Creates a DCS structure for MUON Tracker HV
152   ///
153   /// The structure is the following:
154   ///   TMap (key --> value)
155   ///     <DCSAlias> --> <valueList>
156   ///     <DCSAlias> is a string
157   ///     <valueList> is a TObjArray of AliDCSValue
158   ///     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
159   
160   Bool_t undefStorage(kFALSE);
161   
162   AliCDBManager* man = AliCDBManager::Instance();
163   if (!man->IsDefaultStorageSet())
164   {
165     undefStorage = kTRUE;
166     man->SetDefaultStorage(inputCDB);
167   }
168   
169   // Load mapping
170   Bool_t ok = AliMpCDB::LoadDDLStore();
171   
172   if (undefStorage)
173   {
174     man->UnsetDefaultStorage();
175   }
176   
177   if (!ok)
178   {
179     AliErrorGeneral("CreateDCSAliasMap","Could not load DDLStore from OCDB");
180     return 0x0;
181   }
182
183   TMap* aliasMap = new TMap;
184   aliasMap->SetOwner(kTRUE);
185   
186   TRandom random(0);
187   
188   AliMpHVNamer hvNamer;
189   
190   TObjArray* aliases = hvNamer.GenerateAliases();
191   
192   for ( Int_t i = 0; i < aliases->GetEntries(); ++i ) 
193   {
194     TObjString* alias = static_cast<TObjString*>(aliases->At(i));
195     TString& aliasName = alias->String();
196     if ( aliasName.Contains("sw") ) 
197     {
198       // HV Switch (St345 only)
199       TObjArray* valueSet = new TObjArray;
200       valueSet->SetOwner(kTRUE);
201       Bool_t value = kTRUE;
202 //      Float_t r = random.Uniform();
203 //      if ( r < 0.007 ) value = kFALSE;      
204 //      if ( aliasName.Contains("DE513sw2") ) value = kFALSE;
205       
206       for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
207       {
208         AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
209         valueSet->Add(dcsValue);
210       }
211       aliasMap->Add(new TObjString(*alias),valueSet);
212     }
213     else
214     {
215       TObjArray* valueSet = new TObjArray;
216       valueSet->SetOwner(kTRUE);
217       for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
218       {
219         Float_t value = random.Gaus(1750,62.5);
220         if ( aliasName == "MchHvLvLeft/Chamber00Left/Quad2Sect1.actual.vMon") value = 500;
221         AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
222         valueSet->Add(dcsValue);
223       }
224       if ( aliasName == "MchHvLvLeft/Chamber04Left/Slat06.actual.vMon" ) continue;
225       aliasMap->Add(new TObjString(*alias),valueSet);
226     }
227   }
228   
229   delete aliases;
230     
231   return aliasMap;
232 }
233