]> git.uio.no Git - u/mrichter/AliRoot.git/blob - GRP/TestGRPPreprocessor.C
- Implementing functions for the GRP preprocessor to retrieve DA output files from...
[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
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
27 #include <iostream>
28 #include <fstream>
29 using namespace std;
30
31 void TestGRPPreprocessor(const char* runtype="PHYSICS", TString partition="ALICE", TString detector="", TString beamType = "p-p", Int_t errorLevel=0)
32 {
33   gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle.so");
34
35   AliLog::SetClassDebugLevel("AliGRPPreprocessor",3);
36   Int_t kRun = 7;
37   AliTestShuttle* shuttle = new AliTestShuttle(kRun, 1000, 2000);
38
39   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
40   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
41
42   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
43   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
44
45   // setting runtype
46   shuttle->SetInputRunType(runtype);
47
48   // simulating DCS DPs
49   TMap* dcsAliasMap = CreateDCSAliasMap(errorLevel);
50   shuttle->SetDCSInput(dcsAliasMap);
51
52   // simulating input from DAQ FXS
53   if (errorLevel != 2){
54           //$ALICE_ROOT to be expanded manually by the user for this test macro 
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");
59           shuttle->AddInputFile(AliShuttleInterface::kDAQ, "SPD", "VertexDiamond", "gdc-GLOBAL-01", "$ALICE_ROOT/GRP/ShuttleInput/run000104892_SPD_mon-DA-SPD-0_VertexDiamond");
60           /*
61           // for example:
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           */
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
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();
84   const char *emptybuffer = NULL;
85
86   // simulating input from DAQ logbook_trigger_config
87   if (errorLevel != 3 && errorLevel != 7 && !partition.IsNull() && detector.IsNull()) {
88                   cout << " adding trigger config " << endl;
89                   shuttle->SetInputTriggerConfiguration(buffer);
90   }
91   else if (errorLevel == 7) {
92           shuttle->SetInputTriggerConfiguration(emptybuffer);
93   }
94   
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
116   // simulating input from DAQ logbook
117   if (errorLevel != 1){
118         shuttle->AddInputRunParameter("DAQ_time_start", "1020");
119   }
120   if (errorLevel != 6){
121         shuttle->AddInputRunParameter("beamEnergy", "1400.");
122   }
123
124   shuttle->AddInputRunParameter("DAQ_time_end",   "1980");
125   shuttle->AddInputRunParameter("beamType",    beamType);
126   shuttle->AddInputRunParameter("numberOfDetectors", "5");
127   shuttle->AddInputRunParameter("detectorMask", "34555");
128   shuttle->AddInputRunParameter("LHCperiod",    "LHC08b");
129   shuttle->AddInputRunParameter("partition",partition);
130   shuttle->AddInputRunParameter("detector",detector);
131
132   // simulating HLT
133   Bool_t hltStatus = kTRUE;
134   shuttle->SetInputHLTStatus(hltStatus);
135
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
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
155 }
156
157 TMap* CreateDCSAliasMap(Int_t errorLevel)
158 {
159   // Creates a DCS structure
160   // The structure is the following:
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
166   
167   const Int_t fgknDCSDP = 51;
168   const char* fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
169                    "LHCState",              // missing in DCS
170                    "L3Polarity",
171                    "DipolePolarity",
172                    "LHCLuminosity",         // missing in DCS
173                    "BeamIntensity",         // missing in DCS
174                    "L3Current",
175                    "DipoleCurrent",
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",
216                    "CavernTemperature",
217                    "CavernAtmosPressure",
218                    "SurfaceAtmosPressure",
219                    "CavernAtmosPressure2",
220                  };
221
222   TMap* aliasMap;
223   TObjArray* valueSet;
224   AliDCSValue* dcsVal;
225   
226   aliasMap = new TMap;
227   aliasMap->SetOwner(1);
228   
229   /*
230   // LHCState
231   valueSet = new TObjArray;
232   valueSet->SetOwner(1);
233   dcsVal = new AliDCSValue( 'F', 2 );
234   valueSet->Add(dcsVal);
235   aliasMap->Add( new TObjString(fgkDCSDataPoints[0]), valueSet );
236   */
237
238   // L3Polarity
239   valueSet = new TObjArray;
240   valueSet->SetOwner(1);
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 );
248   valueSet->Add(dcsVal);
249   // add the following two lines to test errors for changing polarity
250   //  dcsVal = new AliDCSValue( kFALSE, 2 );
251   //  valueSet->Add(dcsVal);
252   aliasMap->Add( new TObjString(fgkDCSDataPoints[1]), valueSet );
253   
254   // DipolePolarity
255   valueSet = new TObjArray;
256   valueSet->SetOwner(1);
257   dcsVal = new AliDCSValue( kTRUE, 1010 );
258   valueSet->Add(dcsVal);
259   dcsVal = new AliDCSValue( kTRUE, 1100 );
260   valueSet->Add(dcsVal);
261   dcsVal = new AliDCSValue( kTRUE, 1500 );
262   valueSet->Add(dcsVal);
263   dcsVal = new AliDCSValue( kTRUE, 1990 );
264   aliasMap->Add( new TObjString(fgkDCSDataPoints[2]), valueSet );
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
279   TRandom random;
280
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
289   for( int nAlias=4; nAlias<maxDPindex; nAlias++)  {
290           if (nAlias>=7 && nAlias < 47) continue; 
291     valueSet = new TObjArray;
292     valueSet->SetOwner(1);
293
294     Int_t timeStampValue[10] = { 1010, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1990};
295
296
297     for (int timeStamp=0; timeStamp<10; timeStamp++) {
298       dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*nAlias), timeStampValue[timeStamp]);
299       valueSet->Add(dcsVal);
300     }
301     cout << " simulating " << fgkDCSDataPoints[nAlias] << endl;
302     aliasMap->Add( new TObjString( fgkDCSDataPoints[nAlias]), valueSet );
303   }
304
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++) {
318                                   dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*hp), timeStampValue[timeStamp]);
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
328   return aliasMap;
329 }
330
331 /*
332 TMap* 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
347 void WriteDCSAliasMap()
348 {
349   // This writes the output from CreateDCSAliasMap to a CDB file
350
351   TMap* dcsAliasMap = CreateDCSAliasMap(Int_t errorLevel);
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 }