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