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