]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TPCLib/AliHLTTPCNoiseMapComponent.cxx
correcting compilation warning and making change of AliShuttleInterface (rev 29388)
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCNoiseMapComponent.cxx
CommitLineData
6d17f6d5 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//**************************************************************************
c12197a2 18
19/** @file AliHLTTPCNoiseMapComponent.cxx
20 @author Kalliopi Kanaki
21 @date
22 @brief The TPC Noise Map component
23*/
24
c12197a2 25#if __GNUC__>= 3
26using namespace std;
27#endif
21f63108 28
c12197a2 29#include "AliHLTTPCNoiseMapComponent.h"
30#include "AliHLTTPCDigitReaderDecoder.h"
3a3550fa 31//#include "AliHLTTPCDigitReaderPacked.h"
c12197a2 32#include "AliHLTTPCTransform.h"
33#include "AliHLTTPCDefinitions.h"
21f63108 34
c12197a2 35#include "AliCDBEntry.h"
36#include "AliCDBManager.h"
b1d702f1 37#include "AliCDBStorage.h"
3a3550fa 38#include "AliHLTTPCNoiseMap.h"
21f63108 39
deeb9f12 40#include "AliTPCCalPad.h"
21f63108 41#include "AliTPCROC.h"
42#include "AliTPCCalROC.h"
43
c12197a2 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>
6d17f6d5 51#include "TH2.h"
163d018f 52#include "TH3.h"
c12197a2 53
c12197a2 54ClassImp(AliHLTTPCNoiseMapComponent) //ROOT macro for the implementation of ROOT specific class methods
55
56AliHLTTPCNoiseMapComponent::AliHLTTPCNoiseMapComponent()
6d17f6d5 57 :
deeb9f12 58 fSpecification(0),
deeb9f12 59 fPlotSideA(0),
60 fPlotSideC(0),
61 fApplyNoiseMap(0),
21f63108 62 fResetHistograms(0),
deeb9f12 63 fIsPacked(0),
6d17f6d5 64 fIsUnpacked(0),
21f63108 65 fCurrentSlice(-99),
66 fCurrentPartition(-99),
67 fCurrentRow(-99),
3a3550fa 68 fHistSignal(NULL),
69 fHistMaxSignal(NULL),
70 fHistTotSignal(NULL),
71 fHistPadRMS(NULL),
72 fHistCDBMap(NULL),
deeb9f12 73 fHistSideA(NULL),
3a3550fa 74 fHistSideC(NULL)
c12197a2 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
6d17f6d5 83AliHLTTPCNoiseMapComponent::~AliHLTTPCNoiseMapComponent() {
84// see header file for class documentation
c12197a2 85
86}
87
c12197a2 88// Public functions to implement AliHLTComponent's interface.
89// These functions are required for the registration process
90
6d17f6d5 91const char* AliHLTTPCNoiseMapComponent::GetComponentID() {
92// see header file for class documentation
c12197a2 93
94 return "TPCNoiseMap";
95}
96
6d17f6d5 97void AliHLTTPCNoiseMapComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
98// see header file for class documentation
c12197a2 99
100 list.clear();
101 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginTPC );
102}
103
6d17f6d5 104AliHLTComponentDataType AliHLTTPCNoiseMapComponent::GetOutputDataType() {
105// see header file for class documentation
c12197a2 106
deeb9f12 107 return kAliHLTDataTypeHistogram;
c12197a2 108}
109
6d17f6d5 110int AliHLTTPCNoiseMapComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList) {
111// see header file for class documentation
c12197a2 112
113 tgtList.clear();
deeb9f12 114 tgtList.push_back(kAliHLTDataTypeHistogram);
c12197a2 115 return tgtList.size();
116}
117
6d17f6d5 118void AliHLTTPCNoiseMapComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
119// see header file for class documentation
c12197a2 120
0e588049 121 constBase=800000;
122 inputMultiplier=0.0;
c12197a2 123}
124
6d17f6d5 125AliHLTComponent* AliHLTTPCNoiseMapComponent::Spawn() {
126// see header file for class documentation
c12197a2 127
128 return new AliHLTTPCNoiseMapComponent();
129}
130
6d17f6d5 131int AliHLTTPCNoiseMapComponent::DoInit( int argc, const char** argv ) {
132// see header file for class documentation
21f63108 133
c12197a2 134 Int_t i = 0;
135 Char_t* cpErr;
136
137 int iResult=0;
138
139 TString configuration="";
140 TString argument="";
0e588049 141 for (int j=0; j<argc && iResult>=0; j++) {
c12197a2 142
0e588049 143 argument=argv[j];
c12197a2 144 if (!configuration.IsNull()) configuration+=" ";
21f63108 145 configuration+=argument;
c12197a2 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 ) {
deeb9f12 156 if (!strcmp( argv[i], "-apply-noisemap")) {
157 fApplyNoiseMap = strtoul( argv[i+1], &cpErr ,0);
21f63108 158
deeb9f12 159 if ( *cpErr ) {
160 HLTError("Cannot convert apply-noisemap specifier '%s'.", argv[i+1]);
161 return EINVAL;
162 }
163 i+=2;
164 continue;
165 }
c12197a2 166
deeb9f12 167 if (!strcmp( argv[i], "-plot-side-a")) {
168 fPlotSideA = strtoul( argv[i+1], &cpErr ,0);
21f63108 169
c12197a2 170 if ( *cpErr ) {
deeb9f12 171 HLTError("Cannot convert plot-side-a specifier '%s'.", argv[i+1]);
c12197a2 172 return EINVAL;
173 }
174 i+=2;
175 continue;
176 }
deeb9f12 177
178 if (!strcmp( argv[i], "-plot-side-c")) {
179 fPlotSideC = strtoul( argv[i+1], &cpErr ,0);
deeb9f12 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 }
21f63108 188
189 if (!strcmp( argv[i], "-reset-histograms")) {
190 fResetHistograms = strtoul( argv[i+1], &cpErr ,0);
deeb9f12 191
21f63108 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
c12197a2 200 Logging(kHLTLogError, "HLT::TPCNoiseMap::DoInit", "Unknown Option", "Unknown option '%s'", argv[i] );
201 return EINVAL;
202
deeb9f12 203 } // end while
c12197a2 204
3a3550fa 205 if(fApplyNoiseMap){
206 AliHLTTPCNoiseMap *nm = AliHLTTPCNoiseMap::Instance();
b1d702f1 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 }
3a3550fa 217 }
c12197a2 218
21f63108 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
b1d702f1 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);
163d018f 240 //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
21f63108 241
242// HLTDebug("using AliHLTTPCDigitReaderDecoder");
243// pDigitReader = new AliHLTTPCDigitReaderDecoder(); // double-loop
244// pDigitReader = new AliHLTTPCDigitReaderPacked();
245
c12197a2 246 return 0;
21f63108 247
c12197a2 248} // end DoInit()
249
6d17f6d5 250int AliHLTTPCNoiseMapComponent::DoDeinit() {
b1d702f1 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;
c12197a2 260}
261
0e588049 262int AliHLTTPCNoiseMapComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/){
6d17f6d5 263// see header file for class documentation
c12197a2 264
b1d702f1 265 //HLTInfo("--- Entering DoEvent() in TPCNoiseMap ---");
21f63108 266
deeb9f12 267 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
b1d702f1 268
21f63108 269 const AliHLTComponentBlockData *iter = NULL;
270
c12197a2 271 Float_t xyz[3];
272 Int_t thissector, thisrow;
163d018f 273
21f63108 274 for(iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw|kAliHLTDataOriginTPC); iter != NULL; iter = GetNextInputBlock()){
275
deeb9f12 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;
c12197a2 288
deeb9f12 289 UInt_t slice = AliHLTTPCDefinitions::GetMinSliceNr(*iter);
290 UInt_t partition = AliHLTTPCDefinitions::GetMinPatchNr(*iter);
deeb9f12 291
deeb9f12 292 fSpecification = iter->fSpecification;
293
294 AliHLTTPCDigitReader *pDigitReader = new AliHLTTPCDigitReaderDecoder;
295
296 pDigitReader->InitBlock(iter->fPtr,iter->fSize,partition,slice);
21f63108 297 if(!pDigitReader) break;
298
2fdb1ae7 299 //sprintf(name,"hMaxSignal_slice%d_partition%d", slice, partition);
3a3550fa 300 //fHistMaxSignal = new TH2F(name,name,250,-250,250,250,-250,250);
21f63108 301
3a3550fa 302 while(pDigitReader->Next()){
deeb9f12 303 //while( pDigitReader->NextChannel()) { // pad loop
c12197a2 304
deeb9f12 305 fCurrentRow = pDigitReader->GetRow();
306 fCurrentRow += pDigitReader->GetRowOffset();
6d17f6d5 307
deeb9f12 308 AliHLTTPCTransform::Slice2Sector(slice,fCurrentRow,thissector,thisrow);
3a3550fa 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
21f63108 318 //AliHLTTPCTransform::Raw2Global(xyz,thissector,thisrow,pDigitReader->GetPad(),0);
3a3550fa 319 // transformation from pad-row coordinates to global ones
320 // time info is not taken into account
21f63108 321
322// AliTPCCalROC *calRoc = noisePad->GetCalROC(thissector);
323// calRoc->GetValue(thisrow,pDigitReader->GetPad());
324
deeb9f12 325 //while( pDigitReader->NextBunch()) {
326
21f63108 327 const UInt_t *bunchData = pDigitReader->GetSignals();
163d018f 328 Float_t maxSignal = 0.;
329 Float_t totalSignal = 0.;
330 Float_t squaredSignal = 0.;
331 Float_t rms = 0.;
3a3550fa 332
163d018f 333 //fHistSignal = new TH1F("fHistSignal", "signal distribution per pad",1024,0,1024);
334
335 //fHistSignal->Reset();
4646c6e3 336 //Int_t time = pDigitReader->GetTime();
163d018f 337
3a3550fa 338 for(Int_t i=0;i<pDigitReader->GetBunchSize();i++){
deeb9f12 339
3a3550fa 340 if((Float_t)(bunchData[i])>maxSignal){ maxSignal = (Float_t)(bunchData[i]); }
163d018f 341 totalSignal += (Float_t)bunchData[i];
342 squaredSignal += (Float_t)bunchData[i]*(Float_t)bunchData[i];
343 //fHistSignal->Fill(time+i, bunchData[i]);
3a3550fa 344 } // end for loop over bunches
163d018f 345 rms = TMath::Sqrt(squaredSignal/pDigitReader->GetBunchSize());
346
deeb9f12 347 //} // end of inner while loop
21f63108 348
3a3550fa 349 fHistMaxSignal->Fill(xyz[0],xyz[1],maxSignal);
350 fHistTotSignal->Fill(xyz[0],xyz[1],totalSignal);
163d018f 351
352 fHistPadRMS->Fill(xyz[0],xyz[1],rms);
353
354 //fHistPadRMS->Fill(xyz[0],xyz[1],fHistSignal->GetRMS());
355 //delete fHistSignal; fHistSignal = NULL;
55f2c86a 356
21f63108 357 if(fPlotSideA || fPlotSideC){
358 if(slice<18) fHistSideA->Fill(xyz[0],xyz[1],maxSignal);
359 else fHistSideC->Fill(xyz[0],xyz[1],maxSignal);
55f2c86a 360 } // end if plotting sides
3a3550fa 361 } // end of while loop over pads
55f2c86a 362
5863c71a 363 pDigitReader->Reset();
2fdb1ae7 364 delete pDigitReader;
deeb9f12 365 } // end of for loop over data blocks
c12197a2 366
21f63108 367 if(fResetHistograms) ResetHistograms();
deeb9f12 368 MakeHistosPublic();
3a3550fa 369
deeb9f12 370 return 0;
c12197a2 371} // end DoEvent()
372
3a3550fa 373
deeb9f12 374void AliHLTTPCNoiseMapComponent::MakeHistosPublic() {
6d17f6d5 375// see header file for class documentation
b1d702f1 376
deeb9f12 377// TFile *outputfile = new TFile("test.root","RECREATE");
55f2c86a 378// fHistSignal->Write();
deeb9f12 379// outputfile->Save();
380// outputfile->Close();
3a3550fa 381
deeb9f12 382 TObjArray histos;
3a3550fa 383 histos.Add(fHistMaxSignal);
384 histos.Add(fHistTotSignal);
385 histos.Add(fHistPadRMS);
386 histos.Add(fHistCDBMap);
163d018f 387 //histos.Add(fHistSignal);
21f63108 388 if(fPlotSideA) histos.Add(fHistSideA);
389 if(fPlotSideC) histos.Add(fHistSideC);
21f63108 390
391 TIter iterator(&histos);
3a3550fa 392 while(TObject *pObj=iterator.Next()){ PushBack(pObj, kAliHLTDataTypeHistogram|kAliHLTDataOriginTPC, fSpecification); }
21f63108 393
394 //PushBack( (TObject*) &histos, kAliHLTDataTypeHistogram, fSpecification);
395
b1d702f1 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;
3a3550fa 401
c12197a2 402}
403
21f63108 404void AliHLTTPCNoiseMapComponent::ResetHistograms(){
405// see header file for class documentation
406
3a3550fa 407 //if(fHistPartition) fHistPartition->Reset();
408 if(fHistMaxSignal) fHistMaxSignal->Reset();
409 if(fHistTotSignal) fHistTotSignal->Reset();
410 if(fHistPadRMS) fHistPadRMS->Reset();
411
2fdb1ae7 412 if(fHistSideA) fHistSideA->Reset();
413 if(fHistSideC) fHistSideC->Reset();
21f63108 414}
415
6d17f6d5 416int AliHLTTPCNoiseMapComponent::Configure(const char* arguments) {
417// see header file for class documentation
c12197a2 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
deeb9f12 433 if (argument.CompareTo("-apply-noisemap")==0) {
c12197a2 434 if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
deeb9f12 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());
c12197a2 446
3a3550fa 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
c12197a2 452 }
453 else {
454 HLTError("unknown argument %s", argument.Data());
455 iResult=-EINVAL;
456 break;
457 }
deeb9f12 458 } // end for
459
c12197a2 460 delete pTokens;
deeb9f12 461
462 } // end if pTokens
463
c12197a2 464 if (bMissingParam) {
465 HLTError("missing parameter for argument %s", argument.Data());
466 iResult=-EINVAL;
467 }
21f63108 468 return iResult;
c12197a2 469}
470
6d17f6d5 471int AliHLTTPCNoiseMapComponent::Reconfigure(const char* cdbEntry, const char* chainId) {
472// see header file for class documentation
c12197a2 473 int iResult=0;
474 const char* path="HLT/ConfigTPC/TPCNoiseMapComponent";
475 const char* defaultNotify="";
b1d702f1 476 if(cdbEntry){
477 path = cdbEntry;
478 defaultNotify = "(manual operator entry)";
c12197a2 479 }
deeb9f12 480
b1d702f1 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
c12197a2 507
508 return iResult;
b1d702f1 509
510
c12197a2 511}