]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSDCSAnalyzerSDD.cxx
New treatment of DCS data points for SDD (V. Pospisil)
[u/mrichter/AliRoot.git] / ITS / AliITSDCSAnalyzerSDD.cxx
1 /**************************************************************************
2  * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id:$ */
17
18 ///////////////////////////////////////////////////////////////////
19 //                                                               //
20 // Implementation of the class for SDD DCS data analysis         //
21 // Origin: F.Prino, Torino, prino@to.infn.it                     //
22 //         V.Pospisil, CTU Prague, gdermog@seznam.cz             //
23 ///////////////////////////////////////////////////////////////////
24
25
26 #include "AliITSDCSAnalyzerSDD.h"
27 #include "AliDCSValue.h"
28 #include "AliLog.h"
29 #include "AliITSgeomTGeo.h"
30
31 ClassImp(AliITSDCSAnalyzerSDD)
32
33 //---------------------------------------------------------------
34   AliITSDCSAnalyzerSDD::AliITSDCSAnalyzerSDD(): TObject(),
35 fHVDelay(0),fMVDelay(0),fTLDelay(0),fTRDelay(0),fStTLDelay(0),fStTRDelay(0),fOKDelay(0)
36 {                       
37 // Default constructor
38   Init();
39 } /*AliITSDCSAnalyzerSDD::AliITSDCSAnalyzerSDD*/
40
41 //---------------------------------------------------------------
42
43 AliITSDCSAnalyzerSDD::AliITSDCSAnalyzerSDD(const AliITSDCSAnalyzerSDD& /* dcsa */): TObject(),
44 fHVDelay(0),fMVDelay(0),fTLDelay(0),fTRDelay(0),fStTLDelay(0),fStTRDelay(0),fOKDelay(0)
45 {                       
46 // copy constructor
47                         // Copies are not allowed. The method is protected to avoid misuse.
48   fprintf( stderr, "Copy constructor not allowed");
49 } /*AliITSDCSAnalyzerSDD::AliITSDCSAnalyzerSDD*/
50
51 //---------------------------------------------------------------
52
53 AliITSDCSAnalyzerSDD& AliITSDCSAnalyzerSDD::operator=(const AliITSDCSAnalyzerSDD& /* dcsa */)
54 {                       
55 // assigment operator
56                         // Assignment is not allowed. The method is protected to avoid misuse.
57   fprintf( stderr, "Assignment operator not allowed");
58   return *this;
59 }/*AliITSDCSAnalyzerSDD::operator=*/
60
61 //---------------------------------------------------------------
62
63 AliITSDCSAnalyzerSDD::~AliITSDCSAnalyzerSDD()
64 {                       
65 // destructor
66   for(int j=0; j<kNmodules; j++)
67   {
68     if(fDCSData[j]) delete fDCSData[j];
69   } /*for( j )*/
70 } /*AliITSDCSAnalyzerSDD::~AliITSDCSAnalyzerSDD*/
71
72 //---------------------------------------------------------------
73
74 void AliITSDCSAnalyzerSDD::AnalyzeData(TMap* dcsMap)
75 {                       
76 // Data processing
77
78    Int_t counter = 0;
79
80    for( Int_t iLay = 3; iLay < 5; iLay++ )
81    {
82
83       Int_t maxLad = ( iLay == 3) ? kNladders3 : kNladders4;
84       Int_t maxMod = ( iLay == 3) ? kNmodLad3 : kNmodLad4;
85
86       for(Int_t iLad = 0; iLad < maxLad; iLad++)
87       {
88          for(Int_t iMod = 0; iMod < maxMod; iMod++)
89          {
90                         // Loads arrays of DCS variables from map. Variables are 
91                         //  searched by names (for ex. SDD_LAYER3_LADDER5_MODULE4_HV)
92
93             Int_t moduleLoop = AliITSgeomTGeo::GetModuleIndex( iLay, iLad + 1, iMod + 1 ) - 240;
94
95             TObjArray* arrHV = (TObjArray*) dcsMap->GetValue( fHVDPNames[moduleLoop].Data() );
96             if(!arrHV)
97             {
98                fprintf( stderr, Form("DCS HV alias %s not found!\n", fHVDPNames[moduleLoop].Data()));
99                continue;
100             } /*if*/
101
102             TObjArray* arrMV = (TObjArray*) dcsMap->GetValue( fMVDPNames[moduleLoop].Data() );
103             if(!arrMV)
104             {
105                fprintf( stderr, Form("DCS MV alias %s not found!\n", fMVDPNames[moduleLoop].Data()));
106                continue;
107             } /*if*/
108
109             TObjArray* arrOK = (TObjArray*) dcsMap->GetValue( fOKDPNames[moduleLoop].Data() );
110             if(!arrOK)
111             {
112                fprintf( stderr, Form("DCS MOD_OK alias %s not found!\n", fOKDPNames[moduleLoop].Data()));
113                continue;
114             } /*if*/
115
116             TObjArray* arrTL = (TObjArray*) dcsMap->GetValue( fTLDPNames[moduleLoop].Data() );
117             if(!arrTL)
118             {
119                fprintf( stderr, Form("DCS TEMP_L alias %s not found!\n", fTLDPNames[moduleLoop].Data()));
120                continue;
121             } /*if*/
122
123             TObjArray* arrTR = (TObjArray*) dcsMap->GetValue( fTRDPNames[moduleLoop].Data() );
124             if(!arrTR)
125             {
126                fprintf( stderr, Form("DCS TEMP_R alias %s not found!\n", fTRDPNames[moduleLoop].Data()));
127                continue;
128             } /*if*/
129
130             TObjArray* arrStTL = (TObjArray*) dcsMap->GetValue( fTLStDPNames[moduleLoop].Data() );
131             if(!arrStTL)
132             {
133                fprintf( stderr, Form("DCS TEMP_L_STATE alias %s not found!\n", fTLStDPNames[moduleLoop].Data()));
134                continue;
135             } /*if*/
136
137             TObjArray* arrStTR = (TObjArray*) dcsMap->GetValue( fTRStDPNames[moduleLoop].Data() );
138             if(!arrStTR) 
139             {
140                fprintf( stderr, Form("DCS TEMP_R_STATE alias %s not found!\n", fTRStDPNames[moduleLoop].Data()));
141                continue;
142             } /*if*/
143
144             fDCSData[moduleLoop] = new AliITSDCSDataSDD;
145                         // DCS data for specific SDD module will be stored in this class
146
147             Int_t nEntries;     
148                         // Number of entries in each TObjArray, that contains DCS variable values
149             AliDCSValue *valToProcess;
150                         // Pointer to currently processed DCS variable value
151
152             nEntries = arrTL->GetEntries();
153             fDCSData[moduleLoop]->SetNPointsTempLeft( nEntries );
154                         // Left temperature array size is set
155
156             for( Int_t tlLoop = 0; tlLoop < nEntries; tlLoop++ )
157             {           // Left temerature values are copied into the AliITSDCSDataSDD TempLeft array
158                valToProcess = (AliDCSValue *)(arrTL->At(tlLoop));
159                fDCSData[moduleLoop]->SetValueTempLeft( valToProcess->GetTimeStamp() - fTLDelay, valToProcess->GetFloat() );
160             } /*for( tlLoop )*/
161             counter += nEntries;
162
163             nEntries = arrTR->GetEntries();
164             fDCSData[moduleLoop]->SetNPointsTempRight( nEntries );
165                         // Right temperature array size is set 
166
167             for( Int_t trLoop = 0; trLoop < nEntries; trLoop++ )
168             {           // Right temerature values are copied into the AliITSDCSDataSDD TempRight array
169                valToProcess = (AliDCSValue *)(arrTR->At(trLoop));
170                fDCSData[moduleLoop]->SetValueTempRight( valToProcess->GetTimeStamp() - fTRDelay, valToProcess->GetFloat() );
171             } /*for( trLoop )*/
172             counter += nEntries;
173
174             nEntries = arrHV->GetEntries();
175             fDCSData[moduleLoop]->SetNPointsHV( nEntries );
176                         // HV array size is set 
177
178             for( Int_t hvLoop = 0; hvLoop < nEntries; hvLoop++ )
179             {           // HV values are copied into the AliITSDCSDataSDD HV array
180                valToProcess = (AliDCSValue *)(arrHV->At(hvLoop));
181                fDCSData[moduleLoop]->SetValueHV( valToProcess->GetTimeStamp() - fHVDelay, valToProcess->GetFloat() );
182             } /*for( hvLoop )*/
183             counter += nEntries;
184
185             nEntries = arrMV->GetEntries();
186             fDCSData[moduleLoop]->SetNPointsMV( nEntries );
187                         // MV array size is set 
188
189             for( Int_t mvLoop = 0; mvLoop < nEntries; mvLoop++ )
190             {           // MV values are copied into the AliITSDCSDataSDD MV array
191                valToProcess = (AliDCSValue *)(arrMV->At(mvLoop));
192                fDCSData[moduleLoop]->SetValueMV( valToProcess->GetTimeStamp() - fMVDelay, valToProcess->GetFloat() );
193             } /*for( mvLoop )*/
194             counter += nEntries;
195
196 /* Following part of the code is responsibile for the condensing of all status information given by DCS
197    into one array of Char_t. Each record of this array is in principle a bit map : 
198
199       0. bit ... _OK
200       1. bit ... _TEMP_L_STATE
201       2. bit ... _TEMP_R_STATE 
202
203    Each record have its own time stamp. Because there are three inputs with independent time stamp,
204    some algorithm which assigns new time stamp to bitmap according to three input time stamps is
205    necessary.
206
207    Let's vizualize time stamps of the three input arrays. There is time on x-axis :
208
209             +------------+---------------------+------
210             |            |                     |           _OK
211       +------+------+---+--------+------------+------
212       |      |      |            |            |           _TEMP_L_STATE
213    +--+------+---+--+-------+-----+--------+---+------
214    |             |          |     |        |   |          _TEMP_R_STATE
215    +-------------+----------+-----+--------+---+------
216
217    |   |    | |  |   |   |  |     |        |   |
218    V   V    V V  V   V   V  V     V        V   V
219
220    +---+----+-+--+---+---+--+-----+--------+---+------
221    |   |    | |  |   |   |  |     |        |   |           Status bitmap
222    +---+----+-+--+---+---+--+-----+--------+---+------
223
224
225    Principle of combining three status records into one is visible from the picture.
226    If there are two sequent records with the same status bitmap, they are joined into
227    one (with the time stamp of the earliest one).
228
229 */
230
231             Int_t nStTLEntries = arrStTL->GetEntries();
232             Int_t nStTREntries = arrStTR->GetEntries();
233             Int_t nOKEntries = arrOK->GetEntries();
234                         // Gets number of _STAT_L, _STAT_R and _OK values stored in dcsMap
235
236             if( nStTLEntries < 1 )
237             {           // TObjArray arrStTL is empty. This would cause segmentation violation during
238                         //  the condensing, so this case must be handled before algorithm starts
239                fprintf( stderr, "%s contains no data!\n", fTLStDPNames[moduleLoop].Data() );
240                nStTLEntries = 1;
241                arrStTL->Add( new AliDCSValue(  (Int_t)0, 0x7FFFFFFF ) );
242                         // 0x7FFFFFFF = 2147483647, maximal signed Int_t number. Left temperature
243                         //  sensor will be regarded as switched-off during whole run.
244             } /*if*/
245  
246             if( nStTREntries < 1 )
247             {           // TObjArray arrStTR is empty. This would cause segmentation violation during
248                         //  the condensing, so this case must be handled before algorithm starts
249                fprintf( stderr, "%s contains no data!\n", fTRStDPNames[moduleLoop].Data() );
250                nStTREntries = 1;
251                arrStTR->Add( new AliDCSValue(  (Int_t)0, 0x7FFFFFFF ) );
252                         // 0x7FFFFFFF = 2147483647, maximal signed Int_t number. Right temperature
253                         //  sensor will be regarded as switched-off during whole run.
254             } /*if*/
255
256             if( nOKEntries < 1 )
257             {           // TObjArray arrOK is empty. This would cause segmentation violation during
258                         //  the condensing, so this case must be handled before algorithm starts
259                fprintf( stderr, "%s contains no data!\n", fOKDPNames[moduleLoop].Data() );
260                nOKEntries = 1;
261                arrOK->Add( new AliDCSValue(  (Bool_t)0, 0x7FFFFFFF ) );
262                         // 0x7FFFFFFF = 2147483647, maximal signed Int_t number.
263                         //  Module will be regarded as switched-off during whole run.
264             } /*if*/
265
266             arrStTL->Sort();
267             arrStTR->Sort();
268             arrOK->Sort();
269                         // Condensing would work properly only in the case that
270                         //  the input arrays are sorted by time
271
272             Int_t nEntriesMax = nStTLEntries + nStTREntries + nOKEntries;
273             fDCSData[moduleLoop]->SetNPointsStatus( nEntriesMax );
274                         // Determines necessary length of new array and sets its size 
275                         //  Lot of space in such defined array will be probably 
276                         //  vacant after the analysis, but this will be corrected
277                         //  by Compress() method
278
279             Int_t idxStTL = 0;
280             Int_t idxStTR = 0;
281             Int_t idxOK = 0;    
282                         // Input arrays indexes
283
284             Int_t tsStTL, tsStTR, tsOK;
285                         // Time stamps ofinput arrays
286             Int_t tsNew;// New time stamp (output array)
287
288             Char_t bitStatus;   
289                         // New status record :
290                         // 0. bit ... _OK
291                         // 1. bit ... _TEMP_L_STATE
292                         // 2. bit ... _TEMP_R_STATE 
293             Char_t lastBitStatus = 100;
294
295             AliDCSValue *valStTL, *valStTR, *valOK;
296                         // Pointers to input arrays records (input arrays are TObjArrays
297                         //  containing objects of type AliDCSValue
298
299             tsStTR = ( (AliDCSValue *)arrStTR->At(0) )->GetTimeStamp() - fStTLDelay;
300             tsStTL = ( (AliDCSValue *)arrStTL->At(0) )->GetTimeStamp() - fStTRDelay;
301             tsOK = ( (AliDCSValue *)arrOK->At(0) )->GetTimeStamp() - fOKDelay;
302                         // Time stamps of first records in input filea are readed (and delays are substracted)
303
304             tsNew = (tsStTR < tsStTL) ? tsStTR : tsStTL;
305             if( tsNew > tsOK ) tsNew = tsOK;
306                         // Time intervals are "prolonged" to the very eaarliest of time stamps.
307                         //  It means that first output time stamp will be the same as the one
308                         //  which is first in input arrays. Values of other DCS variables are
309                         //  not defined in this time yet, but they will be treated as equal to
310                         //  values in first records of input arrays.
311
312             nStTLEntries--; nStTREntries--; nOKEntries--;
313                         // Indexes in the input array must not exceed last records.
314
315             while( (idxStTL < nStTLEntries) || (idxStTR < nStTREntries) || (idxOK < nOKEntries) )
316             {           // Loop goes throug all three input files
317
318                valStTL = (AliDCSValue *)( arrStTL->At(idxStTL) );
319                valStTR = (AliDCSValue *)( arrStTR->At(idxStTR) );
320                valOK = (AliDCSValue *)( arrOK->At(idxOK) );
321                         // Values are readed from input arrays
322
323                bitStatus = 0;
324                if( valOK->GetBool() ) bitStatus += 1;        // 0. bit - _OK
325                if( valStTL->GetInt() == 1 ) bitStatus += 2;  // 1. bit - _TEMP_L_STATE
326                if( valStTR->GetInt() == 1 ) bitStatus += 4;  // 2. bit - _TEMP_R_STATE
327                         // Bit map is created
328
329                if( lastBitStatus != bitStatus )
330                {              // If the status bitmap is teh same as last one, it would not be stored.
331                               //  It will save much space.
332                   fDCSData[moduleLoop]->SetValueStatus( tsNew, bitStatus );
333                               // Bit map is written into the output array (if different from last value )
334                   lastBitStatus = bitStatus;
335                   counter += nEntries;
336                } /*if*/
337
338                if( idxStTL == nStTLEntries )
339                 tsStTL = 0x7FFFFFFF;  // = 2147483647, maximal signed Int_t number
340                else
341                 tsStTL = ( (AliDCSValue *)arrStTL->At(idxStTL + 1) )->GetTimeStamp() - fStTLDelay;
342
343                if( idxStTR == nStTREntries )
344                 tsStTR = 0x7FFFFFFF;  // = 2147483647, maximal signed Int_t number
345                else
346                 tsStTR = ( (AliDCSValue *)arrStTR->At(idxStTR + 1) )->GetTimeStamp() - fStTRDelay;
347
348                if( idxOK == nOKEntries )
349                 tsOK = 0x7FFFFFFF;    // = 2147483647, maximal signed Int_t number
350                else
351                 tsOK = ( (AliDCSValue *)arrOK->At(idxOK + 1) )->GetTimeStamp() - fOKDelay;
352                         // Reads time stamps of folowing records in the input arrays (and substracts delays).
353                         // Validity of the last records in the input arrays are prolonged
354                         //  to "infinity"
355
356                if( tsStTL == tsOK && tsStTR == tsOK )  { tsNew = tsStTL; idxStTL++; idxStTR++; idxOK++; continue; }
357                if( tsStTL == tsStTR && tsStTR < tsOK ) { tsNew = tsStTL; idxStTL++; idxStTR++; continue; }
358                if( tsStTL == tsOK && tsOK < tsStTR )   { tsNew = tsStTL; idxStTL++; idxOK++; continue; }
359                if( tsStTR == tsOK && tsOK < tsStTL )   { tsNew = tsStTR; idxStTR++; idxOK++; continue; } 
360                if( tsOK < tsStTL && tsOK < tsStTR )    { tsNew = tsOK;   idxOK++;   continue; }
361                if( tsStTL < tsOK && tsStTL < tsStTR )  { tsNew = tsStTL; idxStTL++; continue; }
362                /*Last possibile case*/                 { tsNew = tsStTR; idxStTR++; }
363
364                         // Index of array, whose following record have time stamp closest to just written one,
365                         //  is increased. If there are more records with identical time stamps meeting this condition,
366                         //  all correspondent indexes are increased. 
367
368             } /*while*/
369
370
371           } /*for( iMod )*/
372        } /*for( iLad )*/
373     } /*for( iLay )*/
374
375
376 } /*AliITSDCSAnalyzerSDD::AnalyzeData*/
377
378
379 //---------------------------------------------------------------
380
381
382 void AliITSDCSAnalyzerSDD::Init()
383 {
384   // Initialization of DCS DP names
385   Char_t dpName[50];
386   Char_t modName[50];
387
388
389   for( Int_t iLay = 3; iLay < 5; iLay++ )
390   {
391
392      Int_t maxLad = ( iLay == 3) ? kNladders3 : kNladders4;
393      Int_t maxMod = ( iLay == 3) ? kNmodLad3 : kNmodLad4;
394
395      for(Int_t iLad=0; iLad<maxLad; iLad++)
396      {
397         for(Int_t iMod=0; iMod<maxMod;iMod++)
398         {
399            sprintf(modName,"SDD_LAYER%i_LADDER%02d_MODULE%d", iLay, iLad, iMod);
400            Int_t id = AliITSgeomTGeo::GetModuleIndex( iLay, iLad + 1, iMod + 1 ) - 240;
401
402            sprintf(dpName,"%s_HV",modName);
403            fHVDPNames[id]=dpName;
404            sprintf(dpName,"%s_MV",modName);
405            fMVDPNames[id]=dpName;
406            sprintf(dpName,"%s_OK",modName);
407            fOKDPNames[id]=dpName;
408            sprintf(dpName,"%s_TEMP_L",modName);
409            fTLDPNames[id]=dpName;
410            sprintf(dpName,"%s_TEMP_R",modName);
411            fTRDPNames[id]=dpName;
412            sprintf(dpName,"%s_TEMP_L_STATE",modName);
413            fTLStDPNames[id]=dpName;
414            sprintf(dpName,"%s_TEMP_R_STATE",modName);
415            fTRStDPNames[id]=dpName;
416
417         } /*for( iMod )*/
418      } /*for( iLad )*/
419
420   } /*for( iLay )*/
421
422
423 } /*AliITSDCSAnalyzerSDD::Init*/
424
425 //---------------------------------------------------------------
426 void AliITSDCSAnalyzerSDD::PrintDCSDPNames( FILE *output )
427 {
428   // Data processing
429   for( Int_t j = 0; j < kNmodules; j++ )
430   {
431     fprintf( output, "Module %d      %s   %s   %s   %s\n",j,fHVDPNames[j].Data(),
432                           fMVDPNames[j].Data(),fTLDPNames[j].Data(),fTRDPNames[j].Data());
433   } /*for( j )*/
434 } /*AliITSDCSAnalyzerSDD::PrintDCSDPNames*/