]>
Commit | Line | Data |
---|---|---|
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 */ | |
36 | ClassImp(AliHLTReadoutListDumpComponent) | |
37 | ||
38 | AliHLTReadoutListDumpComponent::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 | ||
51 | AliHLTReadoutListDumpComponent::~AliHLTReadoutListDumpComponent() | |
52 | { | |
53 | // see header file for class documentation | |
54 | } | |
55 | ||
56 | int 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 | ||
67 | int 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 | ||
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 | 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; | |
d66f4f29 | 103 | if (pBlock->fSize==sizeof(AliHLTEventDDL) or |
104 | pBlock->fSize==sizeof(AliHLTEventDDLV0) or | |
105 | pBlock->fSize==sizeof(AliHLTEventDDLV1)) | |
106 | { | |
209986b4 | 107 | HLTDebug("Filling histograms from binary buffer"); |
89413559 | 108 | AliHLTReadoutList readoutlist(*reinterpret_cast<AliHLTEventDDL*>(pBlock->fPtr)); |
109 | FillReadoutListHistogram(fBitsHisto, &readoutlist); | |
110 | FillReadoutListVsCTP(fBitsVsCTP, &readoutlist, &trigData); | |
209986b4 | 111 | } else { |
d66f4f29 | 112 | HLTError("HLTRDLST size missmatch: %d, expected V0:%d, V1:%d or V2%d", pBlock->fSize, sizeof(AliHLTEventDDLV0), sizeof(AliHLTEventDDLV1), sizeof(AliHLTEventDDLV2)); |
209986b4 | 113 | } |
114 | } | |
115 | } else if (fMode==AliHLTReadoutListDumpComponent::kModeHLTDecision) { | |
116 | for (const TObject* pObject=GetFirstInputObject(); | |
117 | pObject && iResult>=0; | |
118 | pObject=GetNextInputObject()) { | |
119 | const AliHLTTriggerDecision* pDecision=dynamic_cast<const AliHLTTriggerDecision*>(pObject); | |
120 | if (!pDecision) continue; | |
121 | ||
122 | AliHLTReadoutList list=pDecision->ReadoutList(); | |
123 | HLTDebug("Filling histograms from HLT decision object"); | |
124 | FillReadoutListHistogram(fBitsHisto, &list); | |
125 | FillReadoutListVsCTP(fBitsVsCTP, &list, &trigData); | |
126 | } | |
127 | } else { | |
128 | HLTError("invalid mode %d", fMode); | |
129 | iResult=-EFAULT; | |
130 | } | |
131 | return iResult; | |
132 | } | |
133 | ||
134 | int AliHLTReadoutListDumpComponent::ScanArgument(int argc, const char** argv) | |
135 | { | |
136 | // see header file for class documentation | |
137 | int iResult=-EINVAL; | |
138 | if (argc<=0) return 0; | |
139 | int i=0; | |
140 | TString argument=argv[i]; | |
141 | ||
142 | // -binary | |
143 | if (argument.CompareTo("-binary")==0) { | |
144 | fMode=AliHLTReadoutListDumpComponent::kModeBinaryList; | |
145 | return 1; | |
146 | } | |
147 | ||
148 | // -decision | |
149 | if (argument.CompareTo("-decision")==0) { | |
150 | fMode=AliHLTReadoutListDumpComponent::kModeHLTDecision; | |
151 | return 1; | |
152 | } | |
153 | ||
154 | return iResult; | |
155 | } | |
156 | ||
157 | TH1I* AliHLTReadoutListDumpComponent::CreateReadoutListHistogram() | |
158 | { | |
159 | // see header file for class documentation | |
160 | int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8; | |
161 | TH1I* histo=new TH1I("HLTRDLST","HLT readout list", bins, 0, bins); | |
162 | return histo; | |
163 | } | |
164 | ||
165 | TH2I* AliHLTReadoutListDumpComponent::CreateReadoutListVsCTPHistogram() | |
166 | { | |
167 | // see header file for class documentation | |
168 | int bins=gkAliHLTDDLListSize*sizeof(AliHLTUInt32_t)*8; | |
169 | TH2I* histo=new TH2I("HLTRDLSTvsCTP","HLT readout list vs. CTP trigger", bins, 0, bins, gkNCTPTriggerClasses, 0, gkNCTPTriggerClasses); | |
170 | return histo; | |
171 | } | |
172 | ||
173 | int AliHLTReadoutListDumpComponent::FillReadoutListHistogram(TH1I* histo, const AliHLTReadoutList* list) | |
174 | { | |
175 | // see header file for class documentation | |
176 | if (!histo || !list) return -EINVAL; | |
8fab602c | 177 | if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF; |
89413559 | 178 | if (list->Buffer()->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF; |
209986b4 | 179 | |
180 | for (int word=0; word<gkAliHLTDDLListSize; word++) { | |
181 | for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) { | |
89413559 | 182 | if (list->Buffer()->fList[word]&0x1<<bit) histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit); |
209986b4 | 183 | } |
184 | } | |
89413559 | 185 | |
209986b4 | 186 | return 0; |
187 | } | |
188 | ||
189 | int AliHLTReadoutListDumpComponent::FillReadoutListVsCTP(TH2I* histo, const AliHLTReadoutList* list, const AliHLTComponentTriggerData* trigData) | |
190 | { | |
191 | // see header file for class documentation | |
192 | if (!histo || !list || !trigData) return -EINVAL; | |
8fab602c | 193 | if (list->BufferSize()!=sizeof(AliHLTEventDDL)) return -EBADF; |
89413559 | 194 | if (list->Buffer()->fCount!=(unsigned)gkAliHLTDDLListSize) return -EBADF; |
209986b4 | 195 | |
16e6f752 | 196 | AliHLTTriggerMask_t triggerMask=AliHLTCTPData::ActiveTriggers(*trigData); |
197 | AliHLTTriggerMask_t bit0=0x1; | |
209986b4 | 198 | for (int word=0; word<gkAliHLTDDLListSize; word++) { |
199 | for (unsigned bit=0; bit<sizeof(AliHLTUInt32_t)*8; bit++) { | |
89413559 | 200 | if (list->Buffer()->fList[word]&0x1<<bit) { |
209986b4 | 201 | for (int trigger=0; trigger<gkNCTPTriggerClasses; trigger++) { |
202 | if ((triggerMask&(bit0<<trigger))!=0) { | |
203 | histo->Fill(word*sizeof(AliHLTUInt32_t)*8+bit, trigger); | |
204 | } | |
205 | } | |
206 | } | |
207 | } | |
208 | } | |
209 | ||
210 | return 0; | |
211 | } |