]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/util/AliHLTEsdCollectorComponent.cxx
bugfix AliHLTCompStatCollector: filling entry 'Level' of the component statistics...
[u/mrichter/AliRoot.git] / HLT / BASE / util / AliHLTEsdCollectorComponent.cxx
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 ClassImp(AliHLTEsdCollectorComponent)
32
33 AliHLTEsdCollectorComponent::AliHLTEsdCollectorComponent()
34   : AliHLTFileWriter()
35   , fpManager(NULL)
36   , fTreeName()
37 {
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   SetMode(kConcatenateEvents);
47 }
48
49 AliHLTEsdCollectorComponent::~AliHLTEsdCollectorComponent()
50 {
51   // see header file for class documentation
52 }
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   if (GetExtension().IsNull()) SetExtension("root");
61
62   if ((fpManager=AliHLTEsdManager::New())) {
63     TString option="-writelocal";
64     if (!GetDirectory().IsNull()) {
65       option+=" -directory=";
66       option+=GetDirectory();
67     }
68     if (!fTreeName.IsNull()) {
69       option+=" -treename=";
70       option+=fTreeName;
71     }
72     iResult=fpManager->SetOption(option.Data());
73   } else {
74     HLTError("can not find AliHLTEsdManager class descriptor");
75     iResult=-ENODEV;
76   }
77
78   return iResult;
79 }
80
81 int AliHLTEsdCollectorComponent::CloseWriter()
82 {
83   // see header file for class documentation
84   if (fpManager!=NULL) {
85     AliHLTEsdManager::Delete(fpManager);
86     fpManager=NULL;
87   }
88   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   if (!IsDataEvent() && !CheckMode(kWriteAllEvents)) return 0;
98   if (!fpManager) return -ENODEV;
99
100   for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock();
101        pBlock && iResult>=0;
102        pBlock=GetNextInputBlock()) {
103     if (pBlock->fDataType!=kAliHLTDataTypeESDObject &&
104         pBlock->fDataType!=kAliHLTDataTypeESDTree) continue;
105     HLTInfo("writing ESD, data type %s event %d", (DataType2Text(pBlock->fDataType).c_str()), GetEventCount());
106     iResult=fpManager->WriteESD(reinterpret_cast<const AliHLTUInt8_t*>(pBlock->fPtr),
107                                 pBlock->fSize, pBlock->fDataType, NULL, GetEventCount());
108   }
109   return iResult;
110 }
111
112 int AliHLTEsdCollectorComponent::ScanArgument(int argc, const char** argv)
113 {
114   // see header file for class documentation
115   if (argc<=0) return 0;
116   int iResult=-EINVAL;
117   int iArg=0;
118   TString argument=argv[iArg];
119
120   // -treename
121   if (argument.CompareTo("-treename")==0) {
122     if (++iArg==argc) {
123       HLTError("expecting parameter for argument '-treename'");
124       iResult=-EPROTO;
125     } else {
126       fTreeName=argv[iArg];
127       iResult=++iArg;
128     }
129   }
130   return iResult;
131 }