]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCNoiseMapComponent.cxx
correcting compilation warning and making change of AliShuttleInterface (rev 29388)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCNoiseMapComponent.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        *
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no>          *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTPCNoiseMapComponent.cxx
20     @author Kalliopi Kanaki
21     @date   
22     @brief  The TPC Noise Map component
23 */
24
25 #if __GNUC__>= 3
26 using namespace std;
27 #endif
28
29 #include "AliHLTTPCNoiseMapComponent.h"
30 #include "AliHLTTPCDigitReaderDecoder.h"
31 //#include "AliHLTTPCDigitReaderPacked.h"
32 #include "AliHLTTPCTransform.h"
33 #include "AliHLTTPCDefinitions.h"
34
35 #include "AliCDBEntry.h"
36 #include "AliCDBManager.h"
37 #include "AliCDBStorage.h"
38 #include "AliHLTTPCNoiseMap.h"
39
40 #include "AliTPCCalPad.h"
41 #include "AliTPCROC.h"
42 #include "AliTPCCalROC.h"
43
44 #include <cstdlib>
45 #include <cerrno>
46 #include "TString.h"
47 #include "TFile.h"
48 #include "TObjArray.h"
49 #include "TObjString.h"
50 #include <sys/time.h>
51 #include "TH2.h"
52 #include "TH3.h"
53
54 ClassImp(AliHLTTPCNoiseMapComponent) //ROOT macro for the implementation of ROOT specific class methods
55
56 AliHLTTPCNoiseMapComponent::AliHLTTPCNoiseMapComponent()
57     :    
58     fSpecification(0),
59     fPlotSideA(0),
60     fPlotSideC(0),    
61     fApplyNoiseMap(0),
62     fResetHistograms(0),
63     fIsPacked(0),
64     fIsUnpacked(0),
65     fCurrentSlice(-99),
66     fCurrentPartition(-99),
67     fCurrentRow(-99),
68     fHistSignal(NULL),
69     fHistMaxSignal(NULL),
70     fHistTotSignal(NULL),
71     fHistPadRMS(NULL),
72     fHistCDBMap(NULL),    
73     fHistSideA(NULL),  
74     fHistSideC(NULL)
75 {
76   // see header file for class documentation
77   // or
78   // refer to README to build package
79   // or
80   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
81 }
82
83 AliHLTTPCNoiseMapComponent::~AliHLTTPCNoiseMapComponent() { 
84 // see header file for class documentation
85
86 }
87
88 // Public functions to implement AliHLTComponent's interface.
89 // These functions are required for the registration process
90
91 const char* AliHLTTPCNoiseMapComponent::GetComponentID() { 
92 // see header file for class documentation
93
94   return "TPCNoiseMap";
95 }
96
97 void AliHLTTPCNoiseMapComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
98 // see header file for class documentation
99
100   list.clear(); 
101   list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
102 }
103
104 AliHLTComponentDataType AliHLTTPCNoiseMapComponent::GetOutputDataType() { 
105 // see header file for class documentation
106
107   return kAliHLTDataTypeHistogram;
108 }
109
110 int AliHLTTPCNoiseMapComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
111 // see header file for class documentation
112
113   tgtList.clear();
114   tgtList.push_back(kAliHLTDataTypeHistogram);
115   return tgtList.size();
116 }
117
118 void AliHLTTPCNoiseMapComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
119 // see header file for class documentation
120
121   constBase=800000;
122   inputMultiplier=0.0;
123 }
124
125 AliHLTComponent* AliHLTTPCNoiseMapComponent::Spawn() { 
126 // see header file for class documentation
127
128   return new AliHLTTPCNoiseMapComponent();
129 }
130         
131 int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) { 
132 // see header file for class documentation
133  
134   Int_t i = 0;
135   Char_t* cpErr;
136   
137   int iResult=0;
138   
139   TString configuration="";
140   TString argument="";
141   for (int j=0; j<argc && iResult>=0; j++) {
142     
143     argument=argv[j];
144     if (!configuration.IsNull()) configuration+=" ";
145     configuration+=argument;    
146   }
147    
148   if (!configuration.IsNull()) {
149     iResult=Configure(configuration.Data());
150   } else {
151     iResult=Reconfigure(NULL, NULL);
152   }
153
154  
155   while ( i < argc ) {      
156     if (!strcmp( argv[i], "-apply-noisemap")) {
157         fApplyNoiseMap = strtoul( argv[i+1], &cpErr ,0);
158             
159     if ( *cpErr ) {
160         HLTError("Cannot convert apply-noisemap specifier '%s'.", argv[i+1]);
161         return EINVAL;
162     }
163       i+=2;
164       continue;
165     }
166     
167     if (!strcmp( argv[i], "-plot-side-a")) {
168         fPlotSideA = strtoul( argv[i+1], &cpErr ,0);
169             
170     if ( *cpErr ) {
171         HLTError("Cannot convert plot-side-a specifier '%s'.", argv[i+1]);
172         return EINVAL;
173     }
174       i+=2;
175       continue;
176     }
177     
178     if (!strcmp( argv[i], "-plot-side-c")) {
179         fPlotSideC = strtoul( argv[i+1], &cpErr ,0);
180     
181     if ( *cpErr ) {
182         HLTError("Cannot convert plot-side-c specifier '%s'.", argv[i+1]);
183         return EINVAL;
184     }
185       i+=2;
186       continue;
187     }
188
189     if (!strcmp( argv[i], "-reset-histograms")) {
190         fResetHistograms = strtoul( argv[i+1], &cpErr ,0);
191     
192     if ( *cpErr ) {
193         HLTError("Cannot convert reset-histograms specifier '%s'.", argv[i+1]);
194         return EINVAL;
195     }
196       i+=2;
197       continue;
198     }
199                    
200     Logging(kHLTLogError, "HLT::TPCNoiseMap::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
201     return EINVAL;
202
203   } // end while
204   
205   if(fApplyNoiseMap){
206      AliHLTTPCNoiseMap *nm = AliHLTTPCNoiseMap::Instance();
207      if(!nm) { 
208          HLTWarning("AliHLTTPCNoiseMap instance not existent."); 
209      }
210      else {
211          AliTPCCalPad *noisePad = nm->ReadNoiseMap(GetRunNo());
212          if(noisePad) {
213             fHistCDBMap = noisePad->MakeHisto2D(1);
214             
215          }
216      }
217   }
218
219 //   if(fApplyNoiseMap){
220 //     //TFile *f = TFile::Open("/scratch/noiseComp/Run3398_4000_v0_s72.root");
221 //     TFile *f = TFile::Open("/home/kanaki/noiseComp/Run3398_4000_v0_s72.root");
222 //     AliCDBEntry *pEntry = (AliCDBEntry*)f->Get("AliCDBEntry"); 
223 //     noisePad = (AliTPCCalPad*)pEntry->GetObject();
224 //     //fHistCDBMap = noisePad->MakeHisto2D(1); //side C
225 //   }
226    
227   if(fPlotSideA){
228      fHistSideA = new TH2F("fHistSideA","TPC Side A",250,-250,250,250,-250,250);                
229      fHistSideA->SetXTitle("global X (cm)"); fHistSideA->SetYTitle("global Y (cm)");
230   }   
231   
232   if(fPlotSideC){    
233      fHistSideC = new TH2F("fHistSideC","TPC Side C",250,-250,250,250,-250,250);
234      fHistSideC->SetXTitle("global X (cm)"); fHistSideC->SetYTitle("global Y (cm)");
235   }
236  
237   fHistMaxSignal = new TH2F("fHistMaxSignal","maximum signal",   250,-250,250,250,-250,250);
238   fHistTotSignal = new TH2F("fHistTotSignal","total signal",     250,-250,250,250,-250,250);
239   fHistPadRMS    = new TH2F("fHistPadRMS",   "RMS",              250,-250,250,250,-250,250);
240   //fHistSignal    = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
241  
242 //   HLTDebug("using AliHLTTPCDigitReaderDecoder");
243 //   pDigitReader = new AliHLTTPCDigitReaderDecoder(); // double-loop
244 //   pDigitReader = new AliHLTTPCDigitReaderPacked();
245   
246   return 0;
247
248 } // end DoInit()
249
250 int AliHLTTPCNoiseMapComponent::DoDeinit() { 
251 // see header file for class documentation  
252
253   if(fHistMaxSignal) delete fHistMaxSignal; fHistMaxSignal = NULL;
254   if(fHistTotSignal) delete fHistTotSignal; fHistTotSignal = NULL;
255   if(fHistPadRMS)    delete fHistPadRMS;    fHistPadRMS    = NULL;
256   if(fHistSideA)     delete fHistSideA;     fHistSideA     = NULL;
257   if(fHistSideC)     delete fHistSideC;     fHistSideC     = NULL;
258        
259   return 0;
260 }
261
262 int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/){
263 // see header file for class documentation
264  
265   //HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
266  
267   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
268    
269   const AliHLTComponentBlockData *iter = NULL;
270
271   Float_t xyz[3]; 
272   Int_t thissector, thisrow;
273     
274   for(iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){
275       
276      HLTInfo("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", 
277               evtData.fEventID, evtData.fEventID,
278               DataType2Text(iter->fDataType).c_str(), 
279               DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
280
281      if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType && GetEventCount()<2){
282          HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!", 
283          DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
284          DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
285      }      
286      
287      if (iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)) continue;
288       
289      UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
290      UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
291      
292      fSpecification = iter->fSpecification;
293      
294      AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
295
296      pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
297      if(!pDigitReader) break;
298        
299      //sprintf(name,"hMaxSignal_slice%d_partition%d", slice, partition);
300      //fHistMaxSignal = new TH2F(name,name,250,-250,250,250,-250,250);
301             
302      while(pDigitReader->Next()){ 
303      //while( pDigitReader->NextChannel()) { // pad loop 
304       
305       fCurrentRow  = pDigitReader->GetRow();  
306       fCurrentRow += pDigitReader->GetRowOffset();
307
308       AliHLTTPCTransform::Slice2Sector(slice,fCurrentRow,thissector,thisrow);
309       AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
310       
311       if(slice>17) xyz[1] = (-1.0)*xyz[1];
312       else continue;
313       
314       AliHLTTPCTransform::Local2Global(xyz,slice);
315       // temporarily the transformation Raw2Global will be broken down to 2 steps,
316       // as there is a correction necessary at the y coordinate of the local xyz.
317       
318       //AliHLTTPCTransform::Raw2Global(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
319       // transformation from pad-row coordinates to global ones
320       // time info is not taken into account
321       
322 //       AliTPCCalROC *calRoc = noisePad->GetCalROC(thissector);
323 //       calRoc->GetValue(thisrow,pDigitReader->GetPad());
324       
325       //while( pDigitReader->NextBunch()) {
326     
327       const UInt_t *bunchData = pDigitReader->GetSignals();
328       Float_t maxSignal     = 0.;
329       Float_t totalSignal   = 0.;
330       Float_t squaredSignal = 0.;
331       Float_t rms = 0.; 
332       
333       //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
334       
335       //fHistSignal->Reset();
336       //Int_t time = pDigitReader->GetTime();
337      
338       for(Int_t i=0;i<pDigitReader->GetBunchSize();i++){
339           
340           if((Float_t)(bunchData[i])>maxSignal){ maxSignal = (Float_t)(bunchData[i]); }
341           totalSignal += (Float_t)bunchData[i];
342           squaredSignal += (Float_t)bunchData[i]*(Float_t)bunchData[i];
343           //fHistSignal->Fill(time+i, bunchData[i]);
344       } // end for loop over bunches
345       rms = TMath::Sqrt(squaredSignal/pDigitReader->GetBunchSize());
346             
347       //} // end of inner while loop
348            
349       fHistMaxSignal->Fill(xyz[0],xyz[1],maxSignal);
350       fHistTotSignal->Fill(xyz[0],xyz[1],totalSignal);
351             
352       fHistPadRMS->Fill(xyz[0],xyz[1],rms);
353      
354       //fHistPadRMS->Fill(xyz[0],xyz[1],fHistSignal->GetRMS());
355       //delete fHistSignal; fHistSignal = NULL;
356             
357       if(fPlotSideA || fPlotSideC){
358          if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
359          else         fHistSideC->Fill(xyz[0],xyz[1],maxSignal);                             
360       } // end if plotting sides    
361      } // end of while loop over pads
362    
363      pDigitReader->Reset();
364      delete pDigitReader;
365   } // end of for loop over data blocks
366  
367   if(fResetHistograms) ResetHistograms();
368   MakeHistosPublic();
369
370   return 0;
371 } // end DoEvent()
372
373
374 void AliHLTTPCNoiseMapComponent::MakeHistosPublic() {
375 // see header file for class documentation
376  
377 //   TFile *outputfile = new TFile("test.root","RECREATE");
378 //   fHistSignal->Write();
379 //   outputfile->Save();
380 //   outputfile->Close();
381
382   TObjArray histos;
383   histos.Add(fHistMaxSignal);
384   histos.Add(fHistTotSignal);
385   histos.Add(fHistPadRMS);
386   histos.Add(fHistCDBMap);
387   //histos.Add(fHistSignal);
388   if(fPlotSideA) histos.Add(fHistSideA);
389   if(fPlotSideC) histos.Add(fHistSideC);
390   
391   TIter iterator(&histos);
392   while(TObject *pObj=iterator.Next()){ PushBack(pObj, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC, fSpecification); }
393     
394   //PushBack( (TObject*) &histos, kAliHLTDataTypeHistogram, fSpecification);    
395  
396 //   if(fHistMaxSignal) delete fHistMaxSignal; fHistMaxSignal = NULL;
397 //   if(fHistTotSignal) delete fHistTotSignal; fHistTotSignal = NULL;
398 //   if(fHistPadRMS)    delete fHistPadRMS;    fHistPadRMS    = NULL;
399 //   if(fHistSideA)     delete fHistSideA;     fHistSideA     = NULL;
400 //   if(fHistSideC)     delete fHistSideC;     fHistSideC     = NULL;
401   
402 }
403
404 void AliHLTTPCNoiseMapComponent::ResetHistograms(){
405 // see header file for class documentation
406
407   //if(fHistPartition) fHistPartition->Reset();  
408   if(fHistMaxSignal) fHistMaxSignal->Reset();
409   if(fHistTotSignal) fHistTotSignal->Reset();
410   if(fHistPadRMS)    fHistPadRMS->Reset();
411
412   if(fHistSideA) fHistSideA->Reset();
413   if(fHistSideC) fHistSideC->Reset();
414 }
415
416 int AliHLTTPCNoiseMapComponent::Configure(const char* arguments) { 
417 // see header file for class documentation
418   
419   int iResult=0;
420   if (!arguments) return iResult;
421   HLTInfo("parsing configuration string \'%s\'", arguments);
422
423   TString allArgs=arguments;
424   TString argument;
425   int bMissingParam=0;
426
427   TObjArray* pTokens=allArgs.Tokenize(" ");
428   if (pTokens) {
429     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
430       argument=((TObjString*)pTokens->At(i))->GetString();
431       if (argument.IsNull()) continue;
432      
433       if (argument.CompareTo("-apply-noisemap")==0) {
434         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
435         HLTInfo("got \'-apply-noisemap\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
436         
437       } 
438       else if (argument.CompareTo("-plot-side-c")==0) {
439         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
440         HLTInfo("got \'-plot-side-c\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
441         
442       } 
443       else if (argument.CompareTo("-plot-side-a")==0) {
444         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
445         HLTInfo("got \'-plot-side-a\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
446         
447       }       
448       else if(argument.CompareTo("-reset-histograms")==0){
449         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
450         HLTInfo("got \'-reset-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
451         
452       } 
453       else {
454         HLTError("unknown argument %s", argument.Data());
455         iResult=-EINVAL;
456         break;
457       }
458     } // end for
459   
460     delete pTokens;
461   
462   } // end if pTokens
463   
464   if (bMissingParam) {
465     HLTError("missing parameter for argument %s", argument.Data());
466     iResult=-EINVAL;
467   }
468   return iResult;  
469 }
470
471 int AliHLTTPCNoiseMapComponent::Reconfigure(const char* cdbEntry, const char* chainId) { 
472 // see header file for class documentation
473   int iResult=0;
474   const char* path="HLT/ConfigTPC/TPCNoiseMapComponent";
475   const char* defaultNotify="";
476   if(cdbEntry){
477       path          = cdbEntry;
478       defaultNotify = "(manual operator entry)";
479   }
480   
481   if(path){          
482      HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>" );
483      
484      AliCDBPath argumentPath(path);
485      AliCDBStorage *stor = AliCDBManager::Instance()->GetDefaultStorage();
486         
487      if(stor){
488         Int_t version    = stor->GetLatestVersion(path, GetRunNo());
489         Int_t subVersion = stor->GetLatestSubVersion(path, GetRunNo(), version);
490         AliCDBEntry *pEntry = stor->Get(argumentPath,GetRunNo(), version, subVersion);
491
492         if(pEntry){
493             TObjString* pString = dynamic_cast<TObjString*>(pEntry->GetObject());
494             if(pString){
495                HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
496                iResult = Configure(pString->GetString().Data());
497             } // if pString is valid
498             else {
499                HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
500             }
501         } // if pEntry is valid
502         else {
503            HLTError("cannot fetch object \"%s\" from CDB", path);
504         }
505      } // if stor is valid
506   } // if path is valid
507   
508   return iResult;
509
510
511 }