]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/TestZDCPreprocessor.C
Error in Digits2Raw method corrected
[u/mrichter/AliRoot.git] / ZDC / TestZDCPreprocessor.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 TestZDCPreprocessor(Int_t obj=0)
12 {
13   // load library
14   gSystem->Load("libTestShuttle.so");
15
16   // create AliTestShuttle instance
17   // The parameters are run, startTime, endTime
18   AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1);
19
20   // TODO if needed, change location of OCDB and Reference test folders
21   // by default they are set to $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB and TestReference
22   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
23   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
24
25   printf("Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
26   printf("Test Reference storage Uri: %s\n", AliShuttleInterface::GetMainRefStorage().Data());
27
28   // TODO(1)
29   //
30   // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
31   // some fake data has to be created.
32   //
33   // The "fake" input data can be taken using either (a) or (b):
34   // (a) data from a file: Use ReadDCSAliasMap()
35   //     the format of the file is explained in ReadDCSAliasMap()
36   //     To use it uncomment the following line:
37   //
38   //TMap* dcsAliasMap = ReadDCSAliasMap();
39   //
40   // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
41   //     To use it uncomment the following line:
42   //
43   TMap* dcsAliasMap = CreateDCSAliasMap();
44   WriteDCSAliasMap();
45
46   // now give the alias map to the shuttle
47   shuttle->SetDCSInput(dcsAliasMap);
48
49   // TODO(2)
50   //
51   // The shuttle can also process files that originate from DCS, DAQ and HLT.
52   // To test it, we provide some local files and locations where these would be found when
53   // the online machinery would be there.
54   // In real life this functions would be produces by the sub-detectors
55   // calibration programs in DCS, DAQ or HLT. These files can then be retrieved using the Shuttle.
56   //
57   // Files are added with the function AliTestShuttle::AddInputFile. The syntax is:
58   // AddInputFile(<system>, <detector>, <id>, <source>, <local-file>)
59   // In this example we add a file originating from the GDC with the id PEDESTALS
60   // Three files originating from different LDCs but with the same id are also added
61   // Note that the test preprocessor name is TPC. The name of the detector's preprocessor must follow
62   // the "online" naming convention ALICE-INT-2003-039.
63   //
64   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "PEDESTALDATA", "LDC0", "ZDCPedestal.dat");
65   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "PEDHISTOS",    "LDC0", "ZDCPedHisto.root");
66   //
67   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "LASERDATA",   "LDC0", "ZDCLaserCalib.dat");
68   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "LASERHISTOS", "LDC0", "ZDCLasHisto.root");
69   //
70   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "ENERGYCALIB", "LDC0", "ZDCEnergyCalib.dat");
71   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "TOWERCALIB", "LDC0", "ZDCTowerCalib.dat");
72   //
73   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "PHYSICS", "LDC0", "ZDCChMapping.dat");
74   //
75   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "BC", "LDC0", "ZDCChMapping.dat");
76
77   // TODO(3)
78   //
79   // The shuttle can read run type stored in the DAQ logbook.
80   // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
81   // using GetRunType function.
82   if(obj==1)      shuttle->SetInputRunType("STANDALONE_PEDESTAL");
83   else if(obj==2) shuttle->SetInputRunType("STANDALONE_LASER");
84   else if(obj==3) shuttle->SetInputRunType("CALIBRATION_EMD");
85   else if(obj==4) shuttle->SetInputRunType("STANDALONE_COSMIC");
86   else if(obj==5) shuttle->SetInputRunType("CALIBRATION_BC");
87   else if(obj==6) shuttle->SetInputRunType("PHYSICS");
88
89   // TODO(4)
90   //
91   // The shuttle can read run parameters stored in the DAQ run logbook.
92   // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
93   // using GetRunParameter function.
94   // In real life the parameters will be retrieved automatically from the run logbook;
95   //shuttle->AddInputRunParameter("beamType", "Pb-Pb");
96   shuttle->AddInputRunParameter("beamType", "p-p");
97   shuttle->AddInputRunParameter("totalEvents", "1000");
98   shuttle->AddInputRunParameter("NumberOfGDCs", "1");
99
100   // TODO(5) NEW!
101   //
102   // This is for preprocessor that require data from HLT.
103   // Since HLT may be switched off, the preprocessor should first query the Run logbook where
104   // the HLT status is stored. SHUTTLE implements a shortcut function (GetHLTStatus) that returns
105   // a bool directly. 1 = HLT ON, 0 = HLT OFF
106   //
107   Bool_t hltStatus=kFALSE;
108   shuttle->SetInputHLTStatus(hltStatus);
109
110   // TODO(6)
111   //
112   // The shuttle can query condition parameters valid from the current run from the OCDB
113   // To test it, we must first store the object into the OCDB. It will be retrieved in the preprocessor
114   // using GetFromOCDB function.
115
116   /*TObjString obj("This is a condition parameter stored in OCDB");
117   AliCDBId id("ZDC/Calib/Data", 0, AliCDBRunRange::Infinity());
118   AliCDBMetaData md;
119   AliCDBEntry entry(&obj, id, &md);
120
121   shuttle->AddInputCDBEntry(&entry);
122   */
123   
124   // TODO(6)
125   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
126   AliPreprocessor* test = new AliZDCPreprocessor(shuttle);
127
128   // Test the preprocessor
129   shuttle->Process();
130
131   // TODO(7)
132   // In the preprocessor AliShuttleInterface::Store should be called to put the final
133   // data to the CDB. To check if all went fine have a look at the files produced in
134   // $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/SHUTTLE/Data
135   //
136   // Check the file which should have been created
137   AliCDBEntry* chkEntry0 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
138                         ->Get("ZDC/Calib/ChMap", 0);
139   AliCDBEntry* chkEntry1;
140   if(obj==1) chkEntry1 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
141                         ->Get("ZDC/Calib/Pedestals", 0);
142   else if(obj==2) chkEntry1 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
143                         ->Get("ZDC/Calib/LaserCalib", 0);
144   else if(obj==3) chkEntry1 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
145                         ->Get("ZDC/Calib/EnergyCalib", 0);
146   
147   
148   if(!chkEntry0){
149     printf("No file in ZDC/Calib/ChMap\n");
150     return;
151   }
152   if(!chkEntry1){
153     if(obj==1) printf("No file in ZDC/Calib/Pedestal\n");
154     else if(obj==2) printf("No file in ZDC/Calib/LaserCalib\n");
155     else if(obj==3) printf("No file in ZDC/Calib/EnergyCalib\n");
156     return;
157   }
158   
159
160   /*AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (chkEntry1->GetObject());
161   // If everything went fine, draw the result
162   if (output)
163     output->Draw();*/
164 }
165
166 TMap* CreateDCSAliasMap()
167 {
168   // Creates a DCS structure
169   // The structure is the following:
170   //   TMap (key --> value)
171   //     <DCSAlias> --> <valueList>
172   //     <DCSAlias> is a string
173   //     <valueList> is a TObjArray of AliDCSValue
174   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
175
176   // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
177   // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
178
179   TMap* aliasMap = new TMap;
180   aliasMap->SetOwner(1);
181
182   TRandom random;
183   TString aliasNames[28];
184
185   // ******************************** alignment values
186   aliasNames[0] = "ZDC_ZNA_POS.actual.position";
187   aliasNames[1] = "ZDC_ZPA_POS.actual.position";
188   aliasNames[2] = "ZDC_ZNC_POS.actual.position";
189   aliasNames[3] = "ZDC_ZPC_POS.actual.position";
190   //
191   for(int nAlias=0; nAlias<4; nAlias++)
192   {
193     TObjArray* valueSet = new TObjArray;
194     valueSet->SetOwner(1);
195
196     TString aliasName = aliasNames[nAlias];
197     //printf("\n\n alias: %s\n\n",aliasName.Data());
198
199     Float_t simVal = (Float_t) (random.Rndm()*0.025+random.Rndm()*0.1);
200     for(int i=0;i<3;i++)
201     {
202       int timeStamp1[3] = {0,500,1000};
203       AliDCSValue* dcsVal = new AliDCSValue(simVal, timeStamp1[i]);
204       //printf("%s\n",dcsVal->ToString());
205       valueSet->Add(dcsVal);
206     }
207     aliasMap->Add(new TObjString(aliasName), valueSet);
208   }
209   // ******************************** HV values
210   aliasNames[4]  = "ZDC_ZNA_HV0.actual.vMon";
211   aliasNames[5]  = "ZDC_ZNA_HV1.actual.vMon";
212   aliasNames[6]  = "ZDC_ZNA_HV2.actual.vMon";
213   aliasNames[7]  = "ZDC_ZNA_HV3.actual.vMon";
214   aliasNames[8]  = "ZDC_ZNA_HV4.actual.vMon";
215   //
216   aliasNames[9]   = "ZDC_ZPA_HV0.actual.vMon";
217   aliasNames[10]  = "ZDC_ZPA_HV1.actual.vMon";
218   aliasNames[11]  = "ZDC_ZPA_HV2.actual.vMon";
219   aliasNames[12]  = "ZDC_ZPA_HV3.actual.vMon";
220   aliasNames[13]  = "ZDC_ZPA_HV4.actual.vMon";
221   //
222   aliasNames[14]  = "ZDC_ZNC_HV0.actual.vMon";
223   aliasNames[15]  = "ZDC_ZNC_HV1.actual.vMon";
224   aliasNames[16]  = "ZDC_ZNC_HV2.actual.vMon";
225   aliasNames[17]  = "ZDC_ZNC_HV3.actual.vMon";
226   aliasNames[18]  = "ZDC_ZNC_HV4.actual.vMon";
227   //
228   aliasNames[19]  = "ZDC_ZPC_HV0.actual.vMon";
229   aliasNames[20]  = "ZDC_ZPC_HV1.actual.vMon";
230   aliasNames[21]  = "ZDC_ZPC_HV2.actual.vMon";
231   aliasNames[22]  = "ZDC_ZPC_HV3.actual.vMon";
232   aliasNames[23]  = "ZDC_ZPC_HV4.actual.vMon";
233   //
234   aliasNames[24]  = "ZDC_ZEM_HV0.actual.vMon";
235   aliasNames[25]  = "ZDC_ZEM_HV1.actual.vMon";
236   //
237   aliasNames[26]  = "ZDC_REFA_HV.actual.vMon";
238   aliasNames[27]  = "ZDC_REFC_HV.actual.vMon";
239   //
240   for(int nAlias=4;nAlias<28;nAlias++)
241   {
242     TObjArray* valueSet = new TObjArray;
243     valueSet->SetOwner(1);
244    
245     TString aliasName = aliasNames[nAlias];
246     //printf("\n\n alias: %s\n\n",aliasName.Data());
247
248     for(int timeStamp=0;timeStamp<=1000;timeStamp+=500)
249     {
250       Float_t simVal = (Float_t) (random.Gaus()*600.+1800.);
251       AliDCSValue* dcsVal = new AliDCSValue(simVal, timeStamp);
252       //printf("%s\n",dcsVal->ToString());
253       valueSet->Add(dcsVal);
254     }
255     aliasMap->Add(new TObjString(aliasName), valueSet);
256   }
257
258   return aliasMap;
259 }
260
261 TMap* ReadDCSAliasMap()
262 {
263   // Open a file that contains DCS input data
264   // The CDB framework is used to open the file, this means the file is located
265   // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
266   // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
267   // An explanation of the structure can be found in CreateDCSAliasMap()
268
269   AliCDBEntry *entry = AliCDBManager::Instance()->Get("ZDC/DCS/Data", 0);
270   return dynamic_cast<TMap*> (entry->GetObject());
271 }
272
273 void WriteDCSAliasMap()
274 {
275   // This writes the output from CreateDCSAliasMap to a CDB file
276
277   TMap* dcsAliasMap = CreateDCSAliasMap();
278
279   AliCDBMetaData metaData;
280         metaData.SetBeamPeriod(0);
281         metaData.SetResponsible("Chiara Oppedisano");
282         metaData.SetComment("Test object for TestZDCPreprocessor.C");
283
284   AliCDBId id("ZDC/DCS/Data", 0, 0);
285
286   // initialize location of CDB
287   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
288
289   AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
290 }