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