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