]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/CreateSDDDCSMap.C
1994db834cc69096a7f5141862c9cd9b5ec449d2
[u/mrichter/AliRoot.git] / ITS / CreateSDDDCSMap.C
1 #if !defined(__CINT__) || defined(__MAKECINT__)
2 #include <TTimeStamp.h>
3 #include <TMap.h>
4 #include <TMath.h>
5 #include <TFile.h>
6 #include <TObjArray.h>
7 #include <TObjString.h>
8 #include <TRandom.h>
9 #include <TSystem.h>
10 #include <AliDCSValue.h>
11 #endif
12
13
14 //////////////////////////////////////////////////////////////////////////////////////
15 // Generator of testing data for AliITSDCSPreprocessorSDD and  AliITSAnalyzerrSDD   //
16 // Origin: F.Prino, Torino, prino@to.infn.it                                        //
17 //         V.Pospisil, CTU Prague, gdermog@seznam.cz                                //
18 //////////////////////////////////////////////////////////////////////////////////////
19
20
21 TMap* CreateRealisticMap( TTimeStamp startTime, TTimeStamp stopTime );
22 TMap* CreateRandomMap( Int_t maxRecords = 1000, Int_t randomTimeStamps = 0 );
23 void GenerateOutputFiles( TMap *map, char *dir );
24
25
26 void CreateSDDDCSMap( void )
27 {
28
29  TTimeStamp startT( 2008, 2, 7, 15, 0, 0 );
30  TTimeStamp stopT( 2008, 2, 7, 18, 0, 0 );
31                         // The beginning and the end of the simulated run
32
33 //  delete gRandom;
34 //  gRandom = new TRandom2;
35  gRandom->SetSeed(0);
36
37 /* Macro can generate random purely random data or simulate DCS. Choose
38    one of the methods - CreateRandomMap() or CreateRealisticMap() */
39
40 // TMap *outMap = CreateRandomMap( 1000 );
41  TMap *outMap = CreateRealisticMap( startT, stopT );
42
43  GenerateOutputFiles( outMap, "./maps_3h_SIM" );
44
45  TFile newfile( "DCSAliasMap_3h_SIM.root", "RECREATE" );
46
47  printf( "Writting map into the file ...\n");
48
49  outMap->Write( "DCSAliasMap", TObject::kSingleKey );
50
51  printf( "DCSAliasMap created...\n");
52
53 } /*CreateMap*/
54
55
56 /***************************************************************/
57 /*     DCS simulation setup - used in CreateRealisticMap()     */
58 /*   Choose simulation setup by changing following variables   */
59 /***************************************************************/
60
61 // --- Temperature (left side) - behavior of SDD chip -----------
62
63  Float_t mvalTL = 20.0; // Mean value of temperature
64  Float_t fluctTL = 0.5; // Fluctuation (gaussian sigma)
65
66 // --- Temperature readout (left side) - behavior of DCS --------
67
68  Int_t freqROTL = 60;   // Frequency of fixed readout
69  Float_t fluctROTL = 5.0;
70                         // Allowed fluctuation (%)
71
72 // Temperature readout status (left side) - behavior of SDD chip
73
74   Int_t freqROStTL = 60;// Frequency of fixed readout
75   Float_t failureTL = 0.01;
76                         // Probability of thermometer
77                         //  failure (in one hour)
78
79 // --- Temperature (right side) - behavior of SDD chip ----------
80
81  Float_t mvalTR = 20.0; // Mean value of temperature
82  Float_t fluctTR = 0.5;// Fluctuation (gaussian sigma)
83
84 // --- Temperature readout (right side) - behavior of DCS -------
85
86  Int_t freqROTR = 60;   // Frequency of fixed readout
87  Float_t fluctROTR = 5.0;
88                         // Allowed fluctuation (%)
89
90 // Temperature readout status (right side) - behavior of SDD
91
92   Int_t freqROStTR = 60;// Frequency of fixed readout
93   Float_t failureTR = 0.01;
94                         // Probability of thermometer
95                         //  failure (in one hour) 
96
97 // --- High voltage  - behavior of SDD voltage source -----------
98
99  Float_t mvalHV = 1791.0;
100                         // Mean value of HV
101  Float_t fluctHV = 0.5; // Fluctuation (gaussian sigma)
102
103 // --- High voltage readout - behavior of DCS -------------------
104
105  Int_t freqROHV = 60;   // Frequency of fixed readout
106  Float_t fluctROHV = 0.01;
107                         // Allowed fluctuation (%)
108
109 // --- High voltage readout status - behavior of SDD voltage ----
110
111   Int_t freqROOK = 60;  // Frequency of fixed readout
112   Float_t failureHV  = 0.005;
113                         // Probability of HV source
114                         //  failure (in one hour) 
115
116 // --- Medium voltage  - behavior of SDD voltage source --------
117
118  Float_t mvalMV = 45.0; // Mean value of MV
119  Float_t fluctMV = 0.25;// Fluctuation (gaussian sigma)
120
121 // --- Medium voltage readout - behavior of DCS -----------------
122
123  Int_t freqROMV = 60;   // Frequency of fixed readout
124  Float_t fluctROMV = 0.1;
125                         // Allowed fluctuation (%)
126
127 // --- Medium voltage readout status - behavior of SDD voltage --
128
129  Float_t failureMV  = 0.005;
130                         // Probability of MV source
131                         //  failure (in one hour)
132
133 /***************************************************************/
134 /*   ITS geometry setup                                        */
135 /***************************************************************/
136
137  Int_t kNladders3=14;
138  Int_t kNladders4=22;
139  Int_t kNmodLad3=6;
140  Int_t kNmodLad4=8;
141
142 /***************************************************************/
143
144 //----------------------------------------------------------------------------------------
145
146 TMap* CreateRealisticMap( TTimeStamp startTime, TTimeStamp stopTime )
147 {
148   // Creates a DCS structure
149   // The structure is the following:
150   //   TMap (key --> value)
151   //     <DCSAlias> --> <valueList>
152   //     <DCSAlias> is a string
153   //     <valueList> is a TObjArray of AliDCSValue
154   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
155
156   TMap* aliasMap = new TMap;
157   aliasMap->SetOwner(1);
158                         // Empty map is created
159
160   TString aliasName;
161   Char_t dpName[50];
162   Int_t created = 0;
163   Int_t created1 = 0;   // DCS records counter
164
165   Double_t failureTLpersec;
166   Double_t failureTRpersec;
167   Double_t failureHVpersec;
168   Double_t failureMVpersec;
169                         // Probabilities of failure per one second
170   Double_t lambda;
171   lambda = ( TMath::Log( 1.0 - failureTL ) ) / -3600.0;
172   failureTLpersec = 1.0 - TMath::Exp(-lambda );
173   lambda = ( TMath::Log( 1.0 - failureTR ) ) / -3600.0;
174   failureTRpersec = 1.0 - TMath::Exp(-lambda );
175   lambda = ( TMath::Log( 1.0 - failureHV ) ) / -3600.0;
176   failureHVpersec = 1.0 - TMath::Exp(-lambda );
177   lambda = ( TMath::Log( 1.0 - failureMV ) ) / -3600.0;
178   failureMVpersec = 1.0 - TMath::Exp(-lambda );
179                         // Probabilities of failure per one second are counted
180
181   fluctROTL /= 100.0;
182   fluctROTR /= 100.0;
183   fluctROHV /= 100.0;
184   fluctROMV /= 100.0;   // Percents to fractions
185
186   Double_t failureOK = ( failureHV + failureMV ) / 2.0;
187                         // This value is used only for noise in timing
188
189   for( Int_t iLay = 3; iLay < 5; iLay++ )
190   {
191
192       Int_t maxLad = ( iLay == 3) ? kNladders3 : kNladders4;
193       Int_t maxMod = ( iLay == 3) ? kNmodLad3 : kNmodLad4;
194
195       for(Int_t iLad=0; iLad<maxLad; iLad++)
196       {
197          for(Int_t iMod=0; iMod<maxMod; iMod++)
198          {
199
200             fprintf( stderr, "Simulating data taking for layer %i, ladder %i, module %i ... \n", iLay, iLad, iMod );
201
202             TObjArray* valueSetOK = new TObjArray;
203             TObjArray* valueSetHV = new TObjArray;
204             TObjArray* valueSetMV = new TObjArray;
205             TObjArray* valueSetTL = new TObjArray;
206             TObjArray* valueSetTR = new TObjArray;
207             TObjArray* valueSetStTL = new TObjArray;
208             TObjArray* valueSetStTR = new TObjArray;
209
210             valueSetOK->SetOwner(1);
211             valueSetHV->SetOwner(1);
212             valueSetMV->SetOwner(1);
213             valueSetTL->SetOwner(1);
214             valueSetTR->SetOwner(1);
215             valueSetStTL->SetOwner(1);
216             valueSetStTR->SetOwner(1);
217
218             Float_t actualTL, actualTR;
219             Float_t actualHV, actualMV;
220             Int_t   actualStTL = 1;
221             Int_t   actualStTR = 1;
222             Int_t   actualStHV = 1;
223             Int_t   actualStMV = 1;
224                              // Readout devices are alive/dead
225
226             Float_t lastTL = mvalTL;
227             Float_t lastTR = mvalTR;
228             Float_t lastHV = mvalHV;
229             Float_t lastMV = mvalMV;
230                              // Last written values - udes for threshold readout
231
232             Int_t counterTL = 0;
233             Int_t counterTR = 0;
234             Int_t counterHV = 0;
235             Int_t counterMV = 0;
236             Int_t counterStTL = 0;
237             Int_t counterStTR = 0;
238             Int_t counterOK = 0;
239                               // Periodic readout counters
240
241             Int_t endingTimeStamp = stopTime.GetSec();
242
243             for( Int_t timeLoop = startTime.GetSec(); timeLoop < endingTimeStamp; timeLoop ++ )
244             {                 // Loop goes through period of run second per second and determines
245                               //  all values according to rules of DCS
246
247                actualTL = gRandom->Gaus( mvalTL, fluctTL );
248                actualTR = gRandom->Gaus( mvalTR, fluctTR );
249                actualHV = gRandom->Gaus( mvalHV, fluctHV );
250                actualMV = gRandom->Gaus( mvalMV, fluctMV );
251                               // Generates random values of temperatures and voltages
252                               //  in given ranges
253
254                if( gRandom->Rndm() < failureTLpersec ) 
255                 if( actualStTL ) actualStTL = 0; else if( gRandom->Rndm() < 0.1 ) actualStTL = 1;
256                if( gRandom->Rndm() < failureTRpersec ) 
257                 if( actualStTR ) actualStTR = 0; else if( gRandom->Rndm() < 0.1 ) actualStTR = 1;
258                if( gRandom->Rndm() < failureHVpersec ) 
259                 if( actualStHV ) actualStHV = 0; else if( gRandom->Rndm() < 0.1 ) actualStHV = 1;
260                if( gRandom->Rndm() < failureMVpersec ) 
261                 if( actualStMV ) actualStMV = 0; else if( gRandom->Rndm() < 0.1 ) actualStMV = 1;
262                               // Decides if any thermometer or voltage source becomes 
263                               //  dead (or alive again, but this have much 10x les probability )
264
265                if( gRandom->Rndm() < failureTL ) counterTL++;
266                if( gRandom->Rndm() < failureTL ) counterTL--;
267                if( gRandom->Rndm() < failureTR ) counterTR++;
268                if( gRandom->Rndm() < failureTR ) counterTR--;
269                if( gRandom->Rndm() < failureHV ) counterHV++;
270                if( gRandom->Rndm() < failureHV ) counterHV--;
271                if( gRandom->Rndm() < failureMV ) counterMV++;
272                if( gRandom->Rndm() < failureMV ) counterMV--;
273                if( gRandom->Rndm() < failureTL ) counterStTL++;
274                if( gRandom->Rndm() < failureTL ) counterStTL--;
275                if( gRandom->Rndm() < failureTR ) counterStTR++;
276                if( gRandom->Rndm() < failureTR ) counterStTR--;
277                if( gRandom->Rndm() < failureOK ) counterOK++;
278                if( gRandom->Rndm() < failureOK ) counterOK--;
279                         // Simulating noise in the clock frequency
280
281                if( counterTL >= freqROTL )
282                 { valueSetTL->Add( new AliDCSValue( actualTL, timeLoop ) ); lastTL = actualTL; counterTL = 0; created++; }
283                if( counterTR >= freqROTR )
284                 { valueSetTR->Add( new AliDCSValue( actualTR, timeLoop ) ); lastTR = actualTR; counterTR = 0; created++; }
285                if( counterHV >= freqROHV )
286                 { valueSetHV->Add( new AliDCSValue( actualHV, timeLoop ) ); lastHV = actualHV; counterHV = 0; created++; }
287                if( counterMV >= freqROMV )
288                 { valueSetMV->Add( new AliDCSValue( actualMV, timeLoop ) ); lastMV = actualMV; counterMV = 0; created++; }
289                if( counterStTL >= freqROStTL )
290                 { valueSetStTL->Add( new AliDCSValue( actualStTL, timeLoop ) ); counterStTL = 0; created++; }
291                if( counterStTR >= freqROStTR )
292                 { valueSetStTR->Add( new AliDCSValue( actualStTR, timeLoop ) ); counterStTR = 0; created++; }
293                if( counterOK >= freqROOK )
294                 { valueSetOK->Add( new AliDCSValue( (Bool_t)(actualStHV & actualStMV), timeLoop ) ); counterOK = 0; created++; }
295                         // Periodic readout
296
297                if( TMath::Abs( (lastTL - actualTL) / lastTL ) > fluctROTL )
298                 { valueSetTL->Add( new AliDCSValue( actualTL, timeLoop ) ); lastTL = actualTL; counterTL = 0; created1++; }
299                if( TMath::Abs( (lastTR - actualTR) / lastTR ) > fluctROTR )
300                 { valueSetTR->Add( new AliDCSValue( actualTR, timeLoop ) ); lastTR = actualTR; counterTR = 0; created1++; }
301                if( TMath::Abs( (lastHV - actualHV) / lastHV ) > fluctROHV )
302                 { valueSetHV->Add( new AliDCSValue( actualHV, timeLoop ) ); lastHV = actualHV; counterHV = 0; created1++; }
303                if( TMath::Abs( (lastMV - actualMV) / lastMV ) > fluctROMV )
304                 { valueSetMV->Add( new AliDCSValue( actualMV, timeLoop ) ); lastMV = actualMV; counterMV = 0; created1++; }
305                         // Treshold readout
306
307                counterTL++;
308                counterTR++;
309                counterHV++;
310                counterMV++;
311                counterStTL++;
312                counterStTR++;
313                counterOK++;
314
315             } /*for( timeLoop )*/
316
317             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_OK", iLay, iLad, iMod );
318             aliasName = dpName;
319             aliasMap->Add( new TObjString(aliasName), valueSetOK );
320
321             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_HV", iLay, iLad, iMod );
322             aliasName = dpName;
323             aliasMap->Add( new TObjString(aliasName), valueSetHV );
324
325             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_MV", iLay, iLad, iMod );
326             aliasName = dpName;
327             aliasMap->Add( new TObjString(aliasName), valueSetMV );
328
329             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_L", iLay, iLad, iMod );
330             aliasName = dpName;
331             aliasMap->Add( new TObjString(aliasName), valueSetTL );
332
333             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_R", iLay, iLad, iMod );
334             aliasName = dpName;
335             aliasMap->Add( new TObjString(aliasName), valueSetTR );
336
337             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_L_STATE", iLay, iLad, iMod );
338             aliasName = dpName;
339             aliasMap->Add( new TObjString(aliasName), valueSetStTL );
340
341             sprintf( dpName, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_R_STATE", iLay, iLad, iMod );
342             aliasName = dpName;
343             aliasMap->Add( new TObjString(aliasName), valueSetStTR );
344
345          } /*for( iMod ) */
346       } /*for( iLad )*/
347   } /*for( iLay )*/
348
349   fprintf(  stderr, "\nCreated %i objects of type AliDCSValue (%i periodic + %i treshold)... \n", 
350             created + created1, created, created1 );
351
352   return aliasMap;
353
354 } /*CreateRealisticMap*/
355
356 //----------------------------------------------------------------------------------------
357
358
359 TMap* CreateRandomMap( Int_t maxRecords , Int_t randomTimeStamps  )
360 {
361   // Creates a DCS structure
362   // The structure is the following:
363   //   TMap (key --> value)
364   //     <DCSAlias> --> <valueList>
365   //     <DCSAlias> is a string
366   //     <valueList> is a TObjArray of AliDCSValue
367   //     An AliDCSValue consists of timestamp and a value in form of a AliSimpleValue
368
369
370   TMap* aliasMap = new TMap;
371   aliasMap->SetOwner(1);
372
373
374   TString aliasName;
375   Char_t dpName[50];
376   Int_t created = 0;
377
378   for( Int_t iLay = 3; iLay < 5; iLay++ )
379   {
380
381       Int_t maxLad = ( iLay == 3) ? kNladders3 : kNladders4;
382       Int_t maxMod = ( iLay == 3) ? kNmodLad3 : kNmodLad4;
383
384       for(Int_t iLad = 0; iLad < maxLad; iLad++)
385       {
386          for(Int_t iMod =0 ; iMod < maxMod;iMod++)
387          {
388
389             fprintf( stderr, "Generating data for layer %i, ladder %i, module %i ... \n", iLay, iLad, iMod );
390
391             TObjArray* valueSetOK = new TObjArray;
392             TObjArray* valueSetH = new TObjArray;
393             TObjArray* valueSetM = new TObjArray;
394             TObjArray* valueSetTL = new TObjArray;
395             TObjArray* valueSetTR = new TObjArray;
396             TObjArray* valueSetStTL = new TObjArray;
397             TObjArray* valueSetStTR = new TObjArray;
398
399             valueSetOK->SetOwner(1);
400             valueSetH->SetOwner(1);
401             valueSetM->SetOwner(1);
402             valueSetTL->SetOwner(1);
403             valueSetTR->SetOwner(1);
404             valueSetStTL->SetOwner(1);
405             valueSetStTR->SetOwner(1);
406
407             Int_t nrOfRecords;
408             AliDCSValue* dcsVal;
409             Int_t timeStamp;
410
411             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_OK", iLay,iLad,iMod);
412             aliasName=dpName;
413             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ) );
414             timeStamp = 1000000000;
415             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
416             {
417                if( randomTimeStamps )
418                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
419                else
420                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
421             if( 1000*(gRandom->Rndm()) > 50 ) 
422                dcsVal = new AliDCSValue((Bool_t)1, timeStamp);
423             else
424                dcsVal = new AliDCSValue((Bool_t)0, timeStamp);
425             valueSetOK->Add(dcsVal);
426
427             } /*for( recLoop )*/
428             aliasMap->Add(new TObjString(aliasName), valueSetOK);
429             created += nrOfRecords;
430
431             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_HV", iLay, iLad,iMod);
432             aliasName=dpName;
433             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ));
434             timeStamp = 1000000000;
435             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
436             {
437                if( randomTimeStamps )
438                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
439                else
440                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
441                dcsVal = new AliDCSValue( (Float_t)( 1600 + 200*(gRandom->Rndm()) ), timeStamp );
442                valueSetH->Add(dcsVal);
443
444             } /*for( recLoop )*/
445             aliasMap->Add(new TObjString(aliasName), valueSetH);
446             created += nrOfRecords;
447
448             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_MV", iLay, iLad,iMod);
449             aliasName=dpName;
450             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ));
451             timeStamp = 1000000000;
452             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
453             {
454                if( randomTimeStamps )
455                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
456                else
457                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
458                dcsVal = new AliDCSValue( (Float_t)( 30 + 20*(gRandom->Rndm()) ), timeStamp );
459                valueSetM->Add(dcsVal);
460             } /*for( recLoop )*/
461             aliasMap->Add(new TObjString(aliasName), valueSetM);
462             created += nrOfRecords;
463
464             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_L", iLay, iLad,iMod);
465             aliasName=dpName;
466             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ));
467             timeStamp = 1000000000;
468             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
469             {
470                if( randomTimeStamps )
471                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
472                else
473                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
474                dcsVal = new AliDCSValue( (Float_t)( 50 + 50*(gRandom->Rndm()) ), timeStamp );
475                valueSetTL->Add(dcsVal);
476             } /*for( recLoop )*/
477             aliasMap->Add(new TObjString(aliasName), valueSetTL);
478             created += nrOfRecords;
479
480             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_R", iLay, iLad,iMod);
481             aliasName=dpName;
482             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ));
483             timeStamp = 1000000000;
484             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
485             {
486                if( randomTimeStamps )
487                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
488                else
489                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
490                dcsVal = new AliDCSValue( (Float_t)( 50 + 50*(gRandom->Rndm()) ), timeStamp );
491                valueSetTR->Add(dcsVal);
492             } /*for( recLoop )*/
493             aliasMap->Add(new TObjString(aliasName), valueSetTR);
494             created += nrOfRecords;
495
496             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_L_STATE", iLay, iLad,iMod);
497             aliasName=dpName;
498             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ));
499             timeStamp = 1000000000;
500             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
501             {
502                if( randomTimeStamps )
503                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
504                else
505                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
506                if( 1000*(gRandom->Rndm()) > 50 ) 
507                   dcsVal = new AliDCSValue((Int_t)1, timeStamp);
508                else
509                   dcsVal = new AliDCSValue((Int_t)0, timeStamp);
510                valueSetStTL->Add(dcsVal);
511             } /*for( recLoop )*/
512             aliasMap->Add(new TObjString(aliasName), valueSetStTL);
513             created += nrOfRecords;
514
515             sprintf(dpName,"SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_R_STATE", iLay, iLad,iMod);
516             aliasName=dpName;
517             nrOfRecords = (Int_t)(maxRecords * ( gRandom->Rndm() ));
518             timeStamp = 1000000000;
519             for( Int_t recLoop = 0; recLoop < nrOfRecords; recLoop ++ )
520             {
521                if( randomTimeStamps )
522                 timeStamp = (Int_t)(1200000000*(gRandom->Rndm()));
523                else
524                 timeStamp += (Int_t)(50*(gRandom->Rndm()) );
525                if( 1000*(gRandom->Rndm()) > 50 ) 
526                   dcsVal = new AliDCSValue((Int_t)1, timeStamp);
527                else
528                   dcsVal = new AliDCSValue((Int_t)0, timeStamp);
529                valueSetStTR->Add(dcsVal);
530
531             } /*for( recLoop )*/
532             aliasMap->Add(new TObjString(aliasName), valueSetStTR);
533             created += nrOfRecords;
534
535          } /*for( iMod ) */
536       } /*for( iLad )*/
537
538   } /*for( iLay )*/
539
540   fprintf(  stderr, "\nCreated %i objects of type AliDCSValue ... \n", created);
541
542   return aliasMap;
543 }
544
545 // -----------------------------------------------------------------------------
546
547 void GenerateOutputFiles( TMap *map, char *dir )
548 {
549
550   FILE  *outputFile;
551   char   buffer[100],cmd[100];
552   Int_t  nHVEntries, nMVEntries, nTLEntries, nTREntries;
553   Int_t  nOKEntries, nStTLEntries, nStTREntries;
554   
555   sprintf(cmd,"ls -l %s >/dev/null 2>&1",dir);
556   if(gSystem->Exec(cmd)!=0){
557     printf("%s --- NOT EXISTS -- create it\n",dir);
558     sprintf(cmd,"mkdir %s",dir);
559     gSystem->Exec(cmd);
560   }
561
562   for( Int_t iLay = 3; iLay < 5; iLay++ )
563   {
564
565      Int_t maxLad = ( iLay == 3) ? kNladders3 : kNladders4;
566      Int_t maxMod = ( iLay == 3) ? kNmodLad3 : kNmodLad4;
567
568      for(Int_t iLad = 0; iLad < maxLad; iLad++)
569      {
570
571
572         for(Int_t iMod = 0; iMod < maxMod; iMod++)
573         {
574
575            sprintf( buffer, "%s/DCSMapContent_SDD_LAYER%i_LADDER%02d_MODULE%d.txt", dir, iLay, iLad, iMod );
576
577            fprintf( stderr, "Creating file %s ... ", buffer );
578            outputFile = fopen( buffer, "w" );
579             if( outputFile == NULL )
580             {
581                fprintf( stderr, "failed!\n" );
582                return;
583             } /*if*/
584             else
585              fprintf( stderr, "\n" );
586
587
588            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_HV", iLay, iLad, iMod );
589            TObjArray* arrHV = (TObjArray*) map->GetValue( buffer );
590            if( arrHV == NULL ) 
591            {
592                fprintf( stderr, "Map record %s does not exist!\n", buffer );
593                nHVEntries = 0;
594            }
595            else
596             nHVEntries = arrHV->GetEntries();
597
598            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_MV", iLay, iLad, iMod );
599            TObjArray* arrMV = (TObjArray*) map->GetValue( buffer );
600            if( arrMV == NULL ) 
601            {
602                fprintf( stderr, "Map record %s does not exist!\n", buffer );
603                nMVEntries = 0;
604            }
605            else
606             nMVEntries = arrMV->GetEntries();
607
608            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_L", iLay, iLad, iMod );
609            TObjArray* arrTL = (TObjArray*) map->GetValue( buffer );
610            if( arrTL == NULL ) 
611            {
612                fprintf( stderr, "Map record %s does not exist!\n", buffer );
613                nTLEntries = 0;
614            }
615            else
616             nTLEntries = arrTL->GetEntries();
617
618            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_R", iLay, iLad, iMod );
619            TObjArray* arrTR = (TObjArray*) map->GetValue( buffer );
620            if( arrTR == NULL ) 
621            {
622                fprintf( stderr, "Map record %s does not exist!\n", buffer );
623                nTREntries = 0;
624            }
625            else
626             nTREntries = arrTR->GetEntries();
627
628            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_L_STATE", iLay, iLad, iMod );
629            TObjArray* arrStTL = (TObjArray*) map->GetValue( buffer );
630            if( arrStTL == NULL ) 
631            {
632                fprintf( stderr, "Map record %s does not exist!\n", buffer );
633                nStTLEntries = 0;
634            }
635            else
636             nStTLEntries = arrStTL->GetEntries();
637
638            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_TEMP_R_STATE", iLay, iLad, iMod );
639            TObjArray* arrStTR = (TObjArray*) map->GetValue( buffer );
640            if( arrStTR == NULL ) 
641            {
642                fprintf( stderr, "Map record %s does not exist!\n", buffer );
643                nStTREntries = 0;
644            }
645            else
646             nStTREntries = arrStTR->GetEntries();
647
648            sprintf( buffer, "SDD_LAYER%i_LADDER%02d_MODULE%d_OK", iLay, iLad, iMod );
649            TObjArray* arrOK = (TObjArray*) map->GetValue( buffer );
650            if( arrOK == NULL ) 
651            {
652                fprintf( stderr, "Map record %s does not exist!\n", buffer );
653                nOKEntries = 0;
654            }
655            else
656             nOKEntries = arrOK->GetEntries();
657
658            fprintf( outputFile, "+-----------------------------------------------------------------------");
659            fprintf( outputFile, "------------------------------------------------------------------------+\n" );
660            fprintf( outputFile, "|                                                DCS Map content for SDD_LAYER%i_LADDER%02d_MODULE%d" , iLay, iLad, iMod); 
661            fprintf( outputFile, "                                                |\n" );
662            fprintf( outputFile, "+----------------------+----------------------+---------------------+----------------------+");
663            fprintf( outputFile, "-----------------+-----------------+----------------+\n" );
664            fprintf( outputFile, "|    %05i  records    |    %05i  records    |    %05i  records   |    %05i  records   |  %05i records  |",
665                                  nHVEntries, nMVEntries, nTLEntries, nTREntries, nStTLEntries );
666            fprintf( outputFile, "  %05i records  | %05i  records  |\n", nStTREntries, nOKEntries );
667
668            fprintf( outputFile, "|  time (s)     HV     |  time (s)      MV    |  time (s)     TL    |  time (s)     TR    | time (s)   StTL |" );
669            fprintf( outputFile, " time (s)   StTR | time (s)   OK   |\n" );
670            fprintf( outputFile, "+----------------------+----------------------+---------------------+---------------------+");
671            fprintf( outputFile, "-----------------+-----------------+-----------------+\n" );
672
673
674
675            Int_t a = (nHVEntries > nMVEntries ) ? nHVEntries : nMVEntries;
676            Int_t b = (nTLEntries > nTREntries ) ? nTLEntries : nTREntries;
677            Int_t c = (nStTLEntries > nStTREntries ) ? nStTLEntries : nStTREntries;
678            if( a < b ) a = b; if( c < nOKEntries ) c = nOKEntries;
679            Int_t loopMax = ( a > c ) ? a : c ;
680                         // Finds maximal entry number
681
682
683
684            for( Int_t entryLoop = 0; entryLoop < loopMax; entryLoop++ )
685            {
686
687                if( entryLoop < nHVEntries )
688                 fprintf( outputFile, "| %12i %4.2f | ", ((AliDCSValue*)arrHV->At(entryLoop))->GetTimeStamp(),
689                                                                    ((AliDCSValue*)arrHV->At(entryLoop))->GetFloat() );
690                else
691                 fprintf( outputFile, "|                      | ");
692
693                if( entryLoop < nMVEntries )
694                fprintf( outputFile, " %12i  %2.2f | ", ((AliDCSValue*)arrMV->At(entryLoop))->GetTimeStamp(), 
695                                                                    ((AliDCSValue*)arrMV->At(entryLoop))->GetFloat() );
696                else
697                fprintf( outputFile, "                     | ");
698
699                if( entryLoop < nTLEntries )
700                fprintf( outputFile, "%12i  %2.2f | ", ((AliDCSValue*)arrTL->At(entryLoop))->GetTimeStamp(), 
701                                                                    ((AliDCSValue*)arrTL->At(entryLoop))->GetFloat() );
702                else
703                fprintf( outputFile, "                    | ");
704
705                if( entryLoop < nTREntries )
706                fprintf( outputFile, "%12i  %2.2f | ", ((AliDCSValue*)arrTR->At(entryLoop))->GetTimeStamp(), 
707                                                                    ((AliDCSValue*)arrTR->At(entryLoop))->GetFloat() );
708                else
709                fprintf( outputFile, "                    | ");
710
711                if( entryLoop < nStTLEntries )
712                fprintf( outputFile, "%12i  %i | ", ((AliDCSValue*)arrStTL->At(entryLoop))->GetTimeStamp(),
713                                                                    ((AliDCSValue*)arrStTL->At(entryLoop))->GetInt() );
714                else
715                fprintf( outputFile, "                | ");
716
717                if( entryLoop < nStTREntries )
718                fprintf( outputFile, "%12i  %i | ",  ((AliDCSValue*)arrStTR->At(entryLoop))->GetTimeStamp(),
719                                                                    ((AliDCSValue*)arrStTR->At(entryLoop))->GetInt() );
720                else
721                fprintf( outputFile, "                | ");
722
723                if( entryLoop < nOKEntries )
724                fprintf( outputFile, "%12i  %i |\n",  ((AliDCSValue*)arrOK->At(entryLoop))->GetTimeStamp(), 
725                                                                     ((AliDCSValue*)arrOK->At(entryLoop))->GetBool() );
726                else
727                fprintf( outputFile, "                |\n");
728
729            } /*for( entryLoop )*/
730
731            fclose( outputFile );
732
733
734         } /*for(iMod)*/
735
736
737      } /*for(iLad)*/
738    } /*for(iLay)*/
739
740
741 } /*GenerateOutputFiles*/