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 AliHLTEsdCollectorComponent.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 "AliHLTEsdCollectorComponent.h"
27 : #include "AliHLTEsdManager.h"
28 : #include "TString.h"
29 :
30 : /** ROOT macro for the implementation of ROOT specific class methods */
31 8 : ClassImp(AliHLTEsdCollectorComponent)
32 :
33 : AliHLTEsdCollectorComponent::AliHLTEsdCollectorComponent()
34 3 : : AliHLTFileWriter()
35 3 : , fpManager(NULL)
36 3 : , fTreeName()
37 15 : {
38 : // see header file for class documentation
39 : // or
40 : // refer to README to build package
41 : // or
42 : // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
43 :
44 : // all event go into the same file, but there are individual files for
45 : // different data blocks
46 3 : SetMode(kConcatenateEvents);
47 6 : }
48 :
49 : AliHLTEsdCollectorComponent::~AliHLTEsdCollectorComponent()
50 18 : {
51 : // see header file for class documentation
52 9 : }
53 :
54 : int AliHLTEsdCollectorComponent::InitWriter()
55 : {
56 : // see header file for class documentation
57 : int iResult=0;
58 :
59 : // choose .root as default extension
60 0 : if (GetExtension().IsNull()) SetExtension("root");
61 :
62 0 : if ((fpManager=AliHLTEsdManager::New())) {
63 0 : TString option="-writelocal";
64 0 : if (!GetDirectory().IsNull()) {
65 0 : option+=" -directory=";
66 0 : option+=GetDirectory();
67 0 : }
68 0 : if (!fTreeName.IsNull()) {
69 0 : option+=" -treename=";
70 0 : option+=fTreeName;
71 : }
72 0 : iResult=fpManager->SetOption(option.Data());
73 0 : } else {
74 0 : HLTError("can not find AliHLTEsdManager class descriptor");
75 : iResult=-ENODEV;
76 : }
77 :
78 0 : return iResult;
79 0 : }
80 :
81 : int AliHLTEsdCollectorComponent::CloseWriter()
82 : {
83 : // see header file for class documentation
84 0 : if (fpManager!=NULL) {
85 0 : AliHLTEsdManager::Delete(fpManager);
86 0 : fpManager=NULL;
87 0 : }
88 0 : return 0;
89 : }
90 :
91 : int AliHLTEsdCollectorComponent::DumpEvent( const AliHLTComponentEventData& /*evtData*/,
92 : const AliHLTComponentBlockData* /*blocks*/,
93 : AliHLTComponentTriggerData& /*trigData*/ )
94 : {
95 : // see header file for class documentation
96 : int iResult=0;
97 0 : if (!IsDataEvent() && !CheckMode(kWriteAllEvents)) return 0;
98 0 : if (!fpManager) return -ENODEV;
99 :
100 0 : for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
101 0 : pBlock && iResult>=0;
102 0 : pBlock=GetNextInputBlock()) {
103 0 : if (pBlock->fDataType!=kAliHLTDataTypeESDObject &&
104 0 : pBlock->fDataType!=kAliHLTDataTypeESDTree) continue;
105 0 : HLTInfo("writing ESD, data type %s event %d", (DataType2Text(pBlock->fDataType).c_str()), GetEventCount());
106 0 : iResult=fpManager->WriteESD(reinterpret_cast<const AliHLTUInt8_t*>(pBlock->fPtr),
107 0 : pBlock->fSize, pBlock->fDataType, NULL, GetEventCount());
108 0 : }
109 0 : return iResult;
110 0 : }
111 :
112 : int AliHLTEsdCollectorComponent::ScanArgument(int argc, const char** argv)
113 : {
114 : // see header file for class documentation
115 0 : if (argc<=0) return 0;
116 : int iResult=-EINVAL;
117 : int iArg=0;
118 0 : TString argument=argv[iArg];
119 :
120 : // -treename
121 0 : if (argument.CompareTo("-treename")==0) {
122 0 : if (++iArg==argc) {
123 0 : HLTError("expecting parameter for argument '-treename'");
124 : iResult=-EPROTO;
125 0 : } else {
126 0 : fTreeName=argv[iArg];
127 : iResult=++iArg;
128 : }
129 : }
130 : return iResult;
131 0 : }
|