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