Update the wagon task with pi0 correlations and change histogram ranges, some cosmeti...
[u/mrichter/AliRoot.git] / PMD / TestPreprocessor.C
CommitLineData
cda4fe9e 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
050c314f 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
cda4fe9e 10
11void TestPreprocessor()
12{
050c314f 13 // load library
14 gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle.so");
15
16 // create AliTestShuttle instance
17 // The parameters are run, startTime, endTime
18 AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1);
19
20
21 printf("Test Shuttle temp dir: %s\n", AliShuttleInterface::GetShuttleTempDir());
22
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
25 AliTestShuttle::SetMainCDB("local://TestCDB");
26 AliTestShuttle::SetMainRefStorage("local://TestReference");
27
28 printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
29 printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
30
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
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.
66
67 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "PMD", "PMD_PED", "GDC0", "PMD_PED.root");
68 shuttle->AddInputFile(AliShuttleInterface::kDAQ, "PMD", "PMDGAINS", "GDC0", "PMDGAINS.root");
69
70 // TODO(3)
71 //
72 // The shuttle can read run type stored in the DAQ logbook.
73 // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
74 // using GetRunType function.
75 shuttle->SetInputRunType("PHYSICS");
76
77 // TODO(4)
78 //
79 // The shuttle can read run parameters stored in the DAQ run logbook.
80 // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
81 // using GetRunParameter function.
82
83 shuttle->AddInputRunParameter("totalEvents", "30000");
84 shuttle->AddInputRunParameter("NumberOfGDCs", "15");
85
86 // TODO(5)
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
100 // TODO(6)
101 // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
102// AliPreprocessor* test = new AliTestPreprocessor(shuttle);
103 AliPMDPreprocessor* test = new AliPMDPreprocessor(shuttle);
104
105 // Test the preprocessor
106 shuttle->Process();
107
108 // TODO(7)
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
114 AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
115 ->Get("PMD/Calib/Ped", 0);
116 if (!chkEntry)
117 {
118 printf("The file is not there. Something went wrong.\n");
119 return;
120 }
121
122 AliPMDPedestal* output = dynamic_cast<AliPMDPedestal*> (chkEntry->GetObject());
123 // If everything went fine, draw the result
124 if (output)
125 output->Print();
cda4fe9e 126}
127
128TMap* CreateDCSAliasMap()
129{
050c314f 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
137
138 // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
139 // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
140
141 TMap* aliasMap = new TMap;
142 aliasMap->SetOwner(1);
143
144 TRandom random;
145
146 for(int nAlias=0;nAlias<6;nAlias++)
147 {
148 TObjArray* valueSet = new TObjArray;
149 valueSet->SetOwner(1);
150
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)
cda4fe9e 156 {
050c314f 157 AliDCSValue* dcsVal = new AliDCSValue((Float_t) (random.Gaus()+5*nAlias), timeStamp);
158 //printf("%s\n",dcsVal->ToString().Data());
159 valueSet->Add(dcsVal);
cda4fe9e 160 }
050c314f 161 aliasMap->Add(new TObjString(aliasName), valueSet);
162 }
163
164 return aliasMap;
cda4fe9e 165}
166
167TMap* ReadDCSAliasMap()
168{
050c314f 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
175 AliCDBEntry *entry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
176 ->Get("DET/DCS/Data", 0);
177 return dynamic_cast<TMap*> (entry->GetObject());
cda4fe9e 178}
179
180void WriteDCSAliasMap()
181{
050c314f 182 // This writes the output from CreateDCSAliasMap to a CDB file
183
184 TMap* dcsAliasMap = CreateDCSAliasMap();
185
186 AliCDBMetaData metaData;
187 metaData.SetBeamPeriod(0);
188 metaData.SetResponsible("Responsible person");
189 metaData.SetComment("Test object for TestPreprocessor.C");
190
191 AliCDBId id("DET/DCS/Data", 0, 0);
192
193 // look into AliTestShuttle's CDB main folder
194
195 AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
196 ->Put(dcsAliasMap, id, &metaData);
cda4fe9e 197}