Patch from Matthias Richter:
[u/mrichter/AliRoot.git] / GRP / TestGRPPreprocessor.C
CommitLineData
92e5c8ed 1
2// This macro runs the GRP test preprocessor
3// It uses AliTestShuttle to simulate a full Shuttle process
4
5// The input data is created in the functions
6// CreateDCSAliasMap() creates input that would in the same way come from DCS
7// ReadDCSAliasMap() reads from a file
8// CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle
9
e75e6e01 10// Taking as input runtype and errorLevel
11// errorLevel used to simulate errors:
12// 0 --> no error
13// 1 --> DAQ logbook error
14// 2 --> DAQ FXS error
15// 3 --> DAQ logbook_trigger_config erro
16// 4 --> DCS FXS error
17// 5 --> DCS DPs error
18// 6 --> Missing beamEnergy
19// 7 --> null buffer for Trigger Config
20
21// Need to include dummy files in TestShuttle/TestCDB for CTP Configuration and Scalers
22// (see macro $ALICE_ROOT/GRP/MakeCTPDummyEntries.C)
23
24// Modified by C. Zampolli
25
26
e3efae04 27#include <iostream>
28#include <fstream>
29using namespace std;
92e5c8ed 30
e75e6e01 31void TestGRPPreprocessor(const char* runtype="PHYSICS", TString partition="ALICE", TString detector="", TString beamType = "p-p", Int_t errorLevel=0)
92e5c8ed 32{
92e5c8ed 33 gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle.so");
34
7f32679b 35 AliLog::SetClassDebugLevel("AliGRPPreprocessor",3);
92e5c8ed 36 Int_t kRun = 7;
6614fa48 37 AliTestShuttle* shuttle = new AliTestShuttle(kRun, 1000, 2000);
92e5c8ed 38
e75e6e01 39 AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
40 AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
92e5c8ed 41
42 printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
43 printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
44
e75e6e01 45 // setting runtype
46 shuttle->SetInputRunType(runtype);
92e5c8ed 47
e75e6e01 48 // simulating DCS DPs
49 TMap* dcsAliasMap = CreateDCSAliasMap(errorLevel);
92e5c8ed 50 shuttle->SetDCSInput(dcsAliasMap);
51
e75e6e01 52 // simulating input from DAQ FXS
53 if (errorLevel != 2){
6614fa48 54 //$ALICE_ROOT to be expanded manually by the user for this test macro
7f32679b 55 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC35", "$ALICE_ROOT/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc035_Period_LHC09c.Seq_0.tag.root");
56 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC36", "$ALICE_ROOT/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc036_Period_LHC09c.Seq_0.tag.root");
57 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC44", "$ALICE_ROOT/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc044_Period_LHC09c.Seq_0.tag.root");
58 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC45", "$ALICE_ROOT/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc045_Period_LHC09c.Seq_0.tag.root");
6a150f83 59 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "SPD", "VertexDiamond", "gdc-GLOBAL-01", "$ALICE_ROOT/GRP/ShuttleInput/run000104892_SPD_mon-DA-SPD-0_VertexDiamond");
60 /*
6614fa48 61 // for example:
6a150f83 62 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC35", "/home/zampolli/SOFT/AliRoot/AliRoot_Trunk/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc035_Period_LHC09c.Seq_0.tag.root");
63 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC36", "/home/zampolli/SOFT/AliRoot/AliRoot_Trunk/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc036_Period_LHC09c.Seq_0.tag.root");
64 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC44", "/home/zampolli/SOFT/AliRoot/AliRoot_Trunk/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc044_Period_LHC09c.Seq_0.tag.root");
65 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC45", "/home/zampolli/SOFT/AliRoot/AliRoot_Trunk/GRP/ShuttleInput/run000080740_GRP_gdc-aldaqpc045_Period_LHC09c.Seq_0.tag.root");
66 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "SPD", "VertexDiamond", "gdc-GLOBAL-01", "/home/zampolli/SOFT/AliRoot/AliRoot_Trunk/GRP/ShuttleInput/run000104892_SPD_mon-DA-SPD-0_VertexDiamond");
67 */
e75e6e01 68 }
69
70 // simulating input from DCS FXS
71 if (errorLevel != 4 && !partition.IsNull() && detector.IsNull()){
72 shuttle->AddInputFile(AliShuttleInterface::kDCS, "GRP", "CTP_xcounters", "", gSystem->ExpandPathName("$ALICE_ROOT/GRP/CTP/xcounters.txt"));
73 }
74
e3efae04 75 Char_t * filename = gSystem->ExpandPathName("$ALICE_ROOT/GRP/CTP/p-p.cfg");
76 ifstream is;
77 is.open(filename);
78 is.seekg(0,ios::end);
79 int length = is.tellg();
80 const char *buffer = new char[length];
81 is.seekg(0,ios::beg);
82 is.read(buffer,length);
83 is.close();
e75e6e01 84 const char *emptybuffer = NULL;
92e5c8ed 85
e75e6e01 86 // simulating input from DAQ logbook_trigger_config
7f32679b 87 if (errorLevel != 3 && errorLevel != 7 && !partition.IsNull() && detector.IsNull()) {
88 cout << " adding trigger config " << endl;
89 shuttle->SetInputTriggerConfiguration(buffer);
e75e6e01 90 }
91 else if (errorLevel == 7) {
92 shuttle->SetInputTriggerConfiguration(emptybuffer);
93 }
e3efae04 94
6614fa48 95 // open text file with CTP timing params
96 Char_t * fileNameTiming = gSystem->ExpandPathName("$ALICE_ROOT/GRP/ShuttleInput/ctptime.tim");
97 ifstream ifstrTiming;
98 ifstrTiming.open(fileNameTiming);
99 ifstrTiming.seekg(0,ios::end);
100 int lengthTiming = ifstrTiming.tellg();
101 const char *bufferTiming = new char[lengthTiming];
102 ifstrTiming.seekg(0,ios::beg);
103 ifstrTiming.read(bufferTiming,lengthTiming);
104 ifstrTiming.close();
105 // const char *emptybuffer = NULL;
106
107 // simulating input from DAQ logbook_ctp_timing_params
108 if (errorLevel != 3 && errorLevel != 7 && !partition.IsNull() && detector.IsNull()) {
109 cout << " adding ctp timing params " <<endl;
110 shuttle->SetInputCTPTimeParams(bufferTiming);
111 }
112 else if (errorLevel == 7) {
113 shuttle->SetInputCTPTimeParams(emptybuffer);
114 }
115
e75e6e01 116 // simulating input from DAQ logbook
117 if (errorLevel != 1){
6614fa48 118 shuttle->AddInputRunParameter("DAQ_time_start", "1020");
e75e6e01 119 }
120 if (errorLevel != 6){
121 shuttle->AddInputRunParameter("beamEnergy", "1400.");
122 }
123
6614fa48 124 shuttle->AddInputRunParameter("DAQ_time_end", "1980");
e75e6e01 125 shuttle->AddInputRunParameter("beamType", beamType);
92e5c8ed 126 shuttle->AddInputRunParameter("numberOfDetectors", "5");
127 shuttle->AddInputRunParameter("detectorMask", "34555");
128 shuttle->AddInputRunParameter("LHCperiod", "LHC08b");
e75e6e01 129 shuttle->AddInputRunParameter("partition",partition);
130 shuttle->AddInputRunParameter("detector",detector);
92e5c8ed 131
e75e6e01 132 // simulating HLT
92e5c8ed 133 Bool_t hltStatus = kTRUE;
134 shuttle->SetInputHLTStatus(hltStatus);
135
92e5c8ed 136 // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
137 AliPreprocessor* test = new AliGRPPreprocessor(shuttle);
138
139 // Test the preprocessor
140 shuttle->Process();
141
142 printf("\n\n");
143
92e5c8ed 144 // Check the file which should have been created
145 AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
146 ->Get("GRP/GRP/Data", kRun);
147 if (!chkEntry) {
148 printf("The file is not there. Something went wrong.\n");
149 return;
150 }
151 chkEntry->PrintId();
152 chkEntry->GetObject()->Print();
153 printf("\n\n");
154
92e5c8ed 155}
156
e75e6e01 157TMap* CreateDCSAliasMap(Int_t errorLevel)
92e5c8ed 158{
159 // Creates a DCS structure
160 // The structure is the following:
e75e6e01 161 // TMap (key --> value)
162 // <DCSAlias> --> <valueList>
163 // <DCSAlias> is a string
164 // <valueList> is a TObjArray of AliDCSValue
165 // An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
92e5c8ed 166
ce996d13 167 const Int_t fgknDCSDP = 51;
92e5c8ed 168 const char* fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
e75e6e01 169 "LHCState", // missing in DCS
92e5c8ed 170 "L3Polarity",
171 "DipolePolarity",
e75e6e01 172 "LHCLuminosity", // missing in DCS
173 "BeamIntensity", // missing in DCS
92e5c8ed 174 "L3Current",
175 "DipoleCurrent",
e75e6e01 176 "L3_BSF17_H1",
177 "L3_BSF17_H2",
178 "L3_BSF17_H3",
179 "L3_BSF17_Temperature",
180 "L3_BSF4_H1",
181 "L3_BSF4_H2",
182 "L3_BSF4_H3",
183 "L3_BSF4_Temperature",
184 "L3_BKF17_H1",
185 "L3_BKF17_H2",
186 "L3_BKF17_H3",
187 "L3_BKF17_Temperature",
188 "L3_BKF4_H1",
189 "L3_BKF4_H2",
190 "L3_BKF4_H3",
191 "L3_BKF4_Temperature",
192 "L3_BSF13_H1",
193 "L3_BSF13_H2",
194 "L3_BSF13_H3",
195 "L3_BSF13_Temperature",
196 "L3_BSF8_H1",
197 "L3_BSF8_H2",
198 "L3_BSF8_H3",
199 "L3_BSF8_Temperature",
200 "L3_BKF13_H1",
201 "L3_BKF13_H2",
202 "L3_BKF13_H3",
203 "L3_BKF13_Temperature",
204 "L3_BKF8_H1",
205 "L3_BKF8_H2",
206 "L3_BKF8_H3",
207 "L3_BKF8_Temperature",
208 "Dipole_Inside_H1",
209 "Dipole_Inside_H2",
210 "Dipole_Inside_H3",
211 "Dipole_Inside_Temperature",
212 "Dipole_Outside_H1",
213 "Dipole_Outside_H2",
214 "Dipole_Outside_H3",
215 "Dipole_Outside_Temperature",
92e5c8ed 216 "CavernTemperature",
217 "CavernAtmosPressure",
ce996d13 218 "SurfaceAtmosPressure",
219 "CavernAtmosPressure2",
92e5c8ed 220 };
221
222 TMap* aliasMap;
223 TObjArray* valueSet;
224 AliDCSValue* dcsVal;
225
226 aliasMap = new TMap;
227 aliasMap->SetOwner(1);
228
6614fa48 229 /*
92e5c8ed 230 // LHCState
231 valueSet = new TObjArray;
232 valueSet->SetOwner(1);
e75e6e01 233 dcsVal = new AliDCSValue( 'F', 2 );
92e5c8ed 234 valueSet->Add(dcsVal);
e75e6e01 235 aliasMap->Add( new TObjString(fgkDCSDataPoints[0]), valueSet );
6614fa48 236 */
92e5c8ed 237
238 // L3Polarity
239 valueSet = new TObjArray;
240 valueSet->SetOwner(1);
6614fa48 241 dcsVal = new AliDCSValue( kTRUE, 1010 );
242 valueSet->Add(dcsVal);
243 dcsVal = new AliDCSValue( kTRUE, 1100 );
244 valueSet->Add(dcsVal);
245 dcsVal = new AliDCSValue( kTRUE, 1500 );
246 valueSet->Add(dcsVal);
247 dcsVal = new AliDCSValue( kTRUE, 1990 );
92e5c8ed 248 valueSet->Add(dcsVal);
dba333ae 249 // add the following two lines to test errors for changing polarity
250 // dcsVal = new AliDCSValue( kFALSE, 2 );
251 // valueSet->Add(dcsVal);
92e5c8ed 252 aliasMap->Add( new TObjString(fgkDCSDataPoints[1]), valueSet );
253
254 // DipolePolarity
255 valueSet = new TObjArray;
256 valueSet->SetOwner(1);
6614fa48 257 dcsVal = new AliDCSValue( kTRUE, 1010 );
258 valueSet->Add(dcsVal);
259 dcsVal = new AliDCSValue( kTRUE, 1100 );
92e5c8ed 260 valueSet->Add(dcsVal);
6614fa48 261 dcsVal = new AliDCSValue( kTRUE, 1500 );
262 valueSet->Add(dcsVal);
263 dcsVal = new AliDCSValue( kTRUE, 1990 );
92e5c8ed 264 aliasMap->Add( new TObjString(fgkDCSDataPoints[2]), valueSet );
6614fa48 265
266 // LHCLuminosity - keeping outside look to check procedure to calculate statistics values
267 valueSet = new TObjArray;
268 valueSet->SetOwner(1);
269 dcsVal = new AliDCSValue( (Float_t)2, 1010 );
270 valueSet->Add(dcsVal);
271 dcsVal = new AliDCSValue( (Float_t)4, 1100 );
272 valueSet->Add(dcsVal);
273 dcsVal = new AliDCSValue( (Float_t)6, 1200 );
274 valueSet->Add(dcsVal);
275 dcsVal = new AliDCSValue( (Float_t)8, 1985 );
276 valueSet->Add(dcsVal);
277 aliasMap->Add( new TObjString(fgkDCSDataPoints[3]), valueSet );
278
92e5c8ed 279 TRandom random;
280
e75e6e01 281 Int_t maxDPindex = 0;
282 if (errorLevel != 5) {
283 maxDPindex = fgknDCSDP;
284 }
285 else {
286 maxDPindex = 3; // simulating only a few DP in case errorLevel=5
287 }
288
6614fa48 289 for( int nAlias=4; nAlias<maxDPindex; nAlias++) {
e75e6e01 290 if (nAlias>=7 && nAlias < 47) continue;
92e5c8ed 291 valueSet = new TObjArray;
292 valueSet->SetOwner(1);
293
6614fa48 294 Int_t timeStampValue[10] = { 1010, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1990};
295
296
e75e6e01 297 for (int timeStamp=0; timeStamp<10; timeStamp++) {
6614fa48 298 dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*nAlias), timeStampValue[timeStamp]);
92e5c8ed 299 valueSet->Add(dcsVal);
300 }
ce996d13 301 cout << " simulating " << fgkDCSDataPoints[nAlias] << endl;
92e5c8ed 302 aliasMap->Add( new TObjString( fgkDCSDataPoints[nAlias]), valueSet );
303 }
304
e75e6e01 305 // Hall Probes
306 TString probe1[3] = {"L3_BSF","L3_BKF","Dipole_"};
307 TString probe2[6] = {"17_","4_","13_","8_","Inside_","Outside_"};
308 TString probe3[4] = {"H1","H2","H3","Temperature"};
309 Int_t hp = 0;
310
311 for (Int_t i=0;i<3;i++){
312 for (Int_t j=0;j<6;j++){
313 for (Int_t k=0;k<4;k++){
314 TString dpAlias = probe1[i]+probe2[j]+probe3[k];
315 valueSet = new TObjArray;
316 valueSet->SetOwner(1);
317 for (int timeStamp=0; timeStamp<10; timeStamp++) {
6614fa48 318 dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*hp), timeStampValue[timeStamp]);
e75e6e01 319 valueSet->Add(dcsVal);
320 //cout << " hall probe = " << dpAlias << " with value = " << dcsVal->GetFloat() << endl;
321 }
322 aliasMap->Add( new TObjString(dpAlias), valueSet );
323 hp++;
324 }
325 }
326 }
327
92e5c8ed 328 return aliasMap;
329}
330
331/*
332TMap* ReadDCSAliasMap()
333{
334 // Open a file that contains DCS input data
335 // The CDB framework is used to open the file, this means the file is located
336 // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
337 // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
338 // An explanation of the structure can be found in CreateDCSAliasMap()
339
340 AliCDBEntry *entry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
341 ->Get("DET/DCS/Data", 0);
342 return dynamic_cast<TMap*> (entry->GetObject());
343}
344*/
345
346
347void WriteDCSAliasMap()
348{
349 // This writes the output from CreateDCSAliasMap to a CDB file
350
e75e6e01 351 TMap* dcsAliasMap = CreateDCSAliasMap(Int_t errorLevel);
92e5c8ed 352
353 AliCDBMetaData metaData;
354 metaData.SetBeamPeriod(0);
355 metaData.SetResponsible("Ernesto Lopez Torres");
356 metaData.SetComment("Test object for TestGRPPreprocessor.C");
357
358 AliCDBId id("GRP/Data", 0, 0);
359
360 // look into AliTestShuttle's CDB main folder
361
362 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
363 ->Put(dcsAliasMap, id, &metaData);
364}