3 //**************************************************************************
4 //* This file is property of and copyright by the *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
9 //* Permission to use, copy, modify and distribute this software and its *
10 //* documentation strictly for non-commercial purposes is hereby granted *
11 //* without fee, provided that the above copyright notice appears in all *
12 //* copies and that both the copyright notice and this permission notice *
13 //* appear in the supporting documentation. The authors make no claims *
14 //* about the suitability of this software for any purpose. It is *
15 //* provided "as is" without express or implied warranty. *
16 //**************************************************************************
18 /// @file AliHLTOUTDigitReader.cxx
19 /// @author Matthias Richter
21 /// @brief HLTOUT data wrapper for simulated AliRoot HLT digit data.
24 #include "AliHLTOUTDigitReader.h"
25 #include "AliHLTCDHWrapper.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTOUTDigitReader)
37 AliHLTOUTDigitReader::AliHLTOUTDigitReader(int event, AliHLTEsdManager* pEsdManager, const char* digitFile)
39 AliHLTOUTHomerCollection(event, pEsdManager),
40 fDigitFileName(digitFile),
52 // HLTOUT data wrapper for simulated AliRoot HLT digit data
54 // see header file for class documentation
57 AliHLTOUTDigitReader::~AliHLTOUTDigitReader()
69 Bool_t AliHLTOUTDigitReader::ReadNextData(UChar_t*& data)
71 // overloaded from AliHLTOUTHomerCollection: switch to next DDL
72 if (!fppDigitArrays && (!ReadArrays() || !fppDigitArrays))
75 if (fCurrentLink>=fNofDDLs)
78 while (++fCurrentLink<fNofDDLs) {
79 if (fMinDDL>-1 && fMinDDL>fpEquipments[fCurrentLink]) continue;
80 if (fMaxDDL>-1 && fMaxDDL<fpEquipments[fCurrentLink]) continue;
81 AliHLTCDHWrapper cdh((void*)fppDigitArrays[fCurrentLink]->GetArray());
82 UInt_t headerSize=cdh.GetHeaderSize();
83 if (fppDigitArrays[fCurrentLink]->GetSize()>(int)headerSize) {
84 data=reinterpret_cast<UChar_t*>(fppDigitArrays[fCurrentLink]->GetArray());
92 int AliHLTOUTDigitReader::Reset()
94 // overloaded from AliHLTOUTHomerCollection: reset DDL position
99 int AliHLTOUTDigitReader::GetDataSize()
101 // overloaded from AliHLTOUTHomerCollection: get size of current DDL
102 if (fCurrentLink>=0 && fCurrentLink<fNofDDLs && fppDigitArrays) {
103 AliHLTCDHWrapper cdh((void*)fppDigitArrays[fCurrentLink]->GetArray());
104 return fppDigitArrays[fCurrentLink]->GetSize()-cdh.GetHeaderSize();
109 AliHLTCDHWrapper AliHLTOUTDigitReader::GetDataHeader()
111 // overloaded from AliHLTOUTHomerCollection: get data header of current DDL
112 if (fCurrentLink>=0 && fCurrentLink<fNofDDLs && fppDigitArrays) {
113 return AliHLTCDHWrapper(fppDigitArrays[fCurrentLink]->GetArray());
118 void AliHLTOUTDigitReader::SelectEquipment(int /*equipmentType*/, int minEquipmentId, int maxEquipmentId)
120 // overloaded from AliHLTOUTHomerCollection: select equipment range
121 fMinDDL=minEquipmentId;
122 fMaxDDL=maxEquipmentId;
125 int AliHLTOUTDigitReader::GetEquipmentId()
127 // overloaded from AliHLTOUTHomerCollection: get id of current DDL
128 if (fCurrentLink>=0 && fCurrentLink<fNofDDLs && fpEquipments) {
129 return fpEquipments[fCurrentLink];
134 bool AliHLTOUTDigitReader::ReadArrays()
136 // Read the data from the root file and HLTOUT raw tree.
137 // Retrieve the number of branches and allocate arrays acording
138 // to that. After initialization of the arrays and variables, the
139 // event fEnvent is read.
142 if (GetCurrentEventNo()<0) {
143 HLTWarning("no event selected, no data available");
147 // 2011-06-06 in order to support AliHLTReconstructor option 'ignore-hltout' for
148 // digits, the file name can be set to NULL, nothing done in that case
149 if (!fDigitFileName) return false;
152 fpDigitFile=new TFile(fDigitFileName);
154 if (!fpDigitFile) return false;
155 if (fpDigitFile->IsZombie()) return false;
157 fpDigitFile->GetObject("rawhltout", fpDigitTree);
162 vector<int> equipments;
164 TIter iter(fpDigitTree->GetListOfBranches());
165 while (TBranch* br=(TBranch *)iter.Next()) {
167 TString bname=br->GetName();
168 if (bname.BeginsWith("HLT_") && bname.EndsWith(".ddl")) {
169 bname.ReplaceAll("HLT_", "");
170 bname.ReplaceAll(".ddl", "");
171 if (bname.IsDigit()) {
172 int equipment=bname.Atoi();
173 int index=equipment-AliDAQ::DdlIDOffset("HLT");
174 if (index>=0 && strcmp(br->GetName(), AliDAQ::DdlFileName("HLT", index))==0) {
175 equipments.push_back(equipment);
177 HLTWarning("equipment mismatch: skipping id %d (out of range of HLT equipments)", equipment);
182 HLTDebug("found %d HLT branche(s) out of %d", equipments.size(), iTotal);
184 if (equipments.size()>0) {
185 fNofDDLs=equipments.size();
186 fpEquipments=new int[fNofDDLs];
187 fppDigitArrays=new TArrayC*[fNofDDLs];
188 if (fpEquipments && fppDigitArrays) {
189 memcpy(fpEquipments, &equipments[0], fNofDDLs*sizeof(int));
191 for (i=0; i<fNofDDLs; i++) {
192 fppDigitArrays[i]=NULL;
193 fpDigitTree->SetBranchAddress(AliDAQ::DdlFileName("HLT", fpEquipments[i]-AliDAQ::DdlIDOffset("HLT")), &fppDigitArrays[i]);
195 fpDigitTree->GetEvent(GetCurrentEventNo());
196 for (i=0; i<fNofDDLs; i++) {
197 if (fppDigitArrays[i]) {
198 HLTDebug("branch %s: %d byte(s)", AliDAQ::DdlFileName("HLT", fpEquipments[i]-AliDAQ::DdlIDOffset("HLT")), fppDigitArrays[i]);
209 int AliHLTOUTDigitReader::CloseTree()
211 // Cleanup tree and data arrays.
213 for (int i=0; i<fNofDDLs; i++) {
214 if (fppDigitArrays[i]) delete fppDigitArrays[i];
215 fppDigitArrays[i]=NULL;
217 if (fppDigitArrays) delete[] fppDigitArrays;
219 if (fpEquipments) delete[] fpEquipments;
221 if (fpDigitTree) delete fpDigitTree;
229 void AliHLTOUTDigitReader::SetParam(TTree* /*pDigitTree*/, int event)
231 // set parameter for this HLTOUT instance
232 // The function is for internal use only in conjunction with the
233 // AliHLTOUT::New() functions.
235 // TODO: here we have the implemented to correct loading of
236 // the digit file from the run loader. At time of writing
237 // (Jun 2008) the AliLoader for the HLT is missing in the AliRoot
242 void AliHLTOUTDigitReader::SetParam(const char* filename, int event)
244 // set parameter for this HLTOUT instance
245 // The function is for internal use only in conjunction with the
246 // AliHLTOUT::New() functions.
248 if (filename && filename[0]!=0) {
249 fDigitFileName=filename;
251 HLTWarning("no valid digit file provided, using default file %s", fDigitFileName.Data());