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