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 AliHLTMUONRootifierComponent.cxx
21 /// @author Artur Szostak <artursz@iafrica.com>
23 /// @brief Implementation of the AliHLTMUONRootifierComponent component.
26 #include "AliHLTMUONRootifierComponent.h"
27 #include "AliHLTMUONConstants.h"
28 #include "AliHLTMUONUtils.h"
29 #include "AliHLTMUONDataBlockReader.h"
30 #include "AliHLTMUONRecHit.h"
31 #include "AliHLTMUONTriggerRecord.h"
32 #include "AliHLTMUONMansoTrack.h"
35 ClassImp(AliHLTMUONEvent);
36 ClassImp(AliHLTMUONRootifierComponent);
39 AliHLTMUONRootifierComponent::AliHLTMUONRootifierComponent() :
43 /// Default constructor.
48 AliHLTMUONRootifierComponent::~AliHLTMUONRootifierComponent()
51 /// Default destructor.
56 int AliHLTMUONRootifierComponent::DoInit(int /*argc*/, const char** /*argv*/)
59 /// Inherited from AliHLTComponent.
60 /// Parses the command line parameters and initialises the component.
67 int AliHLTMUONRootifierComponent::DoDeinit()
70 /// Inherited from AliHLTComponent. Performs a cleanup of the component.
77 const char* AliHLTMUONRootifierComponent::GetComponentID()
80 /// Inherited from AliHLTComponent. Returns the component ID.
83 return "MUONRootifier";
87 AliHLTComponentDataType AliHLTMUONRootifierComponent::GetOutputDataType()
89 /// Inherited from AliHLTComponent. Returns kAliHLTMultipleDataType
90 /// refer to GetOutputDataTypes for all returned data types.
92 return kAliHLTMultipleDataType;
96 int AliHLTMUONRootifierComponent::GetOutputDataTypes(AliHLTComponentDataTypeList& tgtList)
98 /// Inherited from AliHLTComponent. Returns the output data types.
100 tgtList.push_back(kAliHLTAnyDataType);
105 void AliHLTMUONRootifierComponent::GetInputDataTypes(
106 vector<AliHLTComponentDataType>& list
110 /// Inherited from AliHLTProcessor. Returns the list of expected input data types.
113 list.push_back(kAliHLTAnyDataType);
117 void AliHLTMUONRootifierComponent::GetOutputDataSize(
118 unsigned long& constBase, double& inputMultiplier
122 /// Inherited from AliHLTComponent. Returns an estimate of the expected output data size.
125 constBase = 1024*1024;
126 inputMultiplier = 100;
130 AliHLTComponent* AliHLTMUONRootifierComponent::Spawn()
133 /// Inherited from AliHLTComponent. Creates a new object instance.
136 return new AliHLTMUONRootifierComponent();
140 int AliHLTMUONRootifierComponent::DoEvent(
141 const AliHLTComponentEventData& evtData,
142 AliHLTComponentTriggerData& /*trigData*/
146 /// Inherited from AliHLTProcessor. Processes the new event data.
149 AliHLTMUONEvent event(evtData.fEventID);
151 // First process the blocks of reconstructed hits and trigger records.
152 for (int i = 0; i < GetNumberOfInputBlocks(); i++)
154 const AliHLTComponentBlockData* block = GetInputBlock(i);
155 assert( block != NULL );
156 if (block->fDataType == AliHLTMUONConstants::RecHitsBlockDataType())
158 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
159 ptr += block->fOffset;
160 AliHLTMUONRecHitsBlockReader inblock(ptr, block->fSize);
161 if (not inblock.BufferSizeOk())
163 size_t headerSize = sizeof(AliHLTMUONRecHitsBlockReader::HeaderType);
164 if (block->fSize < headerSize)
166 HLTError("Received a reconstructed hits data block with a size of %d bytes,"
167 " which is smaller than the minimum valid header size of %d bytes."
168 " The block must be corrupt.",
169 block->fSize, headerSize
174 size_t expectedWidth = sizeof(AliHLTMUONRecHitsBlockReader::ElementType);
175 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
177 HLTError("Received a reconstructed hits data block with a record"
178 " width of %d bytes, but the expected value is %d bytes."
179 " The block might be corrupt.",
180 block->fSize, headerSize
185 HLTError("Received a reconstructed hits data block with a size of %d bytes,"
186 " but the block header claims the block should be %d bytes."
187 " The block might be corrupt.",
188 block->fSize, inblock.BytesUsed()
193 // Decode the source DDL from the specification bits.
194 Int_t sourceDDL = -1;
196 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
197 for (int k = 0; k < 22; k++)
207 HLTWarning("The input data block %d contains"
208 " data from multiple DDL sources.", i
215 HLTWarning("The source DDL for input data block %d is %d."
216 " The expected range for the DDL is [1..20].",
221 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
223 const AliHLTMUONRecHitStruct& h = inblock[n];
224 //AliHLTMUONRecHit rh(h.fX, h.fY, h.fZ, sourceDDL);
225 //PushBack(&rh, "ROOTHITS", "MUON");
226 event.Add(new AliHLTMUONRecHit(h.fX, h.fY, h.fZ, sourceDDL));
229 else if (block->fDataType == AliHLTMUONConstants::TriggerRecordsBlockDataType())
231 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
232 ptr += block->fOffset;
233 AliHLTMUONTriggerRecordsBlockReader inblock(ptr, block->fSize);
234 if (not inblock.BufferSizeOk())
236 size_t headerSize = sizeof(AliHLTMUONTriggerRecordsBlockReader::HeaderType);
237 if (block->fSize < headerSize)
239 HLTError("Received a trigger records data block with a size of %d bytes,"
240 " which is smaller than the minimum valid header size of %d bytes."
241 " The block must be corrupt.",
242 block->fSize, headerSize
247 size_t expectedWidth = sizeof(AliHLTMUONTriggerRecordsBlockReader::ElementType);
248 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
250 HLTError("Received a trigger records data block with a record"
251 " width of %d bytes, but the expected value is %d bytes."
252 " The block might be corrupt.",
253 block->fSize, headerSize
258 HLTError("Received a trigger records data block with a size of %d bytes,"
259 " but the block header claims the block should be %d bytes."
260 " The block might be corrupt.",
261 block->fSize, inblock.BytesUsed()
266 // Decode the source DDL from the specification bits.
267 Int_t sourceDDL = -1;
269 AliHLTMUONUtils::UnpackSpecBits(block->fSpecification, ddl);
270 for (int k = 0; k < 22; k++)
280 HLTWarning("The input data block %d contains"
281 " data from multiple DDL sources.", i
286 if (sourceDDL != -1 and (sourceDDL < 21 or sourceDDL > 22))
288 HLTWarning("The source DDL for input data block %d is %d."
289 " The expected range for the DDL is [21..22].",
294 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
296 const AliHLTMUONTriggerRecordStruct& t = inblock[n];
298 AliHLTMUONParticleSign sign;
300 AliHLTMUONUtils::UnpackTriggerRecordFlags(
301 t.fFlags, sign, hitset
304 AliHLTMUONTriggerRecord* tr = new AliHLTMUONTriggerRecord(
305 t.fId, sign, t.fPx, t.fPy, t.fPz, sourceDDL
307 for (int k = 0; k < 4; k++)
308 tr->SetHit(k+11, t.fHit[k].fX, t.fHit[k].fY, t.fHit[k].fZ);
314 // TODO: ignore for now, but should log an optional message.
318 // Now we can look for tracks to add. We needed the ROOT trigger records
319 // and reco hits created before we can create track objects.
320 for (int i = 0; i < GetNumberOfInputBlocks(); i++)
322 const AliHLTComponentBlockData* block = GetInputBlock(i);
323 assert( block != NULL );
324 if (block->fDataType == AliHLTMUONConstants::MansoTracksBlockDataType())
326 AliHLTUInt8_t* ptr = reinterpret_cast<AliHLTUInt8_t*>(block->fPtr);
327 ptr += block->fOffset;
328 AliHLTMUONMansoTracksBlockReader inblock(ptr, block->fSize);
329 if (not inblock.BufferSizeOk())
331 size_t headerSize = sizeof(AliHLTMUONMansoTracksBlockReader::HeaderType);
332 if (block->fSize < headerSize)
334 HLTError("Received a Manso tracks data block with a size of %d bytes,"
335 " which is smaller than the minimum valid header size of %d bytes."
336 " The block must be corrupt.",
337 block->fSize, headerSize
342 size_t expectedWidth = sizeof(AliHLTMUONMansoTracksBlockReader::ElementType);
343 if (inblock.CommonBlockHeader().fRecordWidth != expectedWidth)
345 HLTError("Received a Manso tracks data block with a record"
346 " width of %d bytes, but the expected value is %d bytes."
347 " The block might be corrupt.",
348 block->fSize, headerSize
353 HLTError("Received a Manso tracks data block with a size of %d bytes,"
354 " but the block header claims the block should be %d bytes."
355 " The block might be corrupt.",
356 block->fSize, inblock.BytesUsed()
361 for (AliHLTUInt32_t n = 0; n < inblock.Nentries(); n++)
363 const AliHLTMUONMansoTrackStruct& t = inblock[n];
365 AliHLTMUONParticleSign sign;
367 AliHLTMUONUtils::UnpackMansoTrackFlags(
368 t.fFlags, sign, hitset
371 // Try find the trigger record in 'event'.
372 const AliHLTMUONTriggerRecord* trigrec = NULL;
373 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
375 if (event.Array()[k]->IsA() != AliHLTMUONTriggerRecord::Class())
377 const AliHLTMUONTriggerRecord* tk =
378 static_cast<const AliHLTMUONTriggerRecord*>(event.Array()[k]);
379 if (tk->Id() == t.fTrigRec)
386 // Now try find the hits in 'event'.
387 // If they cannot be found then create new ones.
388 const AliHLTMUONRecHit* hit7 = NULL;
389 const AliHLTMUONRecHit* hit8 = NULL;
390 const AliHLTMUONRecHit* hit9 = NULL;
391 const AliHLTMUONRecHit* hit10 = NULL;
392 for (Int_t k = 0; k < event.Array().GetEntriesFast(); k++)
394 if (event.Array()[k]->IsA() != AliHLTMUONRecHit::Class())
396 const AliHLTMUONRecHit* h =
397 static_cast<const AliHLTMUONRecHit*>(event.Array()[k]);
399 if (hitset[0] and h->X() == t.fHit[0].fX and h->Y() == t.fHit[0].fY
400 and h->Z() == t.fHit[0].fZ)
404 if (hitset[1] and h->X() == t.fHit[1].fX and h->Y() == t.fHit[1].fY
405 and h->Z() == t.fHit[1].fZ)
409 if (hitset[2] and h->X() == t.fHit[2].fX and h->Y() == t.fHit[2].fY
410 and h->Z() == t.fHit[2].fZ)
414 if (hitset[3] and h->X() == t.fHit[3].fX and h->Y() == t.fHit[3].fY
415 and h->Z() == t.fHit[3].fZ)
420 AliHLTMUONRecHit* newhit;
421 if (hitset[0] and hit7 == NULL)
423 newhit = new AliHLTMUONRecHit(t.fHit[0].fX, t.fHit[0].fY, t.fHit[0].fZ);
427 if (hitset[1] and hit8 == NULL)
429 newhit = new AliHLTMUONRecHit(t.fHit[1].fX, t.fHit[1].fY, t.fHit[1].fZ);
433 if (hitset[2] and hit9 == NULL)
435 newhit = new AliHLTMUONRecHit(t.fHit[2].fX, t.fHit[2].fY, t.fHit[2].fZ);
439 if (hitset[3] and hit10 == NULL)
441 newhit = new AliHLTMUONRecHit(t.fHit[3].fX, t.fHit[3].fY, t.fHit[3].fZ);
446 AliHLTMUONMansoTrack* tr = new AliHLTMUONMansoTrack(
447 t.fId, sign, t.fPx, t.fPy, t.fPz, t.fChi2,
448 trigrec, hit7, hit8, hit9, hit10
455 // TODO: ignore for now, but should log an optional message.
459 PushBack(&event, "ROOTEVNT", "MUON");
465 void AliHLTMUONEvent::Print(Option_t* option) const
468 /// Inherited from TObject. Prints the contents of the event objects in fArray.
471 cout << "################## EVENT: " << fEventId << " ##################" << endl;
472 for (Int_t i = 0; i < fArray.GetEntriesFast(); i++)
473 if (fArray[i] != NULL) fArray[i]->Print(option);