1 /**************************************************************************
2 * This file is property of and copyright by the ALICE HLT Project *
3 * All rights reserved. *
6 * Artur Szostak <artursz@iafrica.com> *
8 * Permission to use, copy, modify and distribute this software and its *
9 * documentation strictly for non-commercial purposes is hereby granted *
10 * without fee, provided that the above copyright notice appears in all *
11 * copies and that both the copyright notice and this permission notice *
12 * appear in the supporting documentation. The authors make no claims *
13 * about the suitability of this software for any purpose. It is *
14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
20 /// @file AliHLTMUONRawDataHistoComponent.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
22 /// @date 30 April 2008
23 /// @brief Implementation of the raw data histogramming component for dHLT.
25 /// The class implements
27 #include "AliHLTMUONRawDataHistoComponent.h"
28 #include "AliHLTMUONConstants.h"
29 #include "AliHLTMUONUtils.h"
30 #include "AliHLTDataTypes.h"
31 #include "AliCDBEntry.h"
32 #include "AliCDBManager.h"
33 #include "AliRawDataHeader.h"
34 #include "TTimeStamp.h"
42 // Helper type for memory allocation.
43 typedef const AliHLTMUONMansoTrackStruct* AliHLTMUONMansoTrackStructP;
46 ClassImp(AliHLTMUONRawDataHistoComponent);
49 AliHLTMUONRawDataHistoComponent::AliHLTMUONRawDataHistoComponent() :
50 AliHLTMUONProcessor(),
54 fCurrentEventTime(-1),
56 fSuppressEmptyHists(false),
57 fProcessDataEventsOnly(false),
58 fClearAfterPublish(false)
60 /// Default constructor initialises all histogram object pointers to NULL.
62 for (int i = 0; i < 22; i++)
66 for (int i = 0; i < 20; i++)
69 fSignalHist[i] = NULL;
72 fTrackerDecoder.ExitOnError(false);
73 fTrackerDecoder.TryRecover(false);
74 fTrackerDecoder.SendDataOnParityError(true);
75 fTrackerDecoder.AutoDetectTrailer(true);
76 fTrackerDecoder.CheckForTrailer(true);
78 fTriggerDecoder.ExitOnError(false);
79 fTriggerDecoder.TryRecover(false);
80 fTriggerDecoder.AutoDetectScalars(false);
84 AliHLTMUONRawDataHistoComponent::~AliHLTMUONRawDataHistoComponent()
86 /// Default destructor deletes all histogram objects if they are still allocated.
91 const char* AliHLTMUONRawDataHistoComponent::GetComponentID()
93 /// Inherited from AliHLTComponent. Returns the component ID.
95 return AliHLTMUONConstants::RawDataHistogrammerId();
99 void AliHLTMUONRawDataHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
101 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
103 assert( list.empty() );
104 list.push_back( AliHLTMUONConstants::DDLRawDataType() );
108 AliHLTComponentDataType AliHLTMUONRawDataHistoComponent::GetOutputDataType()
110 /// Inherited from AliHLTComponent. Returns kAliHLTHistogramDataTypeID.
112 return AliHLTMUONConstants::HistogramDataType();
116 void AliHLTMUONRawDataHistoComponent::GetOutputDataSize(
117 unsigned long& constBase, double& inputMultiplier
120 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
122 constBase = (sizeof(TH1D)+50*sizeof(double))*22 + (sizeof(TH1D)+1024*4*sizeof(double))*20*2;
127 AliHLTComponent* AliHLTMUONRawDataHistoComponent::Spawn()
129 /// Inherited from AliHLTComponent. Creates a new object instance.
131 return new AliHLTMUONRawDataHistoComponent;
135 bool AliHLTMUONRawDataHistoComponent::IgnoreArgument(const char* arg) const
137 /// Return true if the argument is one of -cdbpath -run or -delaysetup
138 /// to prevent the parent class from parsing these arguments in DoInit.
140 if (strcmp(arg, "-cdbpath") == 0 or strcmp(arg, "-run") == 0 or
141 strcmp(arg, "-delaysetup") == 0)
152 int AliHLTMUONRawDataHistoComponent::DoInit(int argc, const char** argv)
154 /// Inherited from AliHLTComponent.
155 /// Parses the command line parameters and initialises the component.
157 HLTInfo("Initialising dHLT raw data histogrammer component.");
159 // Inherit the parents functionality.
160 int result = AliHLTMUONProcessor::DoInit(argc, argv);
161 if (result != 0) return result;
163 fLastPublishTime = fCurrentEventTime = -1;
165 bool pubDelaySet = false;
166 fSuppressEmptyHists = false;
167 fProcessDataEventsOnly = false;
168 fClearAfterPublish = false;
169 fTrackerDecoder.TryRecover(false);
170 fTriggerDecoder.TryRecover(false);
172 for (int i = 0; i < argc; i++)
174 if (ArgumentAlreadyHandled(i, argv[i])) continue;
176 if (strcmp(argv[i], "-pubdelay") == 0)
180 HLTWarning("The publishing delay value was already specified."
181 " Will replace previous value given by -pubdelay."
187 HLTError("The value for the publishing delay was not specified.");
192 double num = strtod(argv[i+1], &cpErr);
193 if (cpErr == NULL or *cpErr != '\0' or num < 0)
195 HLTError("Cannot convert '%s' to a positive floating point number.",
207 if (strcmp(argv[i], "-noemptyhists") == 0)
209 fSuppressEmptyHists = true;
213 if (strcmp(argv[i], "-onlydataevents") == 0)
215 fProcessDataEventsOnly = true;
219 if (strcmp(argv[i], "-clearafterpub") == 0)
221 fClearAfterPublish = true;
225 if (strcmp(argv[i], "-tryrecover") == 0)
227 fTrackerDecoder.TryRecover(true);
228 fTriggerDecoder.TryRecover(true);
232 HLTError("Unknown option '%s'.", argv[i]);
241 // Do not add to current directory to prevent memory leak warning.
242 // We will not be leaking any memory if we dont add to the directory.
243 TH1::AddDirectory(kFALSE);
245 for (int i = 0; i < 22; i++)
247 AliHLTInt32_t equipId = AliHLTMUONUtils::DDLNumberToEquipId(i);
248 sprintf(name, "rawDataErrors_%d", equipId);
249 sprintf(title, "Distribution of errors found in raw data from DDL %d.", equipId);
250 fErrorHist[i] = new TH1D(name, title, 40, 0.5, 40.5);
251 fErrorHist[i]->SetXTitle("Error code");
252 fErrorHist[i]->SetYTitle("Number of errors");
254 for (int i = 0; i < 20; i++)
256 AliHLTInt32_t equipId = AliHLTMUONUtils::DDLNumberToEquipId(i);
257 sprintf(name, "manuDistrib_%d", equipId);
258 sprintf(title, "Distribution of MANUs containing raw data in DDL %d.", equipId);
259 fManuHist[i] = new TH1D(name, title, 2048, -0.5, 2047.5);
260 fManuHist[i]->SetXTitle("MANU number (as seen in raw data)");
261 fManuHist[i]->SetYTitle("Number of signals read.");
262 sprintf(name, "signalDistrib_%d", equipId);
263 sprintf(title, "Distribution of signals in raw data from DDL %d.", equipId);
264 fSignalHist[i] = new TH1D(name, title, 4096, -0.5, 4095.5);
265 fSignalHist[i]->SetXTitle("Channels");
266 fSignalHist[i]->SetYTitle("dN/dChannel");
269 catch (const std::bad_alloc&)
271 HLTError("Could not allocate more memory for histogram objects.");
280 int AliHLTMUONRawDataHistoComponent::DoDeinit()
282 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
283 /// Will delete all histogram objects.
285 HLTInfo("Deinitialising dHLT raw data histogrammer component.");
286 fCurrentEventTime = -1;
292 int AliHLTMUONRawDataHistoComponent::DoEvent(
293 const AliHLTComponentEventData& /*evtData*/,
294 AliHLTComponentTriggerData& /*trigData*/
297 /// Inherited from AliHLTProcessor.
298 /// Processes the new event data and generates summary histograms.
300 if (fProcessDataEventsOnly and not IsDataEvent()) return 0; // Only process data events.
302 fCurrentEventTime = TTimeStamp().AsDouble();
304 const AliHLTComponentBlockData* block = GetFirstInputBlock(AliHLTMUONConstants::DDLRawDataType());
305 for ( ; block != NULL; block = GetNextInputBlock())
307 HLTDebug("Handling block with fDataType = '%s', fPtr = %p,"
308 " fSize = %u bytes and fSpecification = 0x%8.8X.",
309 DataType2Text(block->fDataType).c_str(), block->fPtr,
310 block->fSize, block->fSpecification
313 if (AliHLTMUONUtils::IsTrackerDDL(block->fSpecification))
315 ProcessTrackerDDL(block);
317 else if (AliHLTMUONUtils::IsTriggerDDL(block->fSpecification))
319 ProcessTriggerDDL(block);
323 HLTError("Received a raw data block with an invalid specification of"
324 " 0x%8.8X. Expected raw data only from one DDL and not multiple"
325 " DDLs as indicated by the specification.",
326 block->fSpecification
331 // See if 'fPublishDelay' number of seconds has elapsed or this is the first event,
332 // in that case publish the histograms. Do not publish histograms that are empty
333 // if the fSuppressEmptyHists flag is set.
334 if (fLastPublishTime == -1 or fCurrentEventTime - fLastPublishTime >= fPublishDelay)
336 for (int i = 0; i < 22; i++)
338 if (fSuppressEmptyHists and fErrorHist[i]->GetEntries() == 0) continue;
339 PushBack(fErrorHist[i],
340 AliHLTMUONConstants::HistogramDataType(),
341 AliHLTMUONUtils::DDLNumberToSpec(i)
343 // If requested, clear histogram when published.
344 if (fClearAfterPublish) fErrorHist[i]->Reset("M");
346 for (int i = 0; i < 20; i++)
348 AliHLTUInt32_t spec = AliHLTMUONUtils::DDLNumberToSpec(i);
349 if (not (fSuppressEmptyHists and fManuHist[i]->GetEntries() == 0))
351 PushBack(fManuHist[i], AliHLTMUONConstants::HistogramDataType(), spec);
352 if (fClearAfterPublish) fManuHist[i]->Reset("M");
354 if (not (fSuppressEmptyHists and fSignalHist[i]->GetEntries() == 0))
356 PushBack(fSignalHist[i], AliHLTMUONConstants::HistogramDataType(), spec);
357 if (fClearAfterPublish) fSignalHist[i]->Reset("M");
360 fLastPublishTime = fCurrentEventTime;
367 void AliHLTMUONRawDataHistoComponent::ProcessTrackerDDL(const AliHLTComponentBlockData* block)
369 /// Processes a raw data block from the tracker stations.
371 AliHLTInt32_t ddl = AliHLTMUONUtils::SpecToDDLNumber(block->fSpecification);
372 assert(0 <= ddl and ddl < 20);
374 fTrackerDecoder.GetHandler().ErrorHist(fErrorHist[ddl]);
375 fTrackerDecoder.GetHandler().ManuHist(fManuHist[ddl]);
376 fTrackerDecoder.GetHandler().SignalHist(fSignalHist[ddl]);
378 if (block->fSize >= sizeof(AliRawDataHeader))
380 AliHLTUInt8_t* payload = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr)
381 + sizeof(AliRawDataHeader);
382 UInt_t payloadSize = UInt_t(block->fSize) - sizeof(AliRawDataHeader);
383 fTrackerDecoder.Decode(payload, payloadSize);
387 HLTError("Received a raw data block that is too short to be valid."
388 " Its size is only %d bytes",
391 fErrorHist[ddl]->Fill(40);
396 void AliHLTMUONRawDataHistoComponent::ProcessTriggerDDL(const AliHLTComponentBlockData* block)
398 /// Processes a raw data block from the trigger stations.
400 AliHLTInt32_t ddl = AliHLTMUONUtils::SpecToDDLNumber(block->fSpecification);
401 assert(21 <= ddl and ddl < 22);
403 fTriggerDecoder.GetHandler().ErrorHist(fErrorHist[ddl]);
405 if (block->fSize >= sizeof(AliRawDataHeader))
407 AliRawDataHeader* header = reinterpret_cast<AliRawDataHeader*>(block->fPtr);
408 AliHLTUInt8_t* payload = reinterpret_cast<AliHLTUInt8_t*>(header+1);
409 UInt_t payloadSize = UInt_t(block->fSize) - sizeof(AliRawDataHeader);
410 bool scalarEvent = ((header->GetL1TriggerMessage() & 0x1) == 0x1);
411 fTriggerDecoder.Decode(payload, payloadSize, scalarEvent);
415 HLTError("Received a raw data block that is too short to be valid."
416 " Its size is only %d bytes",
419 fErrorHist[ddl]->Fill(40);
424 void AliHLTMUONRawDataHistoComponent::FreeObjects()
426 /// Deletes all the histogram objects that were allocated.
428 for (int i = 0; i < 22; i++)
430 if (fErrorHist[i] != NULL)
432 delete fErrorHist[i];
433 fErrorHist[i] = NULL;
436 for (int i = 0; i < 20; i++)
438 if (fManuHist[i] != NULL)
443 if (fSignalHist[i] != NULL)
445 delete fSignalHist[i];
446 fSignalHist[i] = NULL;