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