Line data Source code
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 */
36 8 : ClassImp(AliHLTReadoutListDumpComponent)
37 :
38 : AliHLTReadoutListDumpComponent::AliHLTReadoutListDumpComponent()
39 3 : : AliHLTFileWriter()
40 3 : , fMode(AliHLTReadoutListDumpComponent::kModeBinaryList)
41 3 : , fBitsHisto(NULL)
42 3 : , fBitsVsCTP(NULL)
43 15 : {
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 6 : }
50 :
51 : AliHLTReadoutListDumpComponent::~AliHLTReadoutListDumpComponent()
52 12 : {
53 : // see header file for class documentation
54 12 : }
55 :
56 : int AliHLTReadoutListDumpComponent::InitWriter()
57 : {
58 : // see header file for class documentation
59 : int iResult=0;
60 0 : fBitsHisto=CreateReadoutListHistogram();
61 0 : fBitsVsCTP=CreateReadoutListVsCTPHistogram();
62 0 : if (!fBitsHisto || !fBitsVsCTP) return -ENOMEM;
63 :
64 0 : return iResult;
65 0 : }
66 :
67 : int AliHLTReadoutListDumpComponent::CloseWriter()
68 : {
69 : // see header file for class documentation
70 0 : TString filename=GetDirectory();
71 0 : if (!filename.IsNull() && !filename.EndsWith("/")) filename+="/";
72 0 : filename+=fBitsHisto->GetName();
73 0 : filename+="_";
74 0 : filename+=GetRunNo();
75 0 : filename+=".root";
76 :
77 0 : TFile out(filename, "RECREATE");
78 0 : fBitsHisto->Write();
79 0 : fBitsVsCTP->Write();
80 0 : out.Close();
81 :
82 0 : delete fBitsHisto;
83 0 : fBitsHisto=NULL;
84 0 : delete fBitsVsCTP;
85 0 : fBitsVsCTP=NULL;
86 : return 0;
87 0 : }
88 :
89 : int 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 0 : if (!IsDataEvent()) return 0;
96 :
97 0 : if (fMode==AliHLTReadoutListDumpComponent::kModeBinaryList) {
98 0 : const AliHLTComponentDataType hltrdlstdt=AliHLTComponentDataTypeInitializer("HLTRDLST", "HLT ");
99 0 : for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
100 0 : pBlock && iResult>=0;
101 0 : pBlock=GetNextInputBlock()) {
102 0 : if (pBlock->fDataType!=hltrdlstdt) continue;
103 0 : if (pBlock->fSize==sizeof(AliHLTEventDDL) or
104 0 : pBlock->fSize==sizeof(AliHLTEventDDLV0) or
105 0 : pBlock->fSize==sizeof(AliHLTEventDDLV1))
106 : {
107 : HLTDebug("Filling histograms from binary buffer");
108 0 : AliHLTReadoutList readoutlist(*reinterpret_cast<AliHLTEventDDL*>(pBlock->fPtr));
109 0 : FillReadoutListHistogram(fBitsHisto, &readoutlist);
110 0 : FillReadoutListVsCTP(fBitsVsCTP, &readoutlist, &trigData);
111 0 : } else {
112 0 : HLTError("HLTRDLST size missmatch: %d, expected V0:%d, V1:%d or V2%d", pBlock->fSize, sizeof(AliHLTEventDDLV0), sizeof(AliHLTEventDDLV1), sizeof(AliHLTEventDDLV2));
113 : }
114 : }
115 0 : } else if (fMode==AliHLTReadoutListDumpComponent::kModeHLTDecision) {
116 0 : for (const TObject* pObject=GetFirstInputObject();
117 0 : pObject && iResult>=0;
118 0 : pObject=GetNextInputObject()) {
119 0 : const AliHLTTriggerDecision* pDecision=dynamic_cast<const AliHLTTriggerDecision*>(pObject);
120 0 : if (!pDecision) continue;
121 :
122 0 : AliHLTReadoutList list=pDecision->ReadoutList();
123 : HLTDebug("Filling histograms from HLT decision object");
124 0 : FillReadoutListHistogram(fBitsHisto, &list);
125 0 : FillReadoutListVsCTP(fBitsVsCTP, &list, &trigData);
126 0 : }
127 0 : } else {
128 0 : HLTError("invalid mode %d", fMode);
129 : iResult=-EFAULT;
130 : }
131 0 : return iResult;
132 0 : }
133 :
134 : int AliHLTReadoutListDumpComponent::ScanArgument(int argc, const char** argv)
135 : {
136 : // see header file for class documentation
137 : int iResult=-EINVAL;
138 0 : if (argc<=0) return 0;
139 : int i=0;
140 0 : TString argument=argv[i];
141 :
142 : // -binary
143 0 : if (argument.CompareTo("-binary")==0) {
144 0 : fMode=AliHLTReadoutListDumpComponent::kModeBinaryList;
145 0 : return 1;
146 : }
147 :
148 : // -decision
149 0 : if (argument.CompareTo("-decision")==0) {
150 0 : fMode=AliHLTReadoutListDumpComponent::kModeHLTDecision;
151 0 : return 1;
152 : }
153 :
154 0 : return iResult;
155 0 : }
156 :
157 : TH1I* AliHLTReadoutListDumpComponent::CreateReadoutListHistogram()
158 : {
159 : // see header file for class documentation
160 : int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8;
161 0 : TH1I* histo=new TH1I("HLTRDLST","HLT readout list", bins, 0, bins);
162 0 : return histo;
163 0 : }
164 :
165 : TH2I* AliHLTReadoutListDumpComponent::CreateReadoutListVsCTPHistogram()
166 : {
167 : // see header file for class documentation
168 : int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8;
169 0 : TH2I* histo=new TH2I("HLTRDLSTvsCTP","HLT readout list vs. CTP trigger", bins, 0, bins, gkNCTPTriggerClasses, 0, gkNCTPTriggerClasses);
170 0 : return histo;
171 0 : }
172 :
173 : int AliHLTReadoutListDumpComponent::FillReadoutListHistogram(TH1I* histo, const AliHLTReadoutList* list)
174 : {
175 : // see header file for class documentation
176 0 : if (!histo || !list) return -EINVAL;
177 0 : if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF;
178 0 : if (list->Buffer()->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF;
179 :
180 0 : for (int word=0; word<gkAliHLTDDLListSize; word++) {
181 0 : for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) {
182 0 : if (list->Buffer()->fList[word]&0x1<<bit) histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit);
183 : }
184 : }
185 :
186 0 : return 0;
187 0 : }
188 :
189 : int AliHLTReadoutListDumpComponent::FillReadoutListVsCTP(TH2I* histo, const AliHLTReadoutList* list, const AliHLTComponentTriggerData* trigData)
190 : {
191 : // see header file for class documentation
192 0 : if (!histo || !list || !trigData) return -EINVAL;
193 0 : if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF;
194 0 : if (list->Buffer()->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF;
195 :
196 0 : AliHLTTriggerMask_t triggerMask=AliHLTCTPData::ActiveTriggers(*trigData);
197 0 : AliHLTTriggerMask_t bit0=0x1;
198 0 : for (int word=0; word<gkAliHLTDDLListSize; word++) {
199 0 : for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) {
200 0 : if (list->Buffer()->fList[word]&0x1<<bit) {
201 0 : for (int trigger=0; trigger<gkNCTPTriggerClasses; trigger++) {
202 0 : if ((triggerMask&(bit0<<trigger))!=0) {
203 0 : histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit, trigger);
204 0 : }
205 : }
206 0 : }
207 : }
208 : }
209 :
210 : return 0;
211 0 : }
|