Function Bool_t GetHLTStatus added to preprocessor. It returns the status of HLT
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / TestPreprocessor.C
CommitLineData
36137ac1 1/* $Id$ */
2
5c6b40ae 3// This class runs the test preprocessor
4// It uses AliTestShuttle to simulate a full Shuttle process
5
6// The input data is created in the functions
7// CreateDCSAliasMap() creates input that would in the same way come from DCS
8// ReadDCSAliasMap() reads from a file
9// CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle
10
11void TestPreprocessor()
12{
36137ac1 13 // load library
14 gSystem->Load("libTestShuttle.so");
5c6b40ae 15
d461a8a7 16 // create AliTestShuttle instance
17 // The parameters are run, startTime, endTime
18 AliTestShuttle* shuttle = new AliTestShuttle(7, 0, 1);
19
20
21 printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
22
eba76848 23 // TODO if needed, change location of OCDB and Reference test folders
24 // by default they are set to $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB and TestReference
441b0e9c 25 AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
26 AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
e19c88ea 27
9b19dde4 28 printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
29 printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
e19c88ea 30
36137ac1 31
32 // TODO(1)
33 //
34 // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
35 // some fake data has to be created.
36 //
37 // The "fake" input data can be taken using either (a) or (b):
38 // (a) data from a file: Use ReadDCSAliasMap()
39 // the format of the file is explained in ReadDCSAliasMap()
40 // To use it uncomment the following line:
41 //
42 //TMap* dcsAliasMap = ReadDCSAliasMap();
43 //
44 // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
45 // To use it uncomment the following line:
46 //
47 TMap* dcsAliasMap = CreateDCSAliasMap();
48
49 // now give the alias map to the shuttle
50 shuttle->SetDCSInput(dcsAliasMap);
51
52 // TODO(2)
53 //
54 // The shuttle can also process files that originate from DCS, DAQ and HLT.
55 // To test it, we provide some local files and locations where these would be found when
56 // the online machinery would be there.
57 // In real life this functions would be produces by the sub-detectors
58 // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
59 //
60 // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
61 // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
62 // In this example we add a file originating from the GDC with the id PEDESTALS
63 // Three files originating from different LDCs but with the same id are also added
fc5a4708 64 // Note that the test preprocessor name is TPC. The name of the detector's preprocessor must follow
65 // the "online" naming convention ALICE-INT-2003-039.
4a33bdd9 66 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "PEDESTALS", "GDC0", "file1.root");
9b19dde4 67 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC0", "file2a.root");
68 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC1", "file2b.root");
886d60e6 69 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC2", "file2c.root");
87968cd5 70 shuttle->AddInputFile(AliShuttleInterface::kHLT, "TPC", "HLTData", "source1", "hlt_file1.root");
71 shuttle->AddInputFile(AliShuttleInterface::kHLT, "TPC", "HLTData", "source2", "hlt_file2.root");
36137ac1 72
73 // TODO(3)
eba76848 74 //
9827400b 75 // The shuttle can read run type stored in the DAQ logbook.
441b0e9c 76 // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
77 // using GetRunType function.
9827400b 78 shuttle->SetInputRunType("PHYSICS");
441b0e9c 79
80 // TODO(4)
81 //
eba76848 82 // The shuttle can read run parameters stored in the DAQ run logbook.
83 // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
84 // using GetRunParameter function.
eba76848 85 shuttle->AddInputRunParameter("totalEvents", "30000");
86 shuttle->AddInputRunParameter("NumberOfGDCs", "15");
87
441b0e9c 88 // TODO(5)
d461a8a7 89 //
87968cd5 90 // The shuttle can read run parameters stored in the DAQ run logbook.
91 // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
92 // using GetRunParameter function.
93 shuttle->AddInputRunParameter("totalEvents", "30000");
94 shuttle->AddInputRunParameter("NumberOfGDCs", "15");
d461a8a7 95
87968cd5 96 // TODO(6) NEW!
97 //
98 // This is for preprocessor that require data from HLT.
99 // Since HLT may be switched off, the preprocessor should first query the Run logbook where
100 // the HLT status is stored. SHUTTLE implements a shortcut function (GetHLTStatus) that returns
101 // a bool directly. 1 = HLT ON, 0 = HLT OFF
102 //
d461a8a7 103
87968cd5 104 Bool_t hltStatus=kTRUE;
105 shuttle->SetInputHLTStatus(hltStatus);
d461a8a7 106
107
87968cd5 108 // TODO(7)
36137ac1 109 // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
fc5a4708 110 AliPreprocessor* test = new AliTestPreprocessor(shuttle);
36137ac1 111
112 // Test the preprocessor
113 shuttle->Process();
114
87968cd5 115 // TODO(8)
36137ac1 116 // In the preprocessor AliShuttleInterface::Store should be called to put the final
117 // data to the CDB. To check if all went fine have a look at the files produced in
118 // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
119 //
120 // Check the file which should have been created
d461a8a7 121 AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
441b0e9c 122 ->Get("TPC/Calib/Data", 7);
d461a8a7 123 if (!chkEntry)
36137ac1 124 {
125 printf("The file is not there. Something went wrong.\n");
126 return;
127 }
128
d461a8a7 129 AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (chkEntry->GetObject());
36137ac1 130 // If everything went fine, draw the result
131 if (output)
132 output->Draw();
5c6b40ae 133}
134
135TMap* CreateDCSAliasMap()
136{
36137ac1 137 // Creates a DCS structure
138 // The structure is the following:
139 // TMap (key --> value)
140 // <DCSAlias> --> <valueList>
141 // <DCSAlias> is a string
142 // <valueList> is a TObjArray of AliDCSValue
143 // An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
5c6b40ae 144
36137ac1 145 // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
146 // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
5c6b40ae 147
36137ac1 148 TMap* aliasMap = new TMap;
149 aliasMap->SetOwner(1);
5c6b40ae 150
36137ac1 151 TRandom random;
5c6b40ae 152
36137ac1 153 for(int nAlias=0;nAlias<6;nAlias++)
154 {
155 TObjArray* valueSet = new TObjArray;
156 valueSet->SetOwner(1);
5c6b40ae 157
36137ac1 158 TString aliasName="DCSAlias";
159 aliasName += nAlias;
160 //printf("\n\n alias: %s\n\n",aliasName.Data());
161
162 for (int timeStamp=0;timeStamp<1000;timeStamp+=10)
163 {
45a493ce 164 AliDCSValue* dcsVal = new AliDCSValue((Float_t) (random.Gaus()+5*nAlias), timeStamp);
36137ac1 165 //printf("%s\n",dcsVal->ToString().Data());
166 valueSet->Add(dcsVal);
167 }
168 aliasMap->Add(new TObjString(aliasName), valueSet);
169 }
5c6b40ae 170
171 return aliasMap;
172}
173
174TMap* ReadDCSAliasMap()
175{
36137ac1 176 // Open a file that contains DCS input data
177 // The CDB framework is used to open the file, this means the file is located
178 // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
179 // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
180 // An explanation of the structure can be found in CreateDCSAliasMap()
181
9b19dde4 182 AliCDBEntry *entry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
e19c88ea 183 ->Get("DET/DCS/Data", 0);
5c6b40ae 184 return dynamic_cast<TMap*> (entry->GetObject());
185}
186
36137ac1 187void WriteDCSAliasMap()
5c6b40ae 188{
36137ac1 189 // This writes the output from CreateDCSAliasMap to a CDB file
5c6b40ae 190
36137ac1 191 TMap* dcsAliasMap = CreateDCSAliasMap();
5c6b40ae 192
36137ac1 193 AliCDBMetaData metaData;
194 metaData.SetBeamPeriod(0);
195 metaData.SetResponsible("Responsible person");
196 metaData.SetComment("Test object for TestPreprocessor.C");
5c6b40ae 197
36137ac1 198 AliCDBId id("DET/DCS/Data", 0, 0);
5c6b40ae 199
e19c88ea 200 // look into AliTestShuttle's CDB main folder
5c6b40ae 201
9b19dde4 202 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
e19c88ea 203 ->Put(dcsAliasMap, id, &metaData);
5c6b40ae 204}