]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TOF/TOFPreprocessor.C
changes for proper protection against failed retrieval of CDB Reco object (moved...
[u/mrichter/AliRoot.git] / TOF / TOFPreprocessor.C
1 /* 
2 $Id$ 
3 */
4
5 // This class runs the test TOF preprocessor
6 // It uses AliTestShuttle to simulate a full Shuttle process
7
8 // The input data is created in the functions
9 //   CreateDCSAliasMap() creates input that would in the same way come from DCS
10 //   ReadDCSAliasMap() reads from a file
11 //   CreateInputFilesMap() creates a list of local files, that can be accessed by the shuttle
12
13 extern TBenchmark *gBenchmark;
14 void TOFPreprocessor()
15 {
16   gSystem->Load("$ALICE/SHUTTLE/TestShuttle/libTestShuttle.so");
17
18   // initialize location of CDB
19   AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
20   AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestReference");
21
22   // create AliTestShuttle instance
23   AliTestShuttle* shuttle = new AliTestShuttle(0, 0, 1000);
24
25   // Generation of "fake" input DCS data
26   TMap* dcsAliasMap = CreateDCSAliasMap();  
27
28   // now give the alias map to the shuttle
29   shuttle->SetDCSInput(dcsAliasMap);   
30
31   // processing files. for the time being, the files are local.
32   shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "DELAYS", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Total.root");
33   shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "RUNLevel", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Partial.root");
34
35   // instantiation of the preprocessor
36   AliPreprocessor* pp = new AliTOFPreprocessor(shuttle);
37
38   // preprocessing
39   gBenchmark->Start("process");
40   shuttle->Process();
41   gBenchmark->Stop("process");
42   gBenchmark->Print("process");
43
44   // checking the file which should have been created  
45   AliCDBEntry* chkEntry = AliCDBManager::Instance()->GetStorage(AliShuttleInterface::GetMainCDB())
46                         ->Get("TOF/Calib/OnlineDelay", 0);
47   if (!chkEntry)
48   {
49     printf("The file is not there. Something went wrong.\n");
50     return;
51   }
52
53   AliTOFDataDCS* output = dynamic_cast<AliTOFDataDCS*> (chkEntry->GetObject());
54   // If everything went fine, draw the result
55   if (output)
56     output->Draw();
57   
58 }
59
60 TMap* CreateDCSAliasMap()
61 {
62   // Creates a DCS structure
63   // The structure is the following:
64   //   TMap (key --> value)
65   //     <DCSAlias> --> <valueList>
66   //     <DCSAlias> is a string
67   //     <valueList> is a TObjArray of AliDCSValue
68   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
69
70   // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
71   // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
72
73   TMap* aliasMap = new TMap;
74   aliasMap->SetOwner(1);
75
76   TRandom random;
77   TDatime *datime = new TDatime();
78   Int_t time = datime->GetTime();
79   Int_t date = datime->GetDate();
80   Int_t pid  = gSystem->GetPid();
81   delete datime;
82   Int_t iseed = TMath::Abs(10000 * pid + time - date); 
83
84   //Float_t thrHVv=7.75, thrHVc=3, thrLVv=2.75, thrLVc=2.5,
85   //thrFEEthr=1.5, thrFEEt=10, thrTemp=35, thrPress=1000;
86   //Float_t tentHVv=6.75, tentHVc=2, tentLVv=1.75, tentLVc=1.5,
87   //  tentFEEthr=0.5, te    result=0;
88   //ntFEEt=20, tentTemp=25, tentPress=900;
89   //Float_t sigmaHVv=1, sigmaHVc=0.25, sigmaLVv=0.25, sigmaLVc=0.25,
90   //  sigmaFEEthr=0.05, sigmaFEEt=5, sigmaTemp=1, sigmaPress=10;
91
92   Float_t tentHVv=6500, tentHVi=80, tentLVv=2.7, tentLVi=4.5,
93     tentLVv33=3.3, tentLVv50=5.0, tentLVv48=48,
94     tentLVi33=100, tentLVi50=3.0, tentLVi48=10,
95     tentFEEthr=1.0, tentFEEtfeac=25, tentFEEttrm=45, 
96     tentTemp=25, tentPress=900;
97   Float_t sigmaHVv=10, sigmaHVi=10, sigmaLVv=0.2, sigmaLVi=1.0,
98     sigmaLVv33=0.1, sigmaLVv50=0.1, sigmaLVv48=1,
99     sigmaLVi33=10, sigmaLVi50=0.5, sigmaLVi48=2,
100     sigmaFEEthr=0.1, sigmaFEEtfeac=10, sigmaFEEttrm=4, 
101     sigmaTemp=1, sigmaPress=10;
102
103   Float_t tent=0, sigma=0, thr=0;
104   Int_t NAliases=10514, NHV=90, NLV=576, NLV33=72, NLV50=72, NLV48=72, NFEEthr=1152, NFEEtfeac=576, NFEEttrm=6840, NT=1, NP=1;
105
106   for(int nAlias=0;nAlias<NAliases;nAlias++) {
107
108     TObjArray* valueSet = new TObjArray;
109     valueSet->SetOwner(1);
110
111     TString sindex;
112     TString aliasName;
113     if (nAlias<NHV){
114       aliasName = "tof_hv_vp_";
115       sindex.Form("%02i",nAlias);
116       aliasName += sindex;
117       //aliasName += nAlias;
118       tent=tentHVv;
119       sigma=sigmaHVv;
120       //      thr=thrHVv;
121     }
122     else if (nAlias<NHV*2){
123       //      aliasName = "HVvneg";
124       //aliasName += nAlias-NHV;
125       aliasName = "tof_hv_vn_";
126       sindex.Form("%02i",nAlias-NHV);
127       aliasName += sindex;
128       tent=-tentHVv;
129       sigma=-sigmaHVv;
130       //thr=-thrHVv;
131     }
132     else if (nAlias<NHV*3){
133       //      aliasName = "HVcpos";
134       //aliasName += nAlias-2*NHV;
135       aliasName = "tof_hv_ip_";
136       sindex.Form("%02i",nAlias-2*NHV);
137       aliasName += sindex;
138       tent=tentHVi;
139       sigma=sigmaHVi;
140       //thr=thrHVc;
141     }
142     else if (nAlias<NHV*4){
143       //      aliasName = "HVcneg";
144       //aliasName += nAlias-3*NHV;
145       aliasName = "tof_hv_in_";
146       sindex.Form("%02i",nAlias-3*NHV);
147       aliasName += sindex;
148       tent=-tentHVi;
149       sigma=-sigmaHVi;
150       //thr=-thrHVc;
151     }
152     else if (nAlias<NHV*4+NLV){
153       //      aliasName = "LVv";
154       //aliasName += nAlias-4*NHV;
155       aliasName = "tof_lv_vfea_";
156       sindex.Form("%03i",nAlias-4*NHV);
157       aliasName += sindex;
158       tent=tentLVv;
159       sigma=sigmaLVv;
160       //thr=thrLVv;
161     }
162     else if (nAlias<NHV*4+2*NLV){
163       //      aliasName = "LVc";
164       //aliasName += nAlias-(4*NHV+NLV);
165       aliasName = "tof_lv_ifea_";
166       sindex.Form("%03i",nAlias-(4*NHV+NLV));
167       aliasName += sindex;
168       tent=tentLVi;
169       sigma=sigmaLVi;
170       //thr=thrLVc;
171     }
172     else if (nAlias<NHV*4+2*NLV+NLV33){
173       //      aliasName = "LVc";
174       //aliasName += nAlias-(4*NHV+NLV);
175       aliasName = "tof_lv_v33_";
176       sindex.Form("%02i",nAlias-(4*NHV+2*NLV));
177       aliasName += sindex;
178       tent=tentLVv33;
179       sigma=sigmaLVv33;
180       //thr=thrLVc;
181     }
182     else if (nAlias<NHV*4+2*NLV+2*NLV33){
183       //      aliasName = "LVc";
184       //aliasName += nAlias-(4*NHV+NLV);
185       aliasName = "tof_lv_i33_";
186       sindex.Form("%02i",nAlias-(4*NHV+2*NLV+NLV33));
187       aliasName += sindex;
188       tent=tentLVi33;
189       sigma=sigmaLVi33;
190       //thr=thrLVc;
191     }
192     else if (nAlias<NHV*4+2*NLV+2*NLV33+NLV50){
193       //      aliasName = "LVc";
194       //aliasName += nAlias-(4*NHV+NLV);
195       aliasName = "tof_lv_v50_";
196       sindex.Form("%02i",nAlias-(4*NHV+2*NLV+2*NLV33));
197       aliasName += sindex;
198       tent=tentLVv50;
199       sigma=sigmaLVv50;
200       //thr=thrLVc;
201     }
202     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50){
203       //      aliasName = "LVc";
204       //aliasName += nAlias-(4*NHV+NLV);
205       aliasName = "tof_lv_i50_";
206       sindex.Form("%02i",nAlias-(4*NHV+2*NLV+2*NLV33+NLV50));
207       aliasName += sindex;
208       tent=tentLVi50;
209       sigma=sigmaLVi50;
210       //thr=thrLVc;
211     }
212     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+NLV48){
213       //      aliasName = "LVc";
214       //aliasName += nAlias-(4*NHV+NLV);
215       aliasName = "tof_lv_v48_";
216       sindex.Form("%02i",nAlias-(4*NHV+2*NLV+2*NLV33+2*NLV50));
217       aliasName += sindex;
218       tent=tentLVv48;
219       sigma=sigmaLVv48;
220       //thr=thrLVc;
221     }
222     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+2*NLV48){
223       //      aliasName = "LVc";
224       //aliasName += nAlias-(4*NHV+NLV);
225       aliasName = "tof_lv_i48_";
226       sindex.Form("%02i",nAlias-(4*NHV+2*NLV+2*NLV33+2*NLV50+NLV48));
227       aliasName += sindex;
228       tent=tentLVi48;
229       sigma=sigmaLVi48;
230       //thr=thrLVc;
231     }
232     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr){
233       //      aliasName = "FEEthr";
234       //aliasName += nAlias-(4*NHV+2*NLV-(4*NHV+2*NLV+2*NLV33+2*NLV50+2*NLV48));
235       aliasName = "tof_fee_th_";
236       sindex.Form("%04i",nAlias-(4*NHV+2*NLV+2*NLV33+2*NLV50+2*NLV48));
237       aliasName += sindex;
238       tent=tentFEEthr;
239       sigma=sigmaFEEthr;
240       //thr=thrFEEthr;
241     }
242     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr+NFEEtfeac){
243       //cout << " nalias fee temp = " << nAlias << endl;
244       //      aliasName = "FEEt";
245       //aliasName += nAlias-(4*NHV+2*NLV+NFEEthr);
246       aliasName = "tof_fee_tfeac_";
247       sindex.Form("%03i",nAlias-(4*NHV+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr));
248       aliasName += sindex;
249       //cout << " nalias fee temp name = " << aliasName << endl;
250       tent=tentFEEtfeac;
251       sigma=sigmaFEEtfeac;
252       //thr=thrFEEthr;
253     }
254     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr+NFEEtfeac+NFEEttrm){
255       //cout << " nalias fee temp = " << nAlias << endl;
256       //      aliasName = "FEEt";
257       //aliasName += nAlias-(4*NHV+2*NLV+NFEEthr);
258       aliasName = "tof_fee_ttrm_";
259       sindex.Form("%04i",nAlias-(4*NHV+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr+NFEEtfeac));
260       aliasName += sindex;
261       //cout << " nalias fee temp name = " << aliasName << endl;
262       tent=tentFEEttrm;
263       sigma=sigmaFEEttrm;
264       //thr=thrFEEthr;
265     }
266     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr+NFEEtfeac+NFEEttrm+1){
267       cout << " putting temperature" << endl;
268       aliasName = "temperature";
269       tent=tentTemp;
270       sigma=sigmaTemp;
271       //thr=thrTemp;
272     }
273     else if (nAlias<NHV*4+2*NLV+2*NLV33+2*NLV50+2*NLV48+NFEEthr+NFEEtfeac+NFEEttrm+2){
274       cout << " putting pressure" << endl;
275       aliasName = "pressure";
276       tent=tentPress;
277       sigma=sigmaPress;
278       //thr=thrPress;
279     }
280
281
282     // gauss generation of values 
283     for (int timeStamp=0;timeStamp<1000;timeStamp+=10){
284       Float_t gaussvalue = (Float_t) (random.Gaus(tent,sigma));
285       if (TMath::Abs(gaussvalue-tent)>sigma){
286         AliDCSValue* dcsVal = new AliDCSValue(gaussvalue, timeStamp);
287         valueSet->Add(dcsVal);
288       }
289     }
290
291     aliasMap->Add(new TObjString(aliasName), valueSet);
292   }
293
294   return aliasMap;
295 }
296
297 TMap* ReadDCSAliasMap()
298 {
299   // Open a file that contains DCS input data
300   // The CDB framework is used to open the file, this means the file is located
301   // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
302   // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
303   // An explanation of the structure can be found in CreateDCSAliasMap()
304
305   AliCDBEntry *entry = AliCDBManager::Instance()->Get("TOF/DCS/Data", 0);
306   return dynamic_cast<TMap*> (entry->GetObject());
307 }
308
309 void WriteDCSAliasMap()
310 {
311   // This writes the output from CreateDCSAliasMap to a CDB file
312
313   TMap* dcsAliasMap = CreateDCSAliasMap();
314
315   AliCDBMetaData metaData;
316         metaData.SetBeamPeriod(0);
317         metaData.SetResponsible("Chiara");
318         metaData.SetComment("Test object for TOFPreprocessor.C");
319
320   AliCDBId id("TOF/DCS/Data", 0, 0);
321
322   // initialize location of CDB
323   AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB");
324
325   AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
326 }