Run type field added in SHUTTLE framework. Run type is read from "run type" logbook...
[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.
9b19dde4 66 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "PEDESTALS", "GDC", "file1.root");
67 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC0", "file2a.root");
68 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC1", "file2b.root");
69 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "TPC", "DRIFTVELOCITY", "LDC2", "file2b.root");
36137ac1 70
71 // TODO(3)
eba76848 72 //
441b0e9c 73 // The shuttle can read run type for each detector stored in the "run type" logbook.
74 // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
75 // using GetRunType function.
76 shuttle->AddInputRunType("TPC", "PHYSICS");
77 shuttle->AddInputRunType("PHS", "PEDESTALS");
78
79 // TODO(4)
80 //
eba76848 81 // The shuttle can read run parameters stored in the DAQ run logbook.
82 // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
83 // using GetRunParameter function.
eba76848 84 shuttle->AddInputRunParameter("totalEvents", "30000");
85 shuttle->AddInputRunParameter("NumberOfGDCs", "15");
86
441b0e9c 87 // TODO(5)
d461a8a7 88 //
89 // The shuttle can query condition parameters valid from the current run from the OCDB
90 // To test it, we must first store the object into the OCDB. It will be retrieved in the preprocessor
91 // using GetFromOCDB function.
92
93 TObjString obj("This is a condition parameter stored in OCDB");
94 AliCDBId id("TPC/Calib/Data", 0, AliCDBRunRange::Infinity());
95 AliCDBMetaData md;
96 AliCDBEntry entry(&obj, id, &md);
97
98 shuttle->AddInputCDBEntry(&entry);
99
100
441b0e9c 101 // TODO(6)
36137ac1 102 // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
fc5a4708 103 AliPreprocessor* test = new AliTestPreprocessor(shuttle);
36137ac1 104
105 // Test the preprocessor
106 shuttle->Process();
107
441b0e9c 108 // TODO(7)
36137ac1 109 // In the preprocessor AliShuttleInterface::Store should be called to put the final
110 // data to the CDB. To check if all went fine have a look at the files produced in
111 // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
112 //
113 // Check the file which should have been created
d461a8a7 114 AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
441b0e9c 115 ->Get("TPC/Calib/Data", 7);
d461a8a7 116 if (!chkEntry)
36137ac1 117 {
118 printf("The file is not there. Something went wrong.\n");
119 return;
120 }
121
d461a8a7 122 AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (chkEntry->GetObject());
36137ac1 123 // If everything went fine, draw the result
124 if (output)
125 output->Draw();
5c6b40ae 126}
127
128TMap* CreateDCSAliasMap()
129{
36137ac1 130 // Creates a DCS structure
131 // The structure is the following:
132 // TMap (key --> value)
133 // <DCSAlias> --> <valueList>
134 // <DCSAlias> is a string
135 // <valueList> is a TObjArray of AliDCSValue
136 // An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
5c6b40ae 137
36137ac1 138 // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
139 // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
5c6b40ae 140
36137ac1 141 TMap* aliasMap = new TMap;
142 aliasMap->SetOwner(1);
5c6b40ae 143
36137ac1 144 TRandom random;
5c6b40ae 145
36137ac1 146 for(int nAlias=0;nAlias<6;nAlias++)
147 {
148 TObjArray* valueSet = new TObjArray;
149 valueSet->SetOwner(1);
5c6b40ae 150
36137ac1 151 TString aliasName="DCSAlias";
152 aliasName += nAlias;
153 //printf("\n\n alias: %s\n\n",aliasName.Data());
154
155 for (int timeStamp=0;timeStamp<1000;timeStamp+=10)
156 {
45a493ce 157 AliDCSValue* dcsVal = new AliDCSValue((Float_t) (random.Gaus()+5*nAlias), timeStamp);
36137ac1 158 //printf("%s\n",dcsVal->ToString().Data());
159 valueSet->Add(dcsVal);
160 }
161 aliasMap->Add(new TObjString(aliasName), valueSet);
162 }
5c6b40ae 163
164 return aliasMap;
165}
166
167TMap* ReadDCSAliasMap()
168{
36137ac1 169 // Open a file that contains DCS input data
170 // The CDB framework is used to open the file, this means the file is located
171 // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
172 // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
173 // An explanation of the structure can be found in CreateDCSAliasMap()
174
9b19dde4 175 AliCDBEntry *entry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
e19c88ea 176 ->Get("DET/DCS/Data", 0);
5c6b40ae 177 return dynamic_cast<TMap*> (entry->GetObject());
178}
179
36137ac1 180void WriteDCSAliasMap()
5c6b40ae 181{
36137ac1 182 // This writes the output from CreateDCSAliasMap to a CDB file
5c6b40ae 183
36137ac1 184 TMap* dcsAliasMap = CreateDCSAliasMap();
5c6b40ae 185
36137ac1 186 AliCDBMetaData metaData;
187 metaData.SetBeamPeriod(0);
188 metaData.SetResponsible("Responsible person");
189 metaData.SetComment("Test object for TestPreprocessor.C");
5c6b40ae 190
36137ac1 191 AliCDBId id("DET/DCS/Data", 0, 0);
5c6b40ae 192
e19c88ea 193 // look into AliTestShuttle's CDB main folder
5c6b40ae 194
9b19dde4 195 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
e19c88ea 196 ->Put(dcsAliasMap, id, &metaData);
5c6b40ae 197}