Updating macro to test GRP preprocessor with new input files.
[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   Int_t kRun = 7;
36   AliTestShuttle* shuttle = new AliTestShuttle(kRun, 1, 10);
37
38   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
39   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
40
41   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
42   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
43
44   // setting runtype
45   shuttle->SetInputRunType(runtype);
46
47   // simulating DCS DPs
48   TMap* dcsAliasMap = CreateDCSAliasMap(errorLevel);
49   shuttle->SetDCSInput(dcsAliasMap);
50
51   // simulating input from DAQ FXS
52   if (errorLevel != 2){
53           shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC35", "/home/zampolli/GRP190809/run000080740_GRP_gdc-aldaqpc035_Period_LHC09c.Seq_0.tag.root");
54           shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC36", "/home/zampolli/GRP190809/run000080740_GRP_gdc-aldaqpc036_Period_LHC09c.Seq_0.tag.root");
55           shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC44", "/home/zampolli/GRP190809/run000080740_GRP_gdc-aldaqpc044_Period_LHC09c.Seq_0.tag.root");
56           shuttle->AddInputFile(AliShuttleInterface::kDAQ, "GRP", "Period_LHC09c_TPC.Seq_0.tag.root", "GDC45", "/home/zampolli/GRP190809/run000080740_GRP_gdc-aldaqpc045_Period_LHC09c.Seq_0.tag.root");
57           
58   }
59
60   // simulating input from DCS FXS
61   if (errorLevel != 4 && !partition.IsNull() && detector.IsNull()){
62           shuttle->AddInputFile(AliShuttleInterface::kDCS, "GRP", "CTP_xcounters", "", gSystem->ExpandPathName("$ALICE_ROOT/GRP/CTP/xcounters.txt"));
63   }
64
65   Char_t * filename = gSystem->ExpandPathName("$ALICE_ROOT/GRP/CTP/p-p.cfg");
66   ifstream is;
67   is.open(filename);
68   is.seekg(0,ios::end);
69   int length = is.tellg();
70   const char *buffer = new char[length];
71   is.seekg(0,ios::beg);
72   is.read(buffer,length);
73   is.close();
74   const char *emptybuffer = NULL;
75
76   // simulating input from DAQ logbook_trigger_config
77   if {
78           (errorLevel != 3 && errorLevel != 7 && !partition.IsNull() && detector.IsNull()) shuttle->SetInputTriggerConfiguration(buffer);
79   }
80   else if (errorLevel == 7) {
81           shuttle->SetInputTriggerConfiguration(emptybuffer);
82   }
83   
84   // simulating input from DAQ logbook
85   if (errorLevel != 1){
86         shuttle->AddInputRunParameter("DAQ_time_start", "1233213.22");
87   }
88   if (errorLevel != 6){
89         shuttle->AddInputRunParameter("beamEnergy", "1400.");
90   }
91
92   shuttle->AddInputRunParameter("DAQ_time_end",   "1345645.22");
93   shuttle->AddInputRunParameter("beamType",    beamType);
94   shuttle->AddInputRunParameter("numberOfDetectors", "5");
95   shuttle->AddInputRunParameter("detectorMask", "34555");
96   shuttle->AddInputRunParameter("LHCperiod",    "LHC08b");
97   shuttle->AddInputRunParameter("partition",partition);
98   shuttle->AddInputRunParameter("detector",detector);
99
100   // simulating HLT
101   Bool_t hltStatus = kTRUE;
102   shuttle->SetInputHLTStatus(hltStatus);
103
104   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
105   AliPreprocessor* test = new AliGRPPreprocessor(shuttle);
106
107   // Test the preprocessor
108   shuttle->Process();
109
110   printf("\n\n");
111
112   // Check the file which should have been created
113   AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
114                         ->Get("GRP/GRP/Data", kRun);
115   if (!chkEntry) {
116     printf("The file is not there. Something went wrong.\n");
117     return;
118   }
119   chkEntry->PrintId();
120   chkEntry->GetObject()->Print();
121   printf("\n\n");
122
123 }
124
125 TMap* CreateDCSAliasMap(Int_t errorLevel)
126 {
127   // Creates a DCS structure
128   // The structure is the following:
129   // TMap (key --> value)
130   // <DCSAlias> --> <valueList>
131   // <DCSAlias> is a string
132   // <valueList> is a TObjArray of AliDCSValue
133   // An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
134   
135   const Int_t fgknDCSDP = 50;
136   const char* fgkDCSDataPoints[AliGRPPreprocessor::fgknDCSDP] = {
137                    "LHCState",              // missing in DCS
138                    "L3Polarity",
139                    "DipolePolarity",
140                    "LHCLuminosity",         // missing in DCS
141                    "BeamIntensity",         // missing in DCS
142                    "L3Current",
143                    "DipoleCurrent",
144                    "L3_BSF17_H1",
145                    "L3_BSF17_H2",
146                    "L3_BSF17_H3",
147                    "L3_BSF17_Temperature",
148                    "L3_BSF4_H1",
149                    "L3_BSF4_H2",
150                    "L3_BSF4_H3",
151                    "L3_BSF4_Temperature",
152                    "L3_BKF17_H1",
153                    "L3_BKF17_H2",
154                    "L3_BKF17_H3",
155                    "L3_BKF17_Temperature",
156                    "L3_BKF4_H1",
157                    "L3_BKF4_H2",
158                    "L3_BKF4_H3",
159                    "L3_BKF4_Temperature",
160                    "L3_BSF13_H1",
161                    "L3_BSF13_H2",
162                    "L3_BSF13_H3",
163                    "L3_BSF13_Temperature",
164                    "L3_BSF8_H1",
165                    "L3_BSF8_H2",
166                    "L3_BSF8_H3",
167                    "L3_BSF8_Temperature",
168                    "L3_BKF13_H1",
169                    "L3_BKF13_H2",
170                    "L3_BKF13_H3",
171                    "L3_BKF13_Temperature",
172                    "L3_BKF8_H1",
173                    "L3_BKF8_H2",
174                    "L3_BKF8_H3",
175                    "L3_BKF8_Temperature",
176                    "Dipole_Inside_H1",
177                    "Dipole_Inside_H2",
178                    "Dipole_Inside_H3",
179                    "Dipole_Inside_Temperature",
180                    "Dipole_Outside_H1",
181                    "Dipole_Outside_H2",
182                    "Dipole_Outside_H3",
183                    "Dipole_Outside_Temperature",
184                    "CavernTemperature",
185                    "CavernAtmosPressure",
186                    "SurfaceAtmosPressure"
187                  };
188
189   TMap* aliasMap;
190   TObjArray* valueSet;
191   AliDCSValue* dcsVal;
192   
193   aliasMap = new TMap;
194   aliasMap->SetOwner(1);
195   
196   // LHCState
197   valueSet = new TObjArray;
198   valueSet->SetOwner(1);
199   dcsVal = new AliDCSValue( 'F', 2 );
200   valueSet->Add(dcsVal);
201   aliasMap->Add( new TObjString(fgkDCSDataPoints[0]), valueSet );
202
203   // L3Polarity
204   valueSet = new TObjArray;
205   valueSet->SetOwner(1);
206   dcsVal = new AliDCSValue( kTRUE, 2 );
207   valueSet->Add(dcsVal);
208   // add the following two lines to test errors for changing polarity
209   //  dcsVal = new AliDCSValue( kFALSE, 2 );
210   //  valueSet->Add(dcsVal);
211   aliasMap->Add( new TObjString(fgkDCSDataPoints[1]), valueSet );
212   
213   // DipolePolarity
214   valueSet = new TObjArray;
215   valueSet->SetOwner(1);
216   dcsVal = new AliDCSValue( kTRUE, 2 );
217   valueSet->Add(dcsVal);
218   aliasMap->Add( new TObjString(fgkDCSDataPoints[2]), valueSet );
219   
220   TRandom random;
221
222   Int_t maxDPindex = 0;
223   if (errorLevel != 5) {
224           maxDPindex = fgknDCSDP;
225   }
226   else {
227           maxDPindex = 3;  // simulating only a few DP in case errorLevel=5
228   }
229
230   for( int nAlias=3; nAlias<maxDPindex; nAlias++)  {
231           if (nAlias>=7 && nAlias < 47) continue; 
232     valueSet = new TObjArray;
233     valueSet->SetOwner(1);
234
235     for (int timeStamp=0; timeStamp<10; timeStamp++) {
236       dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*nAlias), timeStamp+1);
237       valueSet->Add(dcsVal);
238     }
239     aliasMap->Add( new TObjString( fgkDCSDataPoints[nAlias]), valueSet );
240   }
241
242   // Hall Probes
243   TString probe1[3] = {"L3_BSF","L3_BKF","Dipole_"};
244   TString probe2[6] = {"17_","4_","13_","8_","Inside_","Outside_"};
245   TString probe3[4] = {"H1","H2","H3","Temperature"};
246   Int_t hp = 0;
247
248   for (Int_t i=0;i<3;i++){
249           for (Int_t j=0;j<6;j++){
250                   for (Int_t k=0;k<4;k++){
251                           TString dpAlias = probe1[i]+probe2[j]+probe3[k];
252                           valueSet = new TObjArray;
253                           valueSet->SetOwner(1);
254                           for (int timeStamp=0; timeStamp<10; timeStamp++) {
255                                   dcsVal = new AliDCSValue((Float_t) (timeStamp+1+10*hp), timeStamp+1);
256                                   valueSet->Add(dcsVal);
257                                   //cout << " hall probe = " << dpAlias << " with value = " << dcsVal->GetFloat() << endl;
258                           }
259                           aliasMap->Add( new TObjString(dpAlias), valueSet );
260                           hp++;
261                   }
262           }
263   }
264
265   return aliasMap;
266 }
267
268 /*
269 TMap* ReadDCSAliasMap()
270 {
271   // Open a file that contains DCS input data
272   // The CDB framework is used to open the file, this means the file is located
273   // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
274   // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
275   // An explanation of the structure can be found in CreateDCSAliasMap()
276
277   AliCDBEntry *entry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
278                         ->Get("DET/DCS/Data", 0);
279   return dynamic_cast<TMap*> (entry->GetObject());
280 }
281 */
282
283
284 void WriteDCSAliasMap()
285 {
286   // This writes the output from CreateDCSAliasMap to a CDB file
287
288   TMap* dcsAliasMap = CreateDCSAliasMap(Int_t errorLevel);
289
290   AliCDBMetaData metaData;
291   metaData.SetBeamPeriod(0);
292   metaData.SetResponsible("Ernesto Lopez Torres");
293   metaData.SetComment("Test object for TestGRPPreprocessor.C");
294
295   AliCDBId id("GRP/Data", 0, 0);
296
297   // look into AliTestShuttle's CDB main folder
298
299   AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
300                         ->Put(dcsAliasMap, id, &metaData);
301 }