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