]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/TestShuttle/TestPreprocessor.C
adba4ba9163898b47a9469322d8ec44a203b020e
[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   // initialize location of CDB
17   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
18
19   // create AliTestShuttle instance
20   AliTestShuttle* shuttle = new AliTestShuttle();
21
22   // TODO(1)
23   //
24   // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
25   // some fake data has to be created.
26   //
27   // The "fake" input data can be taken using either (a) or (b):
28   // (a) data from a file: Use ReadDCSAliasMap()
29   //     the format of the file is explained in ReadDCSAliasMap()
30   //     To use it uncomment the following line:
31   //
32   //TMap* dcsAliasMap = ReadDCSAliasMap();
33   //
34   // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
35   //     To use it uncomment the following line:
36   //
37   TMap* dcsAliasMap = CreateDCSAliasMap();
38
39   // now give the alias map to the shuttle
40   shuttle->SetDCSInput(dcsAliasMap);
41
42   // TODO(2)
43   //
44   // The shuttle can also process files that originate from DCS, DAQ and HLT.
45   // To test it, we provide some local files and locations where these would be found when
46   // the online machinery would be there.
47   // In real life this functions would be produces by the sub-detectors
48   // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
49   //
50   // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
51   // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
52   // In this example we add a file originating from the GDC with the id PEDESTALS
53   // Three files originating from different LDCs but with the same id are also added
54   shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "PEDESTALS", "GDC", "file1.root");
55   shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "DRIFTVELOCITY", "LDC0", "file2a.root");
56   shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "DRIFTVELOCITY", "LDC1", "file2b.root");
57   shuttle->AddInputFile(AliTestShuttle::kDAQ, "DET", "DRIFTVELOCITY", "LDC2", "file2b.root");
58
59   // TODO(3)
60   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
61   AliPreprocessor* pp = new AliTestPreprocessor("DET", shuttle);
62
63   // Test the preprocessor
64   shuttle->Process();
65
66   // TODO(4)
67   // In the preprocessor AliShuttleInterface::Store should be called to put the final
68   // data to the CDB. To check if all went fine have a look at the files produced in
69   // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
70   //
71   // Check the file which should have been created
72   AliCDBEntry* entry = AliCDBManager::Instance()->Get("DET/SHUTTLE/Data", 0);
73   if (!entry)
74   {
75     printf("The file is not there. Something went wrong.\n");
76     return;
77   }
78
79   AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (entry->GetObject());
80   // If everything went fine, draw the result
81   if (output)
82     output->Draw();
83 }
84
85 TMap* CreateDCSAliasMap()
86 {
87   // Creates a DCS structure
88   // The structure is the following:
89   //   TMap (key --> value)
90   //     <DCSAlias> --> <valueList>
91   //     <DCSAlias> is a string
92   //     <valueList> is a TObjArray of AliDCSValue
93   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
94
95   // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
96   // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
97
98   TMap* aliasMap = new TMap;
99   aliasMap->SetOwner(1);
100
101   TRandom random;
102
103   for(int nAlias=0;nAlias<6;nAlias++)
104   {
105     TObjArray* valueSet = new TObjArray;
106     valueSet->SetOwner(1);
107
108     TString aliasName="DCSAlias";
109     aliasName += nAlias;
110     //printf("\n\n alias: %s\n\n",aliasName.Data());
111
112     for (int timeStamp=0;timeStamp<1000;timeStamp+=10)
113     {
114       AliSimpleValue* simVal = new AliSimpleValue((Float_t) (random.Gaus()+5*nAlias));
115       AliDCSValue* dcsVal = new AliDCSValue(*simVal, timeStamp);
116       //printf("%s\n",dcsVal->ToString().Data());
117       valueSet->Add(dcsVal);
118     }
119     aliasMap->Add(new TObjString(aliasName), valueSet);
120   }
121
122   return aliasMap;
123 }
124
125 TMap* ReadDCSAliasMap()
126 {
127   // Open a file that contains DCS input data
128   // The CDB framework is used to open the file, this means the file is located
129   // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
130   // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
131   // An explanation of the structure can be found in CreateDCSAliasMap()
132
133   AliCDBEntry *entry = AliCDBManager::Instance()->Get("DET/DCS/Data", 0);
134   return dynamic_cast<TMap*> (entry->GetObject());
135 }
136
137 void WriteDCSAliasMap()
138 {
139   // This writes the output from CreateDCSAliasMap to a CDB file
140
141   TMap* dcsAliasMap = CreateDCSAliasMap();
142
143   AliCDBMetaData metaData;
144         metaData.SetBeamPeriod(0);
145         metaData.SetResponsible("Responsible person");
146         metaData.SetComment("Test object for TestPreprocessor.C");
147
148   AliCDBId id("DET/DCS/Data", 0, 0);
149
150   // initialize location of CDB
151   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
152
153   AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
154 }