3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
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 **************************************************************************/
19 /** @file AliHLTRootFileWriterComponent.cxx
20 @author Matthias Richter
22 @brief Base class for writer components to store data in a ROOT file
26 #include "AliHLTRootFileWriterComponent.h"
30 /** the global object for component registration */
31 AliHLTRootFileWriterComponent gAliHLTRootFileWriterComponent;
33 /** ROOT macro for the implementation of ROOT specific class methods */
34 ClassImp(AliHLTRootFileWriterComponent)
36 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent()
39 fEventID(kAliHLTVoidEventID),
42 // see header file for class documentation
44 // refer to README to build package
46 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
48 // all blocks of one event go into the same file
49 SetMode(kConcatenateBlocks);
52 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent(const AliHLTRootFileWriterComponent&)
55 fEventID(kAliHLTVoidEventID),
58 // see header file for class documentation
59 HLTFatal("copy constructor untested");
62 AliHLTRootFileWriterComponent& AliHLTRootFileWriterComponent::operator=(const AliHLTRootFileWriterComponent&)
64 // see header file for class documentation
65 HLTFatal("assignment operator untested");
69 AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent()
71 // see header file for class documentation
74 int AliHLTRootFileWriterComponent::CloseWriter()
76 // see header file for class documentation
77 if (fCurrentFile!=NULL) {
78 HLTDebug("close root file");
79 TFile* pFile=fCurrentFile; fCurrentFile=NULL;
80 pFile->Close(); delete pFile;
85 int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
86 const AliHLTComponentBlockData* blocks,
87 AliHLTComponentTriggerData& trigData )
89 // see header file for class documentation
91 if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0) {
92 // this is just to get rid of the warning "unused parameter"
94 const TObject* pObj=GetFirstInputObject(kAliHLTAnyDataType);
95 HLTDebug("got first object %p", pObj);
97 while (pObj && iResult>=0) {
98 iResult=WriteObject(evtData.fEventID, pObj);
101 HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str()));
103 pObj=GetNextInputObject();
105 HLTDebug("wrote %d object(s) from %d input blocks to file", count, GetNumberOfInputBlocks());
109 int AliHLTRootFileWriterComponent::ScanArgument(int argc, const char** argv)
111 // see header file for class documentation
112 // no other arguments known
113 if (argc==0 && argv==NULL) {
114 // this is just to get rid of the warning "unused parameter"
120 int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb)
122 // see header file for class documentation
125 HLTDebug("write object %p (%s)", pOb, pOb->GetName());
126 if (CheckMode(kConcatenateEvents) && eventID != fEventID &&
127 fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) {
128 TFile* pFile=fCurrentFile; fCurrentFile=NULL;
129 pFile->Close(); delete pFile;
131 if (fCurrentFile==NULL) {
132 fCurrentFile=OpenFile(eventID, 0);
133 if (fCurrentFile) fEventID=eventID;
145 TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option)
147 // see header file for class documentation
149 TString filename("");
150 if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, filename))>=0 && filename.IsNull()==0) {
151 pFile=new TFile(filename, option);
153 if (pFile->IsZombie()) {
156 HLTError("can not open ROOT file %s", filename.Data());
159 HLTFatal("memory allocation failed");
162 HLTError("failed to build a new file name for event %#8x", eventID);