Add setting to read friends
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTReadoutListDumpComponent.cxx
CommitLineData
209986b4 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: Matthias Richter <Matthias.Richter@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 AliHLTReadoutListDumpComponent.cxx
20 @author Matthias Richter
21 @date
22 @brief Base class for writer components to store data in a ROOT file
23
24 */
25
26#include "AliHLTReadoutListDumpComponent.h"
27#include "AliHLTTriggerDecision.h"
28#include "AliHLTCTPData.h"
29#include "TH1I.h"
30#include "TH2I.h"
31#include "TString.h"
32#include "TFile.h"
33#include "TSystem.h"
34
35/** ROOT macro for the implementation of ROOT specific class methods */
36ClassImp(AliHLTReadoutListDumpComponent)
37
38AliHLTReadoutListDumpComponent::AliHLTReadoutListDumpComponent()
39 : AliHLTFileWriter()
40 , fMode(AliHLTReadoutListDumpComponent::kModeBinaryList)
41 , fBitsHisto(NULL)
42 , fBitsVsCTP(NULL)
43{
44 // see header file for class documentation
45 // or
46 // refer to README to build package
47 // or
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49}
50
51AliHLTReadoutListDumpComponent::~AliHLTReadoutListDumpComponent()
52{
53 // see header file for class documentation
54}
55
56int AliHLTReadoutListDumpComponent::InitWriter()
57{
58 // see header file for class documentation
59 int iResult=0;
60 fBitsHisto=CreateReadoutListHistogram();
61 fBitsVsCTP=CreateReadoutListVsCTPHistogram();
62 if (!fBitsHisto || !fBitsVsCTP) return -ENOMEM;
63
64 return iResult;
65}
66
67int AliHLTReadoutListDumpComponent::CloseWriter()
68{
69 // see header file for class documentation
70 TString filename=GetDirectory();
71 if (!filename.IsNull() && !filename.EndsWith("/")) filename+="/";
72 filename+=fBitsHisto->GetName();
73 filename+="_";
74 filename+=GetRunNo();
75 filename+=".root";
76
77 TFile out(filename, "RECREATE");
78 fBitsHisto->Write();
79 fBitsVsCTP->Write();
80 out.Close();
81
82 delete fBitsHisto;
83 fBitsHisto=NULL;
84 delete fBitsVsCTP;
85 fBitsVsCTP=NULL;
86 return 0;
87}
88
89int AliHLTReadoutListDumpComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
90 const AliHLTComponentBlockData* /*blocks*/,
91 AliHLTComponentTriggerData& trigData )
92{
93 // see header file for class documentation
94 int iResult=0;
95 if (!IsDataEvent()) return 0;
96
97 if (fMode==AliHLTReadoutListDumpComponent::kModeBinaryList) {
98 const AliHLTComponentDataType hltrdlstdt=AliHLTComponentDataTypeInitializer("HLTRDLST", "HLT ");
99 for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
100 pBlock && iResult>=0;
101 pBlock=GetNextInputBlock()) {
102 if (pBlock->fDataType!=hltrdlstdt) continue;
103 if (pBlock->fSize==sizeof(AliHLTEventDDL)) {
104 HLTDebug("Filling histograms from binary buffer");
105 FillReadoutListHistogram(fBitsHisto, reinterpret_cast<AliHLTEventDDL*>(pBlock->fPtr));
106 FillReadoutListVsCTP(fBitsVsCTP, reinterpret_cast<AliHLTEventDDL*>(pBlock->fPtr), &trigData);
107 } else {
108 HLTError("HLTRDLST size missmatch: %d, expected %d", pBlock->fSize, sizeof(AliHLTEventDDL));
109 }
110 }
111 } else if (fMode==AliHLTReadoutListDumpComponent::kModeHLTDecision) {
112 for (const TObject* pObject=GetFirstInputObject();
113 pObject && iResult>=0;
114 pObject=GetNextInputObject()) {
115 const AliHLTTriggerDecision* pDecision=dynamic_cast<const AliHLTTriggerDecision*>(pObject);
116 if (!pDecision) continue;
117
118 AliHLTReadoutList list=pDecision->ReadoutList();
119 HLTDebug("Filling histograms from HLT decision object");
120 FillReadoutListHistogram(fBitsHisto, &list);
121 FillReadoutListVsCTP(fBitsVsCTP, &list, &trigData);
122 }
123 } else {
124 HLTError("invalid mode %d", fMode);
125 iResult=-EFAULT;
126 }
127 return iResult;
128}
129
130int AliHLTReadoutListDumpComponent::ScanArgument(int argc, const char** argv)
131{
132 // see header file for class documentation
133 int iResult=-EINVAL;
134 if (argc<=0) return 0;
135 int i=0;
136 TString argument=argv[i];
137
138 // -binary
139 if (argument.CompareTo("-binary")==0) {
140 fMode=AliHLTReadoutListDumpComponent::kModeBinaryList;
141 return 1;
142 }
143
144 // -decision
145 if (argument.CompareTo("-decision")==0) {
146 fMode=AliHLTReadoutListDumpComponent::kModeHLTDecision;
147 return 1;
148 }
149
150 return iResult;
151}
152
153TH1I* AliHLTReadoutListDumpComponent::CreateReadoutListHistogram()
154{
155 // see header file for class documentation
156 int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8;
157 TH1I* histo=new TH1I("HLTRDLST","HLT readout list", bins, 0, bins);
158 return histo;
159}
160
161TH2I* AliHLTReadoutListDumpComponent::CreateReadoutListVsCTPHistogram()
162{
163 // see header file for class documentation
164 int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8;
165 TH2I* histo=new TH2I("HLTRDLSTvsCTP","HLT readout list vs. CTP trigger", bins, 0, bins, gkNCTPTriggerClasses, 0, gkNCTPTriggerClasses);
166 return histo;
167}
168
169int AliHLTReadoutListDumpComponent::FillReadoutListHistogram(TH1I* histo, const AliHLTReadoutList* list)
170{
171 // see header file for class documentation
172 if (!histo || !list) return -EINVAL;
8fab602c 173 if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF;
209986b4 174
175 return FillReadoutListHistogram(histo, list->Buffer());
176}
177
178int AliHLTReadoutListDumpComponent::FillReadoutListHistogram(TH1I* histo, const AliHLTEventDDL* field)
179{
180 // see header file for class documentation
181 if (!histo || !field) return -EINVAL;
182
183 if (field->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF;
184
185 for (int word=0; word<gkAliHLTDDLListSize; word++) {
186 for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) {
187 if (field->fList[word]&0x1<<bit) histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit);
188 }
189 }
190
191 return 0;
192}
193
194int AliHLTReadoutListDumpComponent::FillReadoutListVsCTP(TH2I* histo, const AliHLTReadoutList* list, const AliHLTComponentTriggerData* trigData)
195{
196 // see header file for class documentation
197 if (!histo || !list || !trigData) return -EINVAL;
8fab602c 198 if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF;
209986b4 199
200 return FillReadoutListVsCTP(histo, list->Buffer(), trigData);
201}
202
203int AliHLTReadoutListDumpComponent::FillReadoutListVsCTP(TH2I* histo, const AliHLTEventDDL* field, const AliHLTComponentTriggerData* trigData)
204{
205 // see header file for class documentation
206 if (!histo || !field || !trigData) return -EINVAL;
207
208 if (field->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF;
209
210 AliHLTUInt64_t triggerMask=AliHLTCTPData::ActiveTriggers(*trigData);
211 AliHLTUInt64_t bit0=0x1;
212 for (int word=0; word<gkAliHLTDDLListSize; word++) {
213 for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) {
214 if (field->fList[word]&0x1<<bit) {
215 for (int trigger=0; trigger<gkNCTPTriggerClasses; trigger++) {
216 if ((triggerMask&(bit0<<trigger))!=0) {
217 histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit, trigger);
218 }
219 }
220 }
221 }
222 }
223
224 return 0;
225}