New CE DA ... (Jens)
[u/mrichter/AliRoot.git] / GRP / TestGRPPreprocessor.C
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   
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 // 8 --> Missing LTU configuration
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
28 #include <iostream>
29 #include <fstream>
30 using namespace std;
31
32 void TestGRPPreprocessor(const char* runtype="PHYSICS", TString partition="ALICE", TString detector="", TString beamType = "p-p", Int_t errorLevel=0)
33 {
34   gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle.so");
35
36   AliLog::SetClassDebugLevel("AliGRPPreprocessor",3);
37   Int_t kRun = 7;
38   AliTestShuttle* shuttle = new AliTestShuttle(kRun, 1000, 2000);
39
40   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
41   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
42
43   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
44   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
45
46   // setting runtype
47   shuttle->SetInputRunType(runtype);
48
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                   }
65                   if (errorLevel != 8 && !partition.IsNull() && detector.IsNull()){
66                           shuttle->SetLTUConfig(ltu,detOnlineName.Data());
67                   }
68           }
69   }
70
71   // simulating DCS DPs
72   TMap* dcsAliasMap = CreateDCSAliasMap(errorLevel);
73   shuttle->SetDCSInput(dcsAliasMap);
74
75   // simulating input from DAQ FXS
76   if (errorLevel != 2){
77           
78           //$ALICE_ROOT to be expanded manually by the user for this test macro 
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");
83           shuttle->AddInputFile(AliShuttleInterface::kDAQ, "SPD", "VertexDiamond", "gdc-GLOBAL-01", "$ALICE_ROOT/GRP/ShuttleInput/run000104892_SPD_mon-DA-SPD-0_VertexDiamond");
84           shuttle->AddInputFile(AliShuttleInterface::kDCS, "GRP", "LHCData", "", "$ALICE_ROOT/GRP/ShuttleInput/testRun_GRP_run_number_testRun_data.txt");
85           
86           /*
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");
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");
95           */  
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
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();
112   const char *emptybuffer = NULL;
113
114   // simulating input from DAQ logbook_trigger_config
115   if (errorLevel != 3 && errorLevel != 7 && !partition.IsNull() && detector.IsNull()) {
116                   cout << " adding trigger config " << endl;
117                   shuttle->SetInputTriggerConfiguration(buffer);
118   }
119   else if (errorLevel == 7) {
120           shuttle->SetInputTriggerConfiguration(emptybuffer);
121   }
122   
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
144   // simulating input from DAQ logbook
145   if (errorLevel != 1){
146         shuttle->AddInputRunParameter("DAQ_time_start", "1020");
147   }
148   if (errorLevel != 6){
149         shuttle->AddInputRunParameter("beamEnergy", "123");
150   }
151
152   shuttle->AddInputRunParameter("DAQ_time_end",   "1980");
153   shuttle->AddInputRunParameter("beamType", beamType);
154   shuttle->AddInputRunParameter("numberOfDetectors", "5");
155   shuttle->AddInputRunParameter("LHCperiod",    "LHC08b");
156   shuttle->AddInputRunParameter("partition",partition);
157   shuttle->AddInputRunParameter("detector",detector);
158
159   // simulating HLT
160   Bool_t hltStatus = kTRUE;
161   shuttle->SetInputHLTStatus(hltStatus);
162
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
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
182 }
183
184 TMap* CreateDCSAliasMap(Int_t errorLevel)
185 {
186   // Creates a DCS structure
187   // The structure is the following:
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
193   
194   const Int_t fgknDCSDP = 48;
195   const char* fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
196                    "L3Polarity",
197                    "DipolePolarity",
198                    "L3Current",
199                    "DipoleCurrent",
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",
240                    "CavernTemperature",
241                    "CavernAtmosPressure",
242                    "SurfaceAtmosPressure",
243                    "CavernAtmosPressure2",
244                  };
245
246   TMap* aliasMap;
247   TObjArray* valueSet;
248   AliDCSValue* dcsVal;
249   
250   aliasMap = new TMap;
251   aliasMap->SetOwner(1);
252   
253   // L3Polarity
254   valueSet = new TObjArray;
255   valueSet->SetOwner(1);
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 );
263   valueSet->Add(dcsVal);
264   // add the following two lines to test errors for changing polarity
265   //  dcsVal = new AliDCSValue( kFALSE, 2 );
266   //  valueSet->Add(dcsVal);
267   aliasMap->Add( new TObjString(fgkDCSDataPoints[1]), valueSet );
268   
269   // DipolePolarity
270   valueSet = new TObjArray;
271   valueSet->SetOwner(1);
272   dcsVal = new AliDCSValue( kTRUE, 1010 );
273   valueSet->Add(dcsVal);
274   dcsVal = new AliDCSValue( kTRUE, 1100 );
275   valueSet->Add(dcsVal);
276   dcsVal = new AliDCSValue( kTRUE, 1500 );
277   valueSet->Add(dcsVal);
278   dcsVal = new AliDCSValue( kTRUE, 1990 );
279   aliasMap->Add( new TObjString(fgkDCSDataPoints[2]), valueSet );
280
281
282   TRandom random;
283
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
292   for( int nAlias=2; nAlias<maxDPindex; nAlias++)  {
293           if (nAlias>=4 && nAlias < 44) continue; 
294     valueSet = new TObjArray;
295     valueSet->SetOwner(1);
296
297     Int_t timeStampValue[10] = { 1010, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1990};
298
299
300     for (int timeStamp=0; timeStamp<10; timeStamp++) {
301       dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*nAlias), timeStampValue[timeStamp]);
302       valueSet->Add(dcsVal);
303     }
304     cout << " simulating " << fgkDCSDataPoints[nAlias] << endl;
305     aliasMap->Add( new TObjString( fgkDCSDataPoints[nAlias]), valueSet );
306   }
307
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++) {
321                                   dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*hp), timeStampValue[timeStamp]);
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
331   return aliasMap;
332 }
333
334 /*
335 TMap* 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
350 void WriteDCSAliasMap()
351 {
352   // This writes the output from CreateDCSAliasMap to a CDB file
353
354   TMap* dcsAliasMap = CreateDCSAliasMap(Int_t errorLevel);
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 }