]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/BASE/AliHLTRootFileWriterComponent.cxx
Modification of operator=
[u/mrichter/AliRoot.git] / HLT / BASE / AliHLTRootFileWriterComponent.cxx
1 // @(#) $Id$
2
3 /** @file   AliHLTRootFileWriterComponent.cxx
4     @author Matthias Richter
5     @date   
6     @brief  Base class for writer components to store data in a ROOT file
7
8                                                                           */
9
10 #include "AliHLTRootFileWriterComponent.h"
11 #include "TFile.h"
12 #include "TString.h"
13
14 /** the global object for component registration */
15 AliHLTRootFileWriterComponent gAliHLTRootFileWriterComponent;
16
17 /** ROOT macro for the implementation of ROOT specific class methods */
18 ClassImp(AliHLTRootFileWriterComponent)
19
20 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent()
21   :
22   AliHLTFileWriter(),
23   fEventID(kAliHLTVoidEventID),
24   fCurrentFile(NULL)
25 {
26   // see header file for class documentation
27   // or
28   // refer to README to build package
29   // or
30   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
31
32   // all blocks of one event go into the same file
33   SetMode(kConcatenateBlocks);
34 }
35
36 AliHLTRootFileWriterComponent::AliHLTRootFileWriterComponent(const AliHLTRootFileWriterComponent&)
37   :
38   AliHLTFileWriter(),
39   fEventID(kAliHLTVoidEventID),
40   fCurrentFile(NULL)
41 {
42   // see header file for class documentation
43   HLTFatal("copy constructor untested");
44 }
45
46 AliHLTRootFileWriterComponent& AliHLTRootFileWriterComponent::operator=(const AliHLTRootFileWriterComponent&)
47 {
48   // see header file for class documentation
49   HLTFatal("assignment operator untested");
50   return *this;
51 }
52
53 AliHLTRootFileWriterComponent::~AliHLTRootFileWriterComponent()
54 {
55   // see header file for class documentation
56 }
57
58 int AliHLTRootFileWriterComponent::DumpEvent( const AliHLTComponentEventData& evtData,
59                                             const AliHLTComponentBlockData* blocks, 
60                                             AliHLTComponentTriggerData& trigData )
61 {
62   // see header file for class documentation
63   int iResult=0;
64   if (evtData.fStructSize==0 && blocks==NULL && trigData.fStructSize==0) {
65     // this is just to get rid of the warning "unused parameter"
66   }
67   const TObject* pObj=GetFirstInputObject(kAliHLTAnyDataType);
68   HLTDebug("got first object %p", pObj);
69   int count=0;
70   while (pObj && iResult>=0) {
71     iResult=WriteObject(evtData.fEventID, pObj);
72     if (iResult) {
73       count++;
74       HLTDebug("wrote object of class %s, data type %s", pObj->ClassName(), (DataType2Text(GetDataType(pObj)).c_str())); 
75     }
76     pObj=GetNextInputObject();
77   }
78   HLTDebug("wrote %d of %d object(s) to file", count, GetNumberOfInputBlocks());
79   return iResult;
80 }
81
82 int AliHLTRootFileWriterComponent::ScanArgument(int argc, const char** argv)
83 {
84   // see header file for class documentation
85   // no other arguments known
86   if (argc==0 && argv==NULL) {
87     // this is just to get rid of the warning "unused parameter"
88   }
89   int iResult=-EPROTO;
90   return iResult;
91 }
92
93 int AliHLTRootFileWriterComponent::WriteObject(const AliHLTEventID_t eventID, const TObject *pOb)
94 {
95   // see header file for class documentation
96   int iResult=0;
97   if (pOb) {
98     HLTDebug("write object %p (%s)", pOb, pOb->GetName());
99     if (CheckMode(kConcatenateEvents) && eventID != fEventID &&
100         fCurrentFile!=NULL && eventID!=kAliHLTVoidEventID) {
101       TFile* pFile=fCurrentFile; fCurrentFile=NULL;
102       pFile->Close(); delete pFile;
103     }
104     if (fCurrentFile==NULL) {
105       fCurrentFile=OpenFile(eventID, 0);
106       if (fCurrentFile) fEventID=eventID;
107     }
108     if (fCurrentFile) {
109       fCurrentFile->cd();
110       pOb->Write();
111     } else {
112       iResult=-EBADF;
113     }
114   }
115   return iResult;
116 }
117
118 TFile* AliHLTRootFileWriterComponent::OpenFile(const AliHLTEventID_t eventID, const int blockID, const char* option)
119 {
120   // see header file for class documentation
121   TFile* pFile=NULL;
122   TString filename("");
123   if ((BuildFileName(eventID, blockID, kAliHLTVoidDataType, filename))>=0 && filename.IsNull()==0) {
124     pFile=new TFile(filename, option);
125     if (pFile) {
126       if (pFile->IsZombie()) {
127         delete pFile;
128         pFile=NULL;
129         HLTError("can not open ROOT file %s", filename.Data());
130       }
131     } else {
132       HLTFatal("memory allocation failed");
133     }
134   } else {
135     HLTError("failed to build a new file name for event %#8x", eventID);
136   }
137   return pFile;
138 }