Line data Source code
1 : // $Id$
2 :
3 : ///**************************************************************************
4 : ///* This file is property of and copyright by the *
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 AliHLTRootFilePublisherComponent.cxx
20 : /// @author Matthias Richter, Jochen Thaeder
21 : /// @date
22 : /// @brief HLT file publisher component implementation.
23 : ///
24 :
25 : #include "AliHLTRootFilePublisherComponent.h"
26 : #include "AliHLTErrorGuard.h"
27 :
28 : #include "TList.h"
29 : #include "TTree.h"
30 : #include "TKey.h"
31 : #include "TFile.h"
32 :
33 : /** ROOT macro for the implementation of ROOT specific class methods */
34 8 : ClassImp(AliHLTRootFilePublisherComponent)
35 :
36 : /*
37 : * ---------------------------------------------------------------------------------
38 : * Constructor / Destructor
39 : * ---------------------------------------------------------------------------------
40 : */
41 :
42 : // #################################################################################
43 : AliHLTRootFilePublisherComponent::AliHLTRootFilePublisherComponent()
44 3 : : AliHLTFilePublisher()
45 3 : , fpCurrentEvent(NULL)
46 3 : , fObjectName("")
47 15 : {
48 : // publisher component for root file content
49 : // Component ID: \b ROOTFilePublisher <br>
50 : // Library: \b libAliHLTUtil.so <br>
51 : // Input Data Types: none <br>
52 : // Output Data Types: according to arguments <br>
53 :
54 : // Set file to ROOT-File
55 3 : SetIsRawFile( kFALSE );
56 6 : }
57 :
58 : // #################################################################################
59 : AliHLTRootFilePublisherComponent::~AliHLTRootFilePublisherComponent()
60 18 : {
61 : // destructor
62 :
63 : // file list and file name list are owner of their objects and
64 : // delete all the objects
65 9 : }
66 :
67 : /*
68 : * ---------------------------------------------------------------------------------
69 : * Public functions to implement AliHLTComponent's interface.
70 : * These functions are required for the registration process
71 : * ---------------------------------------------------------------------------------
72 : */
73 :
74 : // #################################################################################
75 : const char* AliHLTRootFilePublisherComponent::GetComponentID()
76 : {
77 : // overloaded from AliHLTComponent
78 666 : return "ROOTFilePublisher";
79 : }
80 :
81 : // #################################################################################
82 : AliHLTComponent* AliHLTRootFilePublisherComponent::Spawn()
83 : {
84 : // overloaded from AliHLTComponent
85 0 : return new AliHLTRootFilePublisherComponent;
86 0 : }
87 :
88 : /*
89 : * ---------------------------------------------------------------------------------
90 : * Protected functions to implement AliHLTComponent's interface.
91 : * These functions provide initialization as well as the actual processing
92 : * capabilities of the component.
93 : * ---------------------------------------------------------------------------------
94 : */
95 :
96 : // #################################################################################
97 : Int_t AliHLTRootFilePublisherComponent::ScanArgument(Int_t argc, const char** argv)
98 : {
99 : // scan configuration arguments
100 :
101 : Int_t iResult = 0;
102 :
103 0 : TString argument = "";
104 0 : TString parameter = "";
105 : Int_t bMissingParam = 0;
106 0 : fObjectName = ""; // Reset this to the default: read all objects in the file.
107 :
108 0 : argument=argv[iResult];
109 0 : if (argument.IsNull()) return -EINVAL;
110 :
111 : // -objectname
112 0 : if ( !argument.CompareTo("-objectname") ) {
113 0 : if ( ! (bMissingParam=(++iResult>=argc)) ) {
114 0 : parameter = argv[iResult];
115 0 : parameter.Remove(TString::kLeading, ' '); // remove all blanks
116 0 : fObjectName = parameter;
117 : }
118 : }
119 : else {
120 0 : HLTError("unknown argument %s", argument.Data());
121 : iResult = -EINVAL;
122 : }
123 :
124 0 : if ( bMissingParam ) {
125 0 : HLTError("missing parameter for argument %s", argument.Data());
126 : iResult = -EPROTO;
127 0 : }
128 :
129 0 : return iResult;
130 0 : }
131 :
132 : // #################################################################################
133 : Int_t AliHLTRootFilePublisherComponent::GetEvent( const AliHLTComponentEventData& /*evtData*/,
134 : AliHLTComponentTriggerData& /*trigData*/,
135 : AliHLTUInt8_t* /*outputPtr*/,
136 : AliHLTUInt32_t& size,
137 : AliHLTComponentBlockDataList& /*outputBlocks*/ )
138 : {
139 : // overloaded from AliHLTDataSource: event processing
140 :
141 0 : if ( !IsDataEvent() ) return 0;
142 :
143 : Int_t iResult=0;
144 0 : size=0;
145 :
146 : // -- Ptr to current event
147 0 : TObjLink *lnk = fpCurrentEvent;
148 0 : if ( lnk == NULL) {
149 0 : lnk = GetEventList()->FirstLink();
150 0 : fpCurrentEvent = lnk;
151 0 : }
152 :
153 0 : if ( lnk ) {
154 0 : EventFiles* pEventDesc = dynamic_cast<EventFiles*>( lnk->GetObject() );
155 0 : if (pEventDesc) {
156 :
157 : HLTDebug("publishing files for event %p", pEventDesc);
158 0 : TList& files=*pEventDesc; // type conversion operator defined
159 0 : TObjLink *flnk=files.FirstLink();
160 :
161 0 : while (flnk && iResult>=0) {
162 0 : if (!flnk->GetObject()) {
163 0 : ALIHLTERRORGUARD(5, "internal mismatch in Root list iterator");
164 0 : continue;
165 : }
166 0 : FileDesc* pFileDesc=dynamic_cast<FileDesc*>(flnk->GetObject());
167 0 : if (!pFileDesc) {
168 0 : ALIHLTERRORGUARD(5, "internal mismatch, invalid object type for dynamic_cast");
169 0 : continue;
170 : }
171 :
172 0 : if (not fOpenFilesAtStart) pFileDesc->OpenFile();
173 : TFile* pFile=NULL;
174 :
175 0 : if (pFileDesc && (pFile=*pFileDesc)!=NULL) {
176 :
177 0 : for ( Int_t i = 0; i < pFile->GetListOfKeys()->GetEntries(); i++ ){
178 0 : if (pFile->GetListOfKeys()==NULL || pFile->GetListOfKeys()->At(i)==NULL) {
179 0 : ALIHLTERRORGUARD(5, "internal mismatch in Root key list");
180 0 : continue;
181 : }
182 0 : TKey * key= dynamic_cast<TKey*>( pFile->GetListOfKeys()->At(i) );
183 0 : if (!key) {
184 0 : ALIHLTERRORGUARD(5, "internal mismatch, object not of type TKey");
185 0 : continue;
186 : }
187 :
188 0 : if ( fObjectName != "" ) {
189 0 : if ( !( ((TString) key->GetName()).CompareTo(fObjectName) ) )
190 0 : PushBack( key->ReadObj(), *pFileDesc, *pFileDesc );
191 : }
192 : else
193 0 : PushBack( key->ReadObj(), *pFileDesc, *pFileDesc );
194 : // above : type conversion operator defined for DataType and Spec
195 0 : }
196 :
197 0 : if (not fOpenFilesAtStart) pFileDesc->CloseFile();
198 : } else {
199 0 : HLTError("no file available");
200 : iResult=-EFAULT;
201 : }
202 0 : flnk = flnk->Next();
203 0 : }
204 0 : } else {
205 0 : HLTError("can not get event descriptor from list link");
206 : iResult=-EFAULT;
207 : }
208 0 : } else {
209 : iResult=-ENOENT;
210 : }
211 0 : if (iResult>=0 && fpCurrentEvent) fpCurrentEvent=fpCurrentEvent->Next();
212 :
213 : return iResult;
214 0 : }
|