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