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