]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/AliHLTTPCNoiseMapComponent.cxx
added 'backwards' mapping: row/pad to channel; code cleanup
[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 <cstdlib>
36 #include <cerrno>
37 #include "TString.h"
38 #include "TFile.h"
39 #include "TObjArray.h"
40 #include "TObjString.h"
41 #include <sys/time.h>
42 #include "TH2.h"
43
44
45 AliHLTTPCNoiseMapComponent gAliHLTTPCNoiseMapComponent;
46
47 ClassImp(AliHLTTPCNoiseMapComponent) //ROOT macro for the implementation of ROOT specific class methods
48
49 AliHLTTPCNoiseMapComponent::AliHLTTPCNoiseMapComponent()
50     :    
51     fNoiseMap(0),
52     fIsPacked(1),
53     fIsUnpacked(0),
54     fCurrentPartition(0),
55     fCurrentRow(0)   
56 {
57   // see header file for class documentation
58   // or
59   // refer to README to build package
60   // or
61   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62 }
63
64 AliHLTTPCNoiseMapComponent::~AliHLTTPCNoiseMapComponent() { 
65 // see header file for class documentation
66
67 }
68
69 // Public functions to implement AliHLTComponent's interface.
70 // These functions are required for the registration process
71
72 const char* AliHLTTPCNoiseMapComponent::GetComponentID() { 
73 // see header file for class documentation
74
75   return "TPCNoiseMap";
76 }
77
78 void AliHLTTPCNoiseMapComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
79 // see header file for class documentation
80
81   list.clear(); 
82   list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
83 }
84
85 AliHLTComponentDataType AliHLTTPCNoiseMapComponent::GetOutputDataType() { 
86 // see header file for class documentation
87
88   return AliHLTTPCDefinitions::fgkNoiseHistoDataType;
89 }
90
91 int AliHLTTPCNoiseMapComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) { 
92 // see header file for class documentation
93
94   tgtList.clear();
95   tgtList.push_back(AliHLTTPCDefinitions::fgkNoiseHistoDataType);
96   return tgtList.size();
97 }
98
99 void AliHLTTPCNoiseMapComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
100 // see header file for class documentation
101
102   constBase=0;
103   inputMultiplier=1.0;
104 }
105
106 AliHLTComponent* AliHLTTPCNoiseMapComponent::Spawn() { 
107 // see header file for class documentation
108
109   return new AliHLTTPCNoiseMapComponent();
110 }
111         
112 int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) { 
113 // see header file for class documentation
114
115   Int_t i = 0;
116   Char_t* cpErr;
117   
118   int iResult=0;
119   
120   TString configuration="";
121   TString argument="";
122   for (int i=0; i<argc && iResult>=0; i++) {
123     
124     argument=argv[i];
125     if (!configuration.IsNull()) configuration+=" ";
126     configuration+=argument;
127     
128   }
129    
130   if (!configuration.IsNull()) {
131     iResult=Configure(configuration.Data());
132   } else {
133     iResult=Reconfigure(NULL, NULL);
134   }
135
136  
137   while ( i < argc ) {      
138     
139    
140     // -- fill noise histograms
141     if (!strcmp( argv[i], "-noisemap")) {
142         fNoiseMap = strtoul( argv[i+1], &cpErr ,0);
143       
144     //if(fNoiseMap) {
145       
146        fHistSideC = new TH2F("fHistSideC","",500,-250,250,500,-250,250);    
147        HLTInfo("---- HAVE CREATED HISTOGRAM(S) ----");
148        //fSideA, fSideC, fSliceA[18], fSliceC[18]
149     
150     //}
151     if ( *cpErr ) {
152         HLTError("Cannot convert noisemap specifier '%s'.", argv[i+1]);
153         return EINVAL;
154     }
155       i+=2;
156       continue;
157     }
158         
159     Logging(kHLTLogError, "HLT::TPCNoiseMap::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
160     return EINVAL;
161
162   }
163
164   //HLTDebug("using AliHLTTPCDigitReaderDecoder");
165   //pDigitReader = new AliHLTTPCDigitReaderDecoder(); // double-loop
166   //pDigitReader = new AliHLTTPCDigitReaderPacked();
167   
168 //   if(fIsPacked){
169 //     //cout<<"Digit reader decoder is chosen"<<endl;
170 //     fDigitReader = new AliHLTTPCDigitReaderDecoder();
171 //   }
172 //   else if(fIsUnpacked){
173 //     //cout<<"Digit reader unpacked is chosen"<<endl;
174 //     fDigitReader = new AliHLTTPCDigitReaderDecoderUnpacked();
175 //   }
176 //   else{
177 //     HLTFatal("Neither of the two options of digit readers is set no data will be read.");
178 //   }
179
180
181   return 0;
182 } // end DoInit()
183
184 int AliHLTTPCNoiseMapComponent::DoDeinit() { 
185 // see header file for class documentation 
186       
187     return 0;
188 }
189
190 int AliHLTTPCNoiseMapComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
191                                               AliHLTComponentTriggerData&, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, 
192                                               vector<AliHLTComponentBlockData>& outputBlocks ) { 
193 // see header file for class documentation
194  if(fNoiseMap) { 
195  
196   HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
197
198   //  == init iter (pointer to datablock)
199   const AliHLTComponentBlockData* iter = NULL;
200   unsigned long ndx;
201   
202   Float_t xyz[3]; 
203   Int_t thissector, thisrow;
204   
205
206   for ( ndx=0; ndx<evtData.fBlockCnt; ndx++ ) {
207       iter = blocks+ndx;
208       
209       HLTInfo("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s", evtData.fEventID, evtData.fEventID, 
210                DataType2Text( iter->fDataType).c_str(), DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
211
212       if (iter->fDataType == AliHLTTPCDefinitions::fgkDDLPackedRawDataType && GetEventCount()<2) {
213           HLTWarning("data type %s is depricated, use %s (kAliHLTDataTypeDDLRaw)!", DataType2Text(AliHLTTPCDefinitions::fgkDDLPackedRawDataType).c_str(),
214                       DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC).c_str());
215       } //endif      
216       
217       if (iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC)) continue;
218   
219      
220       UInt_t slice     = AliHLTTPCDefinitions::GetMinSliceNr( *iter ); 
221       UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
222           
223       //if ( partition < fMinPartition ) fMinPartition = partition;
224       //if ( partition > fMaxPartition ) fMaxPartition = partition; // add a warning
225       
226       //fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( slice, slice, partition, partition );
227       fSpecification = iter->fSpecification;
228       
229       AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
230       pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
231       if(!pDigitReader) break; //AliHLTComponent.cxx, altrochannelselector rcu folder
232             
233       rowOffset = 0;      
234       
235       switch(partition){
236       case 0:
237         rowOffset=AliHLTTPCTransform::GetFirstRow(0);
238         break;
239       case 1:
240         rowOffset=AliHLTTPCTransform::GetFirstRow(1);
241         break;
242       case 2:
243         rowOffset=AliHLTTPCTransform::GetFirstRow(2);
244         break;
245       case 3:
246         rowOffset=AliHLTTPCTransform::GetFirstRow(3);
247         break;
248       case 4:
249         rowOffset=AliHLTTPCTransform::GetFirstRow(4);
250         break;
251       case 5:
252         rowOffset=AliHLTTPCTransform::GetFirstRow(5);
253         break;
254       }
255                 
256       
257         //while( pDigitReader->Next() ){ 
258         while( pDigitReader->NextChannel()) { 
259          
260          fCurrentRow  = pDigitReader->GetRow();  
261          fCurrentRow += rowOffset;
262         
263          if(pDigitReader->GetPad()==1000 || fCurrentRow==1000) continue;
264
265          AliHLTTPCTransform::Slice2Sector(slice,fCurrentRow,thissector,thisrow);
266          AliHLTTPCTransform::Raw2Global(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
267          //AliHLTTPCTransform::Raw2Local(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
268                  
269          //use AliTPCPad to fill the data there and use the functions to ask for max charge etc.
270
271          Int_t  maxSignal = 0;
272          while( pDigitReader->NextBunch()) {
273      
274              //in case we want to fill the histograms with the signal value, an additional loop is necessary                                          
275              for(Int_t i=0;i<pDigitReader->GetBunchSize();i++) {
276                 
277                  const UInt_t *bunchData = pDigitReader->GetSignals();
278                  if(bunchData[i]>maxSignal) maxSignal = bunchData[i]; 
279                  //cout<<"Time: "<<pDigitReader->GetTime()+i<<"    Signal: "<<bunchData[i]<<endl;
280              }                                             
281          } // end of inner while loop
282
283 cout<<slice<<" "<<partition<<" "<<fCurrentRow<<" "<<pDigitReader->GetPad()<<" "<<xyz[0]<<" "<<xyz[1]<<" "<<maxSignal<<endl;
284           
285           fHistSideC->Fill(xyz[0],xyz[1],maxSignal);
286       
287         } // end of outer while pad loop
288   } // end of data block loop 
289  
290   SaveAndResetHistograms();
291  
292  } // end if noisemap==kTRUE  
293  return 0;
294 } // end DoEvent()
295
296 void AliHLTTPCNoiseMapComponent::SaveAndResetHistograms() {
297 // see header file for class documentation
298   
299   TFile *outputfile = new TFile("test.root","RECREATE");
300   fHistSideC->Write();
301   outputfile->Save();
302   outputfile->Close();
303    
304   PushBack( (TObject*) fHistSideC, AliHLTTPCDefinitions::fgkNoiseHistoDataType, fSpecification);
305   //fill it with the right specification for every histogram
306   //make a TObjArray and add all histos
307   //check which pointers are empty and publish only the ones that hold something
308     
309   delete fHistSideC;
310 }
311
312 int AliHLTTPCNoiseMapComponent::Configure(const char* arguments) { 
313 // see header file for class documentation
314   
315   int iResult=0;
316   if (!arguments) return iResult;
317   HLTInfo("parsing configuration string \'%s\'", arguments);
318
319   TString allArgs=arguments;
320   TString argument;
321   int bMissingParam=0;
322
323   TObjArray* pTokens=allArgs.Tokenize(" ");
324   if (pTokens) {
325     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
326       argument=((TObjString*)pTokens->At(i))->GetString();
327       if (argument.IsNull()) continue;
328      
329       if (argument.CompareTo("-noisemap")==0) {
330         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
331         HLTInfo("got \'-noisemap\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
332         
333       } 
334       else {
335         HLTError("unknown argument %s", argument.Data());
336         iResult=-EINVAL;
337         break;
338       }
339     } // endfor
340     delete pTokens;
341   }
342   if (bMissingParam) {
343     HLTError("missing parameter for argument %s", argument.Data());
344     iResult=-EINVAL;
345   }
346   return iResult;
347
348 }
349
350 int AliHLTTPCNoiseMapComponent::Reconfigure(const char* cdbEntry, const char* chainId) { 
351 // see header file for class documentation
352
353   int iResult=0;
354   const char* path="HLT/ConfigTPC/TPCNoiseMapComponent";
355   const char* defaultNotify="";
356   if (cdbEntry) {
357     path=cdbEntry;
358     defaultNotify=" (default)";
359   }
360   if (path) {
361     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
362     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
363     if (pEntry) {
364       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
365       if (pString) {
366         HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
367         iResult=Configure(pString->GetString().Data());
368       } else {
369         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
370       }
371     } else {
372       HLTError("can not fetch object \"%s\" from CDB", path);
373     }
374   }
375   
376   return iResult;
377 }