]>
Commit | Line | Data |
---|---|---|
4ddfc222 | 1 | // @(#) $Id$ |
2 | ||
6daf06e2 | 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 | //************************************************************************** | |
9be2600f | 18 | |
4ddfc222 | 19 | /** @file AliHLTRootFileWriterComponent.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 "AliHLTRootFileWriterComponent.h" | |
27 | #include "TFile.h" | |
28 | #include "TString.h" | |
626bfcc1 | 29 | #include "TObjectTable.h" // for root object validity |
4ddfc222 | 30 | |
4ddfc222 | 31 | /** ROOT macro for the implementation of ROOT specific class methods */ |
32 | ClassImp(AliHLTRootFileWriterComponent) | |
33 | ||
34 | AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent() | |
35 | : | |
36 | AliHLTFileWriter(), | |
37 | fEventID(kAliHLTVoidEventID), | |
38 | fCurrentFile(NULL) | |
39 | { | |
40 | // see header file for class documentation | |
41 | // or | |
42 | // refer to README to build package | |
43 | // or | |
44 | // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt | |
45 | ||
46 | // all blocks of one event go into the same file | |
47 | SetMode(kConcatenateBlocks); | |
48 | } | |
49 | ||
626bfcc1 | 50 | AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent() |
4ddfc222 | 51 | { |
52 | // see header file for class documentation | |
4ddfc222 | 53 | } |
54 | ||
626bfcc1 | 55 | int AliHLTRootFileWriterComponent::InitWriter() |
4ddfc222 | 56 | { |
57 | // see header file for class documentation | |
4ddfc222 | 58 | |
626bfcc1 | 59 | // choose .root as default extension |
60 | if (GetExtension().IsNull()) SetExtension("root"); | |
61 | return 0; | |
4ddfc222 | 62 | } |
63 | ||
79c114b5 | 64 | int AliHLTRootFileWriterComponent::CloseWriter() |
65 | { | |
66 | // see header file for class documentation | |
67 | if (fCurrentFile!=NULL) { | |
68 | HLTDebug("close root file"); | |
69 | TFile* pFile=fCurrentFile; fCurrentFile=NULL; | |
70 | pFile->Close(); delete pFile; | |
71 | } | |
e83e889b | 72 | return 0; |
79c114b5 | 73 | } |
74 | ||
4ddfc222 | 75 | int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData, |
6daf06e2 | 76 | const AliHLTComponentBlockData* /*blocks*/, |
77 | AliHLTComponentTriggerData& /*trigData*/ ) | |
4ddfc222 | 78 | { |
79 | // see header file for class documentation | |
80 | int iResult=0; | |
4ddfc222 | 81 | int count=0; |
6daf06e2 | 82 | for (const TObject* pObj=GetFirstInputObject(); |
83 | pObj && iResult>=0; | |
84 | pObj=GetNextInputObject()) { | |
4ddfc222 | 85 | iResult=WriteObject(evtData.fEventID, pObj); |
0a94ac22 | 86 | if (iResult == 0) { |
4ddfc222 | 87 | count++; |
88 | HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str())); | |
89 | } | |
4ddfc222 | 90 | } |
79c114b5 | 91 | HLTDebug("wrote %d object(s) from %d input blocks to file", count, GetNumberOfInputBlocks()); |
4ddfc222 | 92 | return iResult; |
93 | } | |
94 | ||
6daf06e2 | 95 | int AliHLTRootFileWriterComponent::ScanArgument(int /*argc*/, const char** /*argv*/) |
4ddfc222 | 96 | { |
97 | // see header file for class documentation | |
98 | // no other arguments known | |
96bda103 | 99 | int iResult=-EINVAL; |
4ddfc222 | 100 | return iResult; |
101 | } | |
102 | ||
103 | int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb) | |
104 | { | |
105 | // see header file for class documentation | |
106 | int iResult=0; | |
107 | if (pOb) { | |
108 | HLTDebug("write object %p (%s)", pOb, pOb->GetName()); | |
eab36f74 | 109 | if (!CheckMode(kConcatenateEvents) && eventID != fEventID && |
4ddfc222 | 110 | fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) { |
111 | TFile* pFile=fCurrentFile; fCurrentFile=NULL; | |
112 | pFile->Close(); delete pFile; | |
113 | } | |
114 | if (fCurrentFile==NULL) { | |
115 | fCurrentFile=OpenFile(eventID, 0); | |
116 | if (fCurrentFile) fEventID=eventID; | |
117 | } | |
118 | if (fCurrentFile) { | |
119 | fCurrentFile->cd(); | |
120 | pOb->Write(); | |
121 | } else { | |
122 | iResult=-EBADF; | |
123 | } | |
124 | } | |
125 | return iResult; | |
126 | } | |
127 | ||
128 | TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option) | |
129 | { | |
130 | // see header file for class documentation | |
131 | TFile* pFile=NULL; | |
132 | TString filename(""); | |
5ab95e9a | 133 | if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, 0, filename))>=0 && filename.IsNull()==0) { |
4ddfc222 | 134 | pFile=new TFile(filename, option); |
135 | if (pFile) { | |
136 | if (pFile->IsZombie()) { | |
137 | delete pFile; | |
138 | pFile=NULL; | |
139 | HLTError("can not open ROOT file %s", filename.Data()); | |
140 | } | |
141 | } else { | |
142 | HLTFatal("memory allocation failed"); | |
143 | } | |
144 | } else { | |
145 | HLTError("failed to build a new file name for event %#8x", eventID); | |
146 | } | |
147 | return pFile; | |
148 | } |