]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ZDC/TestZDCPreprocessor.C
Update to write mapping only for the ZDC
[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(const char* runType="PHYSICS")
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/SHUTTLE/TestShuttle/TestCDB");
23   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB");
24   //AliTestShuttle::SetMainCDB("alien://folder=/alice/data/2009/OCDB/");
25   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
26
27   printf("\n Test OCDB storage Uri: %s\n", AliShuttleInterface::GetMainCDB().Data());
28   printf(" Test Reference storage Uri: %s\n\n", AliShuttleInterface::GetMainRefStorage().Data());
29
30   // TODO(1)
31   //
32   // The shuttle can read DCS data, if the preprocessor should be tested to process DCS data,
33   // some fake data has to be created.
34   //
35   // The "fake" input data can be taken using either (a) or (b):
36   // (a) data from a file: Use ReadDCSAliasMap()
37   //     the format of the file is explained in ReadDCSAliasMap()
38   //     To use it uncomment the following line:
39   //
40   //TMap* dcsAliasMap = ReadDCSAliasMap();
41   //
42   // (b) generated in this macro: Use CreateDCSAliasMap() and its documentation
43   //     To use it uncomment the following line:
44   //
45   TMap* dcsAliasMap = CreateDCSAliasMap();
46   dcsAliasMap->Print("");
47   //WriteDCSAliasMap();
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(AliTestShuttle::kDAQ, "ZDC", "PEDESTALDATA", "LDC", "ZDCPedestal.dat");
68   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "PEDESTALHISTOS", "LDC", "ZDCPedHisto.root");
69   //
70   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "LASERDATA", "LDC", "ZDCLaserCalib.dat");
71   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "LASERHISTOS", "LDC", "ZDCLaserHisto.root");
72   //
73   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "EMDENERGYCALIB", "LDC", "ZDCEnergyCalib.dat");
74   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "EMDTOWERCALIB", "LDC", "ZDCTowerCalib.dat");
75   //
76   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "MBCALIB", "LDC", "ZDCMBCalib.root");
77   //
78   shuttle->AddInputFile(AliTestShuttle::kDAQ, "ZDC", "MAPPING", "MON", "ZDCChMapping.dat");
79
80   // TODO(3)
81   //
82   // The shuttle can read run type stored in the DAQ logbook.
83   // To test it, we must provide the run type manually. They will be retrieved in the preprocessor
84   // using GetRunType function.
85   shuttle->SetInputRunType(runType);
86   
87   // TODO(4)
88   //
89   // The shuttle can read run parameters stored in the DAQ run logbook.
90   // To test it, we must provide the run parameters manually. They will be retrieved in the preprocessor
91   // using GetRunParameter function.
92   // In real life the parameters will be retrieved automatically from the run logbook;
93   //shuttle->AddInputRunParameter("beamType", "A-A");
94   shuttle->AddInputRunParameter("beamType", "p-p");
95   shuttle->AddInputRunParameter("totalEvents", "1000");
96   shuttle->AddInputRunParameter("NumberOfGDCs", "1");
97
98   // TODO(5) NEW!
99   //
100   // This is for preprocessor that require data from HLT.
101   // Since HLT may be switched off, the preprocessor should first query the Run logbook where
102   // the HLT status is stored. SHUTTLE implements a shortcut function (GetHLTStatus) that returns
103   // a bool directly. 1 = HLT ON, 0 = HLT OFF
104   //
105   Bool_t hltStatus=kFALSE;
106   shuttle->SetInputHLTStatus(hltStatus);
107
108   // TODO(6)
109   //
110   // The shuttle can query condition parameters valid from the current run from the OCDB
111   // To test it, we must first store the object into the OCDB. It will be retrieved in the preprocessor
112   // using GetFromOCDB function.
113
114   /*TObjString obj("This is a condition parameter stored in OCDB");
115   AliCDBId id("ZDC/Calib/Data", 0, AliCDBRunRange::Infinity());
116   AliCDBMetaData md;
117   AliCDBEntry entry(&obj, id, &md);
118
119   shuttle->AddInputCDBEntry(&entry);
120   */
121   
122   // TODO(6)
123   // Create the preprocessor that should be tested, it registers itself automatically to the shuttle
124   AliPreprocessor* test = new AliZDCPreprocessor(shuttle);
125   shuttle->Print();
126   
127   // Test the preprocessor
128   shuttle->Process();
129   //printf(" Back to test macro: final checks! \n");
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   TString str(runType);
140   AliCDBEntry* chkEntry1;
141   if((str.CompareTo("STANDALONE_PEDESTAL")) == 0) chkEntry1 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
142                         ->Get("ZDC/Calib/Pedestals", 0);
143   else if((str.CompareTo("STANDALONE_LASER")) == 0) chkEntry1 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
144                         ->Get("ZDC/Calib/LaserCalib", 0);
145   else if((str.CompareTo("CALIBRATION_EMD")) == 0) chkEntry1 = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
146                         ->Get("ZDC/Calib/EnergyCalib", 0);
147   
148   
149   if(!chkEntry0){
150     printf("No file in ZDC/Calib/ChMap\n");
151     return;
152   }
153   if(!chkEntry1){
154     if((str.CompareTo("STANDALONE_PEDESTAL")) == 0)  printf("No file in ZDC/Calib/Pedestal\n");
155     else if((str.CompareTo("STANDALONE_LASER")) == 0) printf("No file in ZDC/Calib/LaserCalib\n");
156     else if((str.CompareTo("CALIBRATION_EMD")) == 0)  printf("No file in ZDC/Calib/EnergyCalib\n");
157     return;
158   }
159   
160
161   /*AliTestDataDCS* output = dynamic_cast<AliTestDataDCS*> (chkEntry1->GetObject());
162   // If everything went fine, draw the result
163   if (output)
164     output->Draw();*/
165 }
166
167 TMap* CreateDCSAliasMap()
168 {
169   // Creates a DCS structure
170   // The structure is the following:
171   //   TMap (key --> value)
172   //     <DCSAlias> --> <valueList>
173   //     <DCSAlias> is a string
174   //     <valueList> is a TObjArray of AliDCSValue
175   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
176
177   // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
178   // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
179
180   TMap* aliasMap = new TMap;
181   aliasMap->SetOwner(1);
182
183   TRandom random;
184   TString aliasNames[28];
185
186   // ******************************** alignment values
187   aliasNames[0] = "ZDC_ZNA_POS.actual.position";
188   aliasNames[1] = "ZDC_ZPA_POS.actual.position";
189   aliasNames[2] = "ZDC_ZNC_POS.actual.position";
190   aliasNames[3] = "ZDC_ZPC_POS.actual.position";
191   //
192   for(int nAlias=0; nAlias<4; nAlias++){
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     int timeStamp1[5] = {0,500,1000,1500,2000};
201     for(int i=0;i<5;i++){
202       AliDCSValue* dcsVal = new AliDCSValue(simVal, timeStamp1[i]);
203       //printf("%s\n",dcsVal->ToString());
204       valueSet->Add(dcsVal);
205     }
206     aliasMap->Add(new TObjString(aliasName), valueSet);
207   }
208   // ******************************** HV values
209   aliasNames[4]  = "ZDC_ZNA_HV0.actual.vMon";
210   aliasNames[5]  = "ZDC_ZNA_HV1.actual.vMon";
211   aliasNames[6]  = "ZDC_ZNA_HV2.actual.vMon";
212   aliasNames[7]  = "ZDC_ZNA_HV3.actual.vMon";
213   aliasNames[8]  = "ZDC_ZNA_HV4.actual.vMon";
214   //
215   aliasNames[9]   = "ZDC_ZPA_HV0.actual.vMon";
216   aliasNames[10]  = "ZDC_ZPA_HV1.actual.vMon";
217   aliasNames[11]  = "ZDC_ZPA_HV2.actual.vMon";
218   aliasNames[12]  = "ZDC_ZPA_HV3.actual.vMon";
219   aliasNames[13]  = "ZDC_ZPA_HV4.actual.vMon";
220   //
221   aliasNames[14]  = "ZDC_ZNC_HV0.actual.vMon";
222   aliasNames[15]  = "ZDC_ZNC_HV1.actual.vMon";
223   aliasNames[16]  = "ZDC_ZNC_HV2.actual.vMon";
224   aliasNames[17]  = "ZDC_ZNC_HV3.actual.vMon";
225   aliasNames[18]  = "ZDC_ZNC_HV4.actual.vMon";
226   //
227   aliasNames[19]  = "ZDC_ZPC_HV0.actual.vMon";
228   aliasNames[20]  = "ZDC_ZPC_HV1.actual.vMon";
229   aliasNames[21]  = "ZDC_ZPC_HV2.actual.vMon";
230   aliasNames[22]  = "ZDC_ZPC_HV3.actual.vMon";
231   aliasNames[23]  = "ZDC_ZPC_HV4.actual.vMon";
232   //
233   aliasNames[24]  = "ZDC_ZEM_HV0.actual.vMon";
234   aliasNames[25]  = "ZDC_ZEM_HV1.actual.vMon";
235   //
236   aliasNames[26]  = "ZDC_REFA_HV.actual.vMon";
237   aliasNames[27]  = "ZDC_REFC_HV.actual.vMon";
238   //
239   for(int nAlias=4;nAlias<28;nAlias++){
240 //   if(nAlias<14 || nAlias>18){
241      TObjArray* valueSet = new TObjArray;
242      valueSet->SetOwner(1);
243    
244      TString aliasName = aliasNames[nAlias];
245      //printf("\n\n alias: %s\n\n",aliasName.Data());
246
247      for(int timeStamp=0;timeStamp<=2000;timeStamp+=500){
248        Float_t simVal = (Float_t) (random.Gaus()*600.+1800.);
249        AliDCSValue* dcsVal = new AliDCSValue(simVal, timeStamp);
250        //printf("%s\n",dcsVal->ToString());
251        valueSet->Add(dcsVal);
252      }
253      aliasMap->Add(new TObjString(aliasName), valueSet);
254 //   }
255   }
256
257   return aliasMap;
258 }
259
260 TMap* ReadDCSAliasMap()
261 {
262   // Open a file that contains DCS input data
263   // The CDB framework is used to open the file, this means the file is located
264   // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
265   // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
266   // An explanation of the structure can be found in CreateDCSAliasMap()
267
268   AliCDBManager *manager = AliCDBManager::Instance();
269   AliCDBStorage *sto = manager->GetStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/");
270   AliCDBId id("ZDC/DCS/Data",0,999999999);
271   AliCDBEntry *entry = sto->Get("ZDC/DCS/Data", 0);
272   if(!entry) printf("TestZDCPreprocessor.C -> ERROR! No entry found as DCS Map! \n");
273   return dynamic_cast<TMap*> (entry->GetObject());
274 }
275
276 void WriteDCSAliasMap()
277 {
278   // This writes the output from CreateDCSAliasMap to a CDB file
279
280   TMap* dcsAliasMap = CreateDCSAliasMap();
281
282   AliCDBMetaData metaData;
283         metaData.SetBeamPeriod(0);
284         metaData.SetResponsible("Chiara Oppedisano");
285         metaData.SetComment("Test object for TestZDCPreprocessor.C");
286
287   AliCDBId id("ZDC/DCS/Data", 0, 999999999);
288
289   // initialize location of CDB
290   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
291
292   AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
293 }