]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCNoiseMapComponent.cxx
TPCNoiseMapComponent included into build (Kelly)
[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 #include "AliHLTTPCNoiseMapComponent.h"
29 #include "AliHLTTPCDigitReaderDecoder.h"
30 #include "AliHLTTPCDigitReaderPacked.h"
31 #include "AliHLTTPCTransform.h"
32 #include "AliHLTTPCDefinitions.h"
33 #include "AliCDBEntry.h"
34 #include "AliCDBManager.h"
35 #include "AliTPCCalPad.h"
36 #include <cstdlib>
37 #include <cerrno>
38 #include "TString.h"
39 #include "TFile.h"
40 #include "TObjArray.h"
41 #include "TObjString.h"
42 #include <sys/time.h>
43 #include "TH2.h"
44
45
46 AliHLTTPCNoiseMapComponent gAliHLTTPCNoiseMapComponent;
47
48 ClassImp(AliHLTTPCNoiseMapComponent) //ROOT macro for the implementation of ROOT specific class methods
49
50 AliHLTTPCNoiseMapComponent::AliHLTTPCNoiseMapComponent()
51     :    
52     fSpecification(0),
53     //pDigitReader(0),
54     fPlotSideA(0),
55     fPlotSideC(0),    
56     fApplyNoiseMap(0),
57     fIsPacked(0),
58     fIsUnpacked(0),
59     fSlice(-99),
60     fCurrentPartition(0),
61     fCurrentRow(0),
62     fHistSideA(NULL),  
63     fHistSideC(NULL),
64     fHistCDBMap(NULL)
65     //fHistSlice(NULL)    
66 {
67   // see header file for class documentation
68   // or
69   // refer to README to build package
70   // or
71   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
72 }
73
74 AliHLTTPCNoiseMapComponent::~AliHLTTPCNoiseMapComponent() { 
75 // see header file for class documentation
76
77 }
78
79 // Public functions to implement AliHLTComponent's interface.
80 // These functions are required for the registration process
81
82 const char* AliHLTTPCNoiseMapComponent::GetComponentID() { 
83 // see header file for class documentation
84
85   return "TPCNoiseMap";
86 }
87
88 void AliHLTTPCNoiseMapComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
89 // see header file for class documentation
90
91   list.clear(); 
92   list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
93 }
94
95 AliHLTComponentDataType AliHLTTPCNoiseMapComponent::GetOutputDataType() { 
96 // see header file for class documentation
97
98   return kAliHLTDataTypeHistogram;
99 }
100
101 int AliHLTTPCNoiseMapComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
102 // see header file for class documentation
103
104   tgtList.clear();
105   tgtList.push_back(kAliHLTDataTypeHistogram);
106   return tgtList.size();
107 }
108
109 void AliHLTTPCNoiseMapComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
110 // see header file for class documentation
111
112   constBase=0;
113   inputMultiplier=1.0;
114 }
115
116 AliHLTComponent* AliHLTTPCNoiseMapComponent::Spawn() { 
117 // see header file for class documentation
118
119   return new AliHLTTPCNoiseMapComponent();
120 }
121         
122 int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) { 
123 // see header file for class documentation
124
125   Int_t i = 0;
126   Char_t* cpErr;
127   
128   int iResult=0;
129   
130   TString configuration="";
131   TString argument="";
132   for (int i=0; i<argc && iResult>=0; i++) {
133     
134     argument=argv[i];
135     if (!configuration.IsNull()) configuration+=" ";
136     configuration+=argument;
137     
138   }
139    
140   if (!configuration.IsNull()) {
141     iResult=Configure(configuration.Data());
142   } else {
143     iResult=Reconfigure(NULL, NULL);
144   }
145
146  
147   while ( i < argc ) {      
148     if (!strcmp( argv[i], "-apply-noisemap")) {
149         fApplyNoiseMap = strtoul( argv[i+1], &cpErr ,0);
150                             
151     if ( *cpErr ) {
152         HLTError("Cannot convert apply-noisemap specifier '%s'.", argv[i+1]);
153         return EINVAL;
154     }
155       i+=2;
156       continue;
157     }
158     
159     if (!strcmp( argv[i], "-plot-side-a")) {
160         fPlotSideA = strtoul( argv[i+1], &cpErr ,0);
161         
162         fHistSideA = new TH2F("fHistSideA","TPC Side A",250,-250,250,250,-250,250);           
163         fHistSideA->SetXTitle("global X (cm)"); fHistSideA->SetYTitle("global Y (cm)");
164     
165     if ( *cpErr ) {
166         HLTError("Cannot convert plot-side-a specifier '%s'.", argv[i+1]);
167         return EINVAL;
168     }
169       i+=2;
170       continue;
171     }
172     
173     if (!strcmp( argv[i], "-plot-side-c")) {
174         fPlotSideC = strtoul( argv[i+1], &cpErr ,0);
175         
176         fHistSideC = new TH2F("fHistSideC","TPC Side C",250,-250,250,250,-250,250);
177         fHistSideC->SetXTitle("global X (cm)"); fHistSideC->SetYTitle("global Y (cm)");
178                 
179         //fSliceA[18], fSliceC[18]
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], "-slice")) {
190 //         fSlice = strtoul( argv[i+1], &cpErr ,0);
191 //            
192 //     if ( *cpErr ) {
193 //         HLTError("Cannot convert slice specifier '%s'. Must be integer", 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   //HLTDebug("using AliHLTTPCDigitReaderDecoder");
206   //pDigitReader = new AliHLTTPCDigitReaderDecoder(); // double-loop
207   //pDigitReader = new AliHLTTPCDigitReaderPacked();
208   
209 //   if(fIsPacked){
210 //     //cout<<"Digit reader decoder is chosen"<<endl;
211 //     fDigitReader = new AliHLTTPCDigitReaderDecoder();
212 //   }
213 //   else if(fIsUnpacked){
214 //     //cout<<"Digit reader unpacked is chosen"<<endl;
215 //     fDigitReader = new AliHLTTPCDigitReaderDecoderUnpacked();
216 //   }
217 //   else{
218 //     HLTFatal("Neither of the two options of digit readers is set no data will be read.");
219 //   }
220
221
222   return 0;
223 } // end DoInit()
224
225 int AliHLTTPCNoiseMapComponent::DoDeinit() { 
226 // see header file for class documentation 
227       
228     return 0;
229 }
230
231 // int AliHLTTPCNoiseMapComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
232 //                                            AliHLTComponentTriggerData&, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, 
233 //                                            vector<AliHLTComponentBlockData>& outputBlocks ) { 
234
235
236 int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData){
237 // see header file for class documentation
238  
239   HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
240   
241   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
242   
243   const AliHLTComponentBlockData* iter = NULL;
244   //unsigned long ndx;
245   
246   Float_t xyz[3]; 
247   Int_t thissector, thisrow;
248   
249   // reading an existing noise map file
250   if(fApplyNoiseMap){
251      TFile *f = TFile::Open("Run3398_4000_v0_s72.root");
252      AliCDBEntry *entry = (AliCDBEntry*)f->Get("AliCDBEntry"); 
253      AliTPCCalPad *noisePad = (AliTPCCalPad*)entry->GetObject();
254      fHistCDBMap = noisePad->MakeHisto2D(1); //side C
255   }
256
257   for (iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){
258   
259   //for ( ndx=0; ndx<evtData.fBlockCnt; ndx++ ) {
260   //  iter = blocks+ndx;
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 slice     = AliHLTTPCDefinitions::GetMinSliceNr(*iter); 
276      UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
277          
278      //if ( partition < fMinPartition ) fMinPartition = partition;
279      //if ( partition > fMaxPartition ) fMaxPartition = partition; // add a warning
280      
281      //fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, partition, partition );
282      fSpecification = iter->fSpecification;
283      
284      AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
285
286      pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
287      if(!pDigitReader) break; //AliHLTComponent.cxx, altrochannelselector rcu folder
288                        
289      while( pDigitReader->Next() ){ 
290      //while( pDigitReader->NextChannel()) { // pad loop 
291       
292       fCurrentRow  = pDigitReader->GetRow();  
293       fCurrentRow += pDigitReader->GetRowOffset();
294
295       AliHLTTPCTransform::Slice2Sector(slice,fCurrentRow,thissector,thisrow);
296       AliHLTTPCTransform::Raw2Global(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
297               
298       //use AliTPCPad to fill the data there and use the functions to ask for max charge etc.
299
300       Int_t  maxSignal = 0;
301       //while( pDigitReader->NextBunch()) {
302     
303       //in case we want to fill the histograms with the signal value, an additional loop is necessary                                      
304       for(Int_t i=0;i<pDigitReader->GetBunchSize();i++) {
305           
306           const UInt_t *bunchData = pDigitReader->GetSignals();
307           if(bunchData[i]>maxSignal) maxSignal = bunchData[i]; 
308           
309           //cout<<"Time: "<<pDigitReader->GetTime()+i<<"    Signal: "<<bunchData[i]<<endl;                                                   
310       }
311       //} // end of inner while loop
312       //cout<<slice<<" "<<partition<<" "<<fCurrentRow<<" "<<pDigitReader->GetPad()<<" "<<xyz[0]<<" "<<xyz[1]<<" "<<maxSignal<<endl;
313
314         if(fPlotSideA || fPlotSideC){
315            if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
316            else         fHistSideC->Fill(xyz[0],xyz[1],maxSignal);                  
317         }    
318           
319       } // end of while loop
320   } // end of for loop over data blocks
321  
322   MakeHistosPublic();
323   return 0;
324 } // end DoEvent()
325
326 void AliHLTTPCNoiseMapComponent::MakeHistosPublic() {
327 // see header file for class documentation
328   
329 //   TFile *outputfile = new TFile("test.root","RECREATE");
330 //   fHistSideC->Write();
331 //   fHistCDBMap->Write();
332 //   fHistSlice[18]->Write();
333 //   outputfile->Save();
334 //   outputfile->Close();
335   
336   TObjArray histos;
337   histos.Add(fHistSideA);
338   histos.Add(fHistSideC);
339   PushBack( (TObject*) &histos, kAliHLTDataTypeHistogram, fSpecification);   
340    
341   //PushBack( (TObject*) fHistSideC, kAliHLTDataTypeHistogram, fSpecification);
342  
343   //fill it with the right specification for every histogram
344   //make a TObjArray and add all histos
345   //check which pointers are empty and publish only the ones that hold something
346   
347   //delete histos;
348   delete fHistSideA; 
349   delete fHistSideC;
350 }
351
352 int AliHLTTPCNoiseMapComponent::Configure(const char* arguments) { 
353 // see header file for class documentation
354   
355   int iResult=0;
356   if (!arguments) return iResult;
357   HLTInfo("parsing configuration string \'%s\'", arguments);
358
359   TString allArgs=arguments;
360   TString argument;
361   int bMissingParam=0;
362
363   TObjArray* pTokens=allArgs.Tokenize(" ");
364   if (pTokens) {
365     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
366       argument=((TObjString*)pTokens->At(i))->GetString();
367       if (argument.IsNull()) continue;
368      
369       if (argument.CompareTo("-apply-noisemap")==0) {
370         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
371         HLTInfo("got \'-apply-noisemap\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
372         
373       } 
374       else if (argument.CompareTo("-plot-side-c")==0) {
375         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
376         HLTInfo("got \'-plot-side-c\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
377         
378       } 
379       else if (argument.CompareTo("-plot-side-a")==0) {
380         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
381         HLTInfo("got \'-plot-side-a\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
382         
383       } 
384       else {
385         HLTError("unknown argument %s", argument.Data());
386         iResult=-EINVAL;
387         break;
388       }
389     } // end for
390   
391     delete pTokens;
392   
393   } // end if pTokens
394   
395   if (bMissingParam) {
396     HLTError("missing parameter for argument %s", argument.Data());
397     iResult=-EINVAL;
398   }
399   return iResult;
400 }
401
402 int AliHLTTPCNoiseMapComponent::Reconfigure(const char* cdbEntry, const char* chainId) { 
403 // see header file for class documentation
404
405   int iResult=0;
406   const char* path="HLT/ConfigTPC/TPCNoiseMapComponent";
407   const char* defaultNotify="";
408   if (cdbEntry) {
409       path=cdbEntry;
410       defaultNotify=" (default)";
411   }
412   
413   if (path) {
414     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
415     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
416     if (pEntry) {
417       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
418       if (pString) {
419         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
420         iResult=Configure(pString->GetString().Data());
421       } else {
422         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
423       }
424     } else {
425       HLTError("cannot fetch object \"%s\" from CDB", path);
426     }
427   }
428   
429   return iResult;
430 }