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