]>
Commit | Line | Data |
---|---|---|
4e8187d8 | 1 | // $Id$ |
79c114b5 | 2 | |
6daf06e2 | 3 | //************************************************************************** |
4e8187d8 | 4 | //* This file is property of and copyright by the * |
6daf06e2 | 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 | //************************************************************************** | |
79c114b5 | 18 | |
4e8187d8 | 19 | /// @file AliHLTRootFileStreamerComponent.cxx |
20 | /// @author Matthias Richter | |
21 | /// @date | |
22 | /// @brief Save objects in a ROOT memory file | |
23 | /// | |
79c114b5 | 24 | |
25 | #include "AliHLTRootFileStreamerComponent.h" | |
26 | #include "TString.h" | |
27 | ||
79c114b5 | 28 | /** ROOT macro for the implementation of ROOT specific class methods */ |
29 | ClassImp(AliHLTRootFileStreamerComponent) | |
30 | ||
31 | AliHLTRootFileStreamerComponent::AliHLTRootFileStreamerComponent() | |
32 | : | |
33 | AliHLTProcessor(), | |
34 | fDataType(kAliHLTVoidDataType), | |
35 | fSpecification(~(AliHLTUInt32_t)0) | |
36 | { | |
4e8187d8 | 37 | // The RootFileStreamer provides a stand alone component to write incoming |
38 | // TObject like structures into a ROOT memory file. A ROOT memory file is | |
39 | // a ROOT file stored in memory instead on disk (AliHLTMemoryFile) The file | |
40 | // is published via the output stream. On the receiver side the file can | |
41 | // be directly written to disk and appears like a normal root file. | |
42 | // | |
43 | // Component ID: \b ROOTFileStreamer <br> | |
44 | // Library: \b libAliHLTUtil.so <br> | |
45 | // Input Data Types: ::kAliHLTAnyDataType <br> | |
46 | // Output Data Types: according to component arguments, | |
47 | // ::kAliHLTVoidDataType by default <br> | |
79c114b5 | 48 | } |
49 | ||
50 | AliHLTRootFileStreamerComponent::~AliHLTRootFileStreamerComponent() | |
51 | { | |
4e8187d8 | 52 | // destructor |
79c114b5 | 53 | } |
54 | ||
4e8187d8 | 55 | void AliHLTRootFileStreamerComponent::GetInputDataTypes( AliHLTComponentDataTypeList& list) |
79c114b5 | 56 | { |
4e8187d8 | 57 | // overloaded from AliHLTComponent |
79c114b5 | 58 | list.clear(); |
6daf06e2 | 59 | list.push_back(kAliHLTAllDataTypes); |
79c114b5 | 60 | } |
61 | ||
62 | AliHLTComponentDataType AliHLTRootFileStreamerComponent::GetOutputDataType() | |
63 | { | |
4e8187d8 | 64 | // overloaded from AliHLTComponent |
79c114b5 | 65 | return fDataType; |
66 | } | |
67 | ||
68 | void AliHLTRootFileStreamerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) | |
69 | { | |
4e8187d8 | 70 | // overloaded from AliHLTComponent |
79c114b5 | 71 | constBase=500; |
72 | inputMultiplier=5.0; | |
73 | } | |
74 | ||
75 | int AliHLTRootFileStreamerComponent::DoInit( int argc, const char** argv ) | |
76 | { | |
4e8187d8 | 77 | // overloaded from AliHLTComponent: initialization |
79c114b5 | 78 | |
79 | int iResult=0; | |
80 | TString argument=""; | |
81 | int bMissingParam=0; | |
82 | for (int i=0; i<argc && iResult>=0; i++) { | |
83 | argument=argv[i]; | |
84 | if (argument.IsNull()) continue; | |
85 | ||
86 | // -datatype | |
87 | if (argument.CompareTo("-datatype")==0) { | |
88 | if ((bMissingParam=(++i>=argc))) break; | |
89 | memcpy(&fDataType.fID, argv[i], TMath::Min(kAliHLTComponentDataTypefIDsize, (Int_t)strlen(argv[i]))); | |
90 | if ((bMissingParam=(++i>=argc))) break; | |
91 | memcpy(&fDataType.fOrigin, argv[i], TMath::Min(kAliHLTComponentDataTypefOriginSize, (Int_t)strlen(argv[i]))); | |
92 | ||
93 | // -dataspec | |
94 | } else if (argument.CompareTo("-dataspec")==0) { | |
95 | if ((bMissingParam=(++i>=argc))) break; | |
96 | TString parameter(argv[i]); | |
97 | parameter.Remove(TString::kLeading, ' '); // remove all blanks | |
98 | if (parameter.IsDigit()) { | |
99 | fSpecification=(AliHLTUInt32_t)parameter.Atoi(); | |
100 | } else if (parameter.BeginsWith("0x") && | |
101 | parameter.Replace(0,2,"",0).IsHex()) { | |
102 | sscanf(parameter.Data(),"%x", &fSpecification); | |
103 | } else { | |
104 | HLTError("wrong parameter for argument %s, number expected", argument.Data()); | |
105 | iResult=-EINVAL; | |
106 | } | |
107 | } else { | |
108 | HLTError("unknown argument %s", argument.Data()); | |
109 | break; | |
110 | } | |
111 | } | |
112 | if (bMissingParam) { | |
113 | HLTError("missing parameter for argument %s", argument.Data()); | |
114 | iResult=-EINVAL; | |
115 | } | |
116 | return iResult; | |
117 | } | |
118 | ||
298ef463 | 119 | int AliHLTRootFileStreamerComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, |
79c114b5 | 120 | AliHLTComponentTriggerData& /*trigData*/ ) |
121 | { | |
4e8187d8 | 122 | // overloaded from AliHLTProcessor: event processing |
79c114b5 | 123 | int iResult=0; |
124 | AliHLTMemoryFile* pFile=CreateMemoryFile(fDataType,fSpecification); | |
125 | if (pFile) { | |
79c114b5 | 126 | int count=0; |
6daf06e2 | 127 | for (const TObject* pObj=GetFirstInputObject(); |
128 | pObj && iResult>=0; | |
129 | pObj=GetNextInputObject()) { | |
79c114b5 | 130 | iResult=Write(pFile, pObj); |
131 | if (iResult) { | |
132 | count++; | |
133 | HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str())); | |
134 | } | |
79c114b5 | 135 | } |
136 | HLTInfo("wrote %d object(s) from %d input blocks to file", count, GetNumberOfInputBlocks()); | |
137 | iResult=CloseMemoryFile(pFile); | |
138 | } else { | |
139 | iResult=-ENOMEM; | |
140 | } | |
141 | return iResult; | |
142 | } |