Fixing small memory leaks (Hans)
[u/mrichter/AliRoot.git] / TOF / TOFPreprocessor.C
CommitLineData
ccc28861 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
27a53fea 13extern TBenchmark *gBenchmark;
7fffa85b 14void TOFPreprocessor(Char_t * RunType="PHYSICS")
ccc28861 15{
b0635849 16 gSystem->Load("$ALICE_ROOT/SHUTTLE/TestShuttle/libTestShuttle");
ccc28861 17
17149e6b 18 AliLog::SetClassDebugLevel("AliTOFPreprocessor",2);
ccc28861 19 // initialize location of CDB
162637e4 20 AliTestShuttle::SetMainCDB("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
21 AliTestShuttle::SetMainRefStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestReference");
58f7f59a 22
ccc28861 23 // create AliTestShuttle instance
104ba366 24 Int_t nrun = 104892;
ff326f84 25 AliTestShuttle* shuttle = new AliTestShuttle(nrun, 30, 980);
7fffa85b 26 //setting run type to physiscs
27 shuttle->SetInputRunType(RunType);
ff326f84 28 shuttle->SetTimeCreated(20);
29 shuttle->SetDCSQueryOffset(20);
ccc28861 30
31 // Generation of "fake" input DCS data
27a53fea 32 TMap* dcsAliasMap = CreateDCSAliasMap();
ccc28861 33
34 // now give the alias map to the shuttle
27a53fea 35 shuttle->SetDCSInput(dcsAliasMap);
ccc28861 36
37 // processing files. for the time being, the files are local.
104ba366 38 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "HITS", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Hits.root");
f04b3a69 39 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "CALIB", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Calib.root");
5b4ed716 40 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "READOUT", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Readout.root");
5abdf772 41 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "DELAYS", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Total.root");
42 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "RUNLevel", "MON", "$ALICE_ROOT/TOF/ShuttleInput/Partial.root");
1f4ce44e 43 shuttle->AddInputFile(AliTestShuttle::kDCS, "TOF", "TofFeeLightMap", "", "$ALICE_ROOT/TOF/ShuttleInput/TOFFEElight.20101028.133932.8000");
69355034 44 shuttle->AddInputFile(AliTestShuttle::kDCS, "TOF", "TofFeeMap", "", "$ALICE_ROOT/TOF/ShuttleInput/TOFFEE.20091217.194708.105517");
013ac2dd 45
46 TString filename;
47 TString LDCname;
48 //char filename[100];
49 //char LDCname[5];
7fffa85b 50
4541173c 51 for (Int_t iLDC=0;iLDC<2;iLDC++){
013ac2dd 52 filename.Form("$ALICE_ROOT/TOF/ShuttleInput/TOFoutPulserLDC_%02i.root",iLDC*2);
53 LDCname.Form("LDC%i",iLDC*2);
4541173c 54 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "PULSER", LDCname, filename);
013ac2dd 55 filename.Form("$ALICE_ROOT/TOF/ShuttleInput/TOFoutNoiseLDC_%02i.root",iLDC*2);
56 LDCname.Form("LDC%i",iLDC*2);
4541173c 57 shuttle->AddInputFile(AliTestShuttle::kDAQ, "TOF", "NOISE", LDCname, filename);
58 }
013ac2dd 59
ccc28861 60
61 // instantiation of the preprocessor
124a2863 62 AliPreprocessor* pp = new AliTOFPreprocessor(shuttle);
ccc28861 63
64 // preprocessing
27a53fea 65 gBenchmark->Start("process");
ccc28861 66 shuttle->Process();
27a53fea 67 gBenchmark->Stop("process");
68 gBenchmark->Print("process");
ccc28861 69
ccc28861 70
71}
72
104ba366 73
ccc28861 74TMap* CreateDCSAliasMap()
75{
76 // Creates a DCS structure
77 // The structure is the following:
27a53fea 78 // TMap (key --> value)
79 // <DCSAlias> --> <valueList>
80 // <DCSAlias> is a string
81 // <valueList> is a TObjArray of AliDCSValue
82 // An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
ccc28861 83
27a53fea 84 // In this example 6 aliases exists: DCSAlias1 ... DCSAlias6
85 // Each contains 1000 values randomly generated by TRandom::Gaus + 5*nAlias
ccc28861 86
87 TMap* aliasMap = new TMap;
88 aliasMap->SetOwner(1);
89
90 TRandom random;
104ba366 91 /*
ccc28861 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);
104ba366 98 */
ccc28861 99
27a53fea 100
d202b31a 101 Float_t tentHVv=6500, tentHVi=80;
102 Float_t sigmaHVv=10, sigmaHVi=10;
ccc28861 103
104ba366 104 Float_t tent=0, sigma=0;//, thr=0;
d202b31a 105 // to have all the aliases, decomment the following line:
106 Int_t NAliases=360, NHV=90;
7fffa85b 107
104ba366 108
7fffa85b 109 // if not all the aliases are there, use this:
d202b31a 110 //Int_t NAliases=120, NHV=90;
ccc28861 111
104ba366 112 TString sindex;
113 TString aliasName;
114
ccc28861 115 for(int nAlias=0;nAlias<NAliases;nAlias++) {
116
117 TObjArray* valueSet = new TObjArray;
118 valueSet->SetOwner(1);
119
ccc28861 120 if (nAlias<NHV){
124a2863 121 aliasName = "tof_hv_vp_";
122 sindex.Form("%02i",nAlias);
123 aliasName += sindex;
124 //aliasName += nAlias;
ccc28861 125 tent=tentHVv;
126 sigma=sigmaHVv;
127 // thr=thrHVv;
128 }
129 else if (nAlias<NHV*2){
124a2863 130 // aliasName = "HVvneg";
131 //aliasName += nAlias-NHV;
132 aliasName = "tof_hv_vn_";
133 sindex.Form("%02i",nAlias-NHV);
134 aliasName += sindex;
ccc28861 135 tent=-tentHVv;
136 sigma=-sigmaHVv;
137 //thr=-thrHVv;
138 }
139 else if (nAlias<NHV*3){
124a2863 140 // aliasName = "HVcpos";
141 //aliasName += nAlias-2*NHV;
142 aliasName = "tof_hv_ip_";
143 sindex.Form("%02i",nAlias-2*NHV);
144 aliasName += sindex;
145 tent=tentHVi;
146 sigma=sigmaHVi;
ccc28861 147 //thr=thrHVc;
148 }
149 else if (nAlias<NHV*4){
124a2863 150 // aliasName = "HVcneg";
151 //aliasName += nAlias-3*NHV;
152 aliasName = "tof_hv_in_";
153 sindex.Form("%02i",nAlias-3*NHV);
154 aliasName += sindex;
155 tent=-tentHVi;
156 sigma=-sigmaHVi;
ccc28861 157 //thr=-thrHVc;
158 }
ccc28861 159 // gauss generation of values
104ba366 160 for (int timeStamp=0;timeStamp<6000;timeStamp+=10){
db83b789 161 //for (int timeStamp=0;timeStamp<1;timeStamp++){
ccc28861 162 Float_t gaussvalue = (Float_t) (random.Gaus(tent,sigma));
163 if (TMath::Abs(gaussvalue-tent)>sigma){
164 AliDCSValue* dcsVal = new AliDCSValue(gaussvalue, timeStamp);
165 valueSet->Add(dcsVal);
166 }
167 }
168
169 aliasMap->Add(new TObjString(aliasName), valueSet);
104ba366 170
171 }
172
173
174
175
176 const Int_t kNsectors = 18;
177 const Int_t kNplates = 5;
178
179 UInt_t baseWord = 0;
180 UInt_t oldBaseWord = 0;
181
182 for(int i=0;i<kNsectors;i++)
183 for(int j=0;j<kNplates;j++) {
184
185 TObjArray* valueSetHV = new TObjArray;
186 valueSetHV->SetOwner(1);
187
188 aliasName = "TOF_HVSTATUS_";
189 sindex.Form("SM%02dMOD%1d",i,j);
190 aliasName += sindex;
191
192
193 //for (int timeStamp=0;timeStamp<6000;timeStamp+=600) {
194 for (int timeStamp=0;timeStamp<1201;timeStamp+=600) {
195 if (timeStamp==0 /*|| timeStamp==1200*/) {
196 baseWord = CreateHVword(i,j, kTRUE);
197 oldBaseWord = baseWord;
198 AliDCSValue* dcsVal = new AliDCSValue(baseWord, timeStamp);
199 valueSetHV->Add(dcsVal);
200 }
201 else {
202 if (random.Uniform(0.,1.)>=0.5) {
203 baseWord = CreateHVword(i,j, kFALSE);
204 if (baseWord<=oldBaseWord) {
205 oldBaseWord = baseWord;
206 AliDCSValue* dcsVal = new AliDCSValue(baseWord, timeStamp);
207 valueSetHV->Add(dcsVal);
208 }
209 else {
210 AliDCSValue* dcsVal = new AliDCSValue(oldBaseWord, timeStamp);
211 valueSetHV->Add(dcsVal);
212 }
213 //Info(Form(" %2d %1d %s %d %d",i,j,aliasName,timeStamp,baseWord));
214 }
215 }
216 }
217
218 /*
219 baseWord = CreateHVword(i,j, kTRUE);
220 AliDCSValue* dcsVal0 = new AliDCSValue(baseWord, 0);
221 valueSetHV->Add(dcsVal0);
222
223 if ((i==0 && j==2) || (i==9 && j==4)) {
224 baseWord = CreateHVword(i,j, kFALSE);
225 AliDCSValue* dcsVal1 = new AliDCSValue(baseWord, 600);
226 valueSetHV->Add(dcsVal1);
227 }
228
229 baseWord = CreateHVword(i,j, kTRUE);
230 AliDCSValue* dcsVal2 = new AliDCSValue(baseWord, 1200);
231 valueSetHV->Add(dcsVal2);
232 */
233
234 aliasMap->Add(new TObjString(aliasName), valueSetHV);
235
236 }
237
238
239 const Int_t kNddl = 72;
240 baseWord = 0;
241 oldBaseWord = 0;
242
243 for(int i=0;i<kNddl;i++) {
244
245 TObjArray* valueSetLV = new TObjArray;
246 valueSetLV->SetOwner(1);
247
248 aliasName = "TOF_FEACSTATUS_";
249 sindex.Form("%02d",i);
250 aliasName += sindex;
251
252
253 //for (int timeStamp=0;timeStamp<6000;timeStamp+=600) {
254 for (int timeStamp=0;timeStamp<1201;timeStamp+=400) {
255 if (timeStamp==0 /*|| timeStamp==1200*/) {
256 baseWord = CreateLVword(kTRUE);
257 AliDCSValue* dcsVal = new AliDCSValue(baseWord, timeStamp);
258 valueSetLV->Add(dcsVal);
259 oldBaseWord = baseWord;
260 //Info(Form(" %2d %s %d %d",i,aliasName,timeStamp,baseWord));
261 }
262 else {
263 if (random.Uniform(0.,1.)>=0.5) {
264 baseWord = CreateLVword(kFALSE);
265 if (baseWord<=oldBaseWord) {
266 oldBaseWord = baseWord;
267 AliDCSValue* dcsVal = new AliDCSValue(baseWord, timeStamp);
268 valueSetLV->Add(dcsVal);
269 }
270 else {
271 AliDCSValue* dcsVal = new AliDCSValue(oldBaseWord, timeStamp);
272 valueSetLV->Add(dcsVal);
273 }
274 //Info(Form(" %2d %1d %s %d %d",i,j,aliasName,timeStamp,baseWord));
275 }
276 }
277 }
278
279 /*
280 baseWord = CreateLVword(kTRUE);
281 AliDCSValue* dcsVal0 = new AliDCSValue(baseWord, 0);
282 valueSetLV->Add(dcsVal0);
283
284 if (i==7 || i==9) {
285 baseWord = CreateLVword(kFALSE);
286 AliDCSValue* dcsVal1 = new AliDCSValue(baseWord, 400);
287 valueSetLV->Add(dcsVal1);
288 }
289 else if (i==50 || i==35) {
290 baseWord = CreateLVword(kFALSE);
291 AliDCSValue* dcsVal2 = new AliDCSValue(baseWord, 800);
292 valueSetLV->Add(dcsVal2);
293 }
294
295 baseWord = CreateLVword(kTRUE);
296 AliDCSValue* dcsVal3 = new AliDCSValue(baseWord, 1200);
297 valueSetLV->Add(dcsVal3);
298 */
299
300 aliasMap->Add(new TObjString(aliasName), valueSetLV);
301
ccc28861 302 }
303
104ba366 304
ccc28861 305 return aliasMap;
306}
307
104ba366 308
309UInt_t CreateHVword(Int_t nSector, Int_t nPlate, Bool_t isAtBorder) {
310 //
311 //
312 //
313
314 UInt_t baseWord = 0;
315 UInt_t word = 0;
316 TRandom random;
317
318 for (Int_t iStrip=0; iStrip<AliTOFGeometry::NStrip(nPlate); iStrip++) {
319
320 if (isAtBorder) {
321 word = 1;
322 if (nPlate==2 && nSector>=13 && nSector<=15)
323 word = 0;
324 }
325 else {
326 random.Uniform(0.,1.)<0.5 ? word = 0 : word = 1;
327 if (nPlate==2 && nSector>=13 && nSector<=15)
328 word = 0;
329 word = 0;
330 }
331
332 AliBitPacking::PackWord(word,baseWord,iStrip,iStrip);
333 }
334
335 return baseWord;
336
337}
338
339
340UInt_t CreateLVword(Bool_t isAtBorder) {
341 //
342 //
343 //
344
345 UInt_t baseWord = 0;
346 UInt_t word = 0;
347 TRandom random;
348
349 for (Int_t iFeac=0; iFeac<8; iFeac++) {
350
351 if (isAtBorder)
352 word = 1;
353 else {
354 random.Uniform(0.,1.)<0.5 ? word = 0 : word = 1;
355 word = 0;
356 }
357
358 AliBitPacking::PackWord(word,baseWord,iFeac,iFeac);
359 }
360
361 return baseWord;
362
363}
364
365
ccc28861 366TMap* ReadDCSAliasMap()
367{
368 // Open a file that contains DCS input data
369 // The CDB framework is used to open the file, this means the file is located
370 // in $ALICE_ROOT/SHUTTLE/TestShuttle/TestCDB/<detector>/DCS/Data
371 // The file contains an AliCDBEntry that contains a TMap with the DCS structure.
372 // An explanation of the structure can be found in CreateDCSAliasMap()
373
374 AliCDBEntry *entry = AliCDBManager::Instance()->Get("TOF/DCS/Data", 0);
375 return dynamic_cast<TMap*> (entry->GetObject());
376}
377
378void WriteDCSAliasMap()
379{
380 // This writes the output from CreateDCSAliasMap to a CDB file
381
382 TMap* dcsAliasMap = CreateDCSAliasMap();
383
384 AliCDBMetaData metaData;
385 metaData.SetBeamPeriod(0);
386 metaData.SetResponsible("Chiara");
387 metaData.SetComment("Test object for TOFPreprocessor.C");
388
389 AliCDBId id("TOF/DCS/Data", 0, 0);
390
391 // initialize location of CDB
162637e4 392 AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB/SHUTTLE/TestShuttle/TestCDB");
ccc28861 393
394 AliCDBManager::Instance()->Put(dcsAliasMap, id, &metaData);
395}
104ba366 396
397