source: trunk/Mars/mfileio/MWriteFitsFile.h@ 14814

Last change on this file since 14814 was 14792, checked in by lyard, 12 years ago
Added fits output for MC data
File size: 6.4 KB
Line 
1#ifndef MARS_MWreitFitsFile
2#define MARS_MWreitFitsFile
3
4#include <list>
5#include <vector>
6#include <map>
7
8#include <TClass.h>
9
10#ifndef MARS_MWriteFile
11#include "MWriteFile.h"
12#endif
13
14#include "MTopFitsGroup.h"
15#include "MFitsArray.h"
16
17
18///////////////////////////////////////////////////////////////////////////////
19// Information of one MParContainer, which data should be written into all or
20// just a few columns of one FITS table
21class MFitsSubTable
22{
23 // the container, which data should be written to the FITS sub-table.
24 MParContainer *fContainer;
25
26 // used only if the Container is defined by its name.
27 // if kTRUE must exist in the MParList of the program
28 // if kFALSE the container is ignored. if it is not in the
29 // MParList of the program
30 Bool_t fMust;
31
32public:
33 MFitsSubTable( Bool_t must)
34 : fContainer(NULL), fMust(must)
35 {}
36
37 MFitsSubTable(MParContainer * container, Bool_t must)
38 : fContainer(container), fMust(must)
39 {}
40
41
42 MFitsSubTable(const MFitsSubTable & subTable)
43 : fContainer(subTable.fContainer), fMust(subTable.fMust)
44 {}
45
46 Bool_t MustHave() {return fMust;}
47 MParContainer * GetContainer() {return fContainer;}
48 void SetContainer(MParContainer * cont)
49 {fContainer = cont;}
50
51};
52
53
54
55///////////////////////////////////////////////////////////////////////////////
56// A class to write data of MParContainer into FITS files.
57class MWriteFitsFile : public MWriteFile
58{
59private:
60 // all (global) currently open top FITS groups.
61 // Note: several instances of MWriteFitsFile can write to the same
62 // top level FITS group (a top level FITS group corresponds to
63 // one ROOT file)
64 static std::map<MUniqueFileId, MTopFitsGroup> fTopFitsGroups;
65
66 // pointer to the top level FITS group of this instance
67 std::map<MUniqueFileId, MTopFitsGroup>::iterator iTopFitsGroup;
68
69 // the key (TString) of following maps is the FITS table name, which
70 // corresponds to one TTree
71
72 // all main FITS table. Children tables to store data of
73 // TClonesArray are not in this map.
74 //ETIENNE ofits objects cannot be copied. So store pointers instead
75 std::map<TString, std::ofits*> fFitsTables;
76
77 // all information needed to write data of TClonesArray to their
78 // own FITS table. Note: one parent FTIS table may have several
79 // children tables, each for one TClonesArray.
80 std::map<TString, std::list<MArrayHelperBase *> > fClHelper;
81
82 // all information about the MParContainer, which data are stored
83 // in the same FITS table. The key of map<TString, MFitsSubTable>
84 // is the class name of the MParContainer
85 std::map<TString, std::map<TString, MFitsSubTable> > fSubTables;
86
87 std::map<TString, std::vector<void*> > fDataPointers;
88 std::map<TString, std::vector<char> > fTypeChars;
89 std::map<TString, std::vector<uint32_t> > fColSizes;
90 std::map<TString, std::vector<uint32_t> > fColWidth;
91 std::map<TString, bool> fTableObjectCreated;
92 std::map<TString, bool> fTableHeaderWritten;
93
94 void DeleteArrayHelper();
95
96 // rule to construct an output file-name from the input-filename
97 TString fRule;
98
99 TString fOpenOption; // RECREATE or NEW
100 TString fGroupName; // name of top level group
101 TString fTitle; // title of top level group
102
103 void OpenTopLevelGroup(const char * fname);
104 void CloseTopLevelGroup();
105
106 Bool_t InitColumns(const TString & tableName,
107 const TString & parentVarName,
108 std::ofits* fitsTable,
109 void * baseAdr,
110 TClass * classDef);
111 void InitSingleColumn(const TString& tableName,
112 uint32_t count,
113 const std::string& typeName,
114 void* dataPointer,
115 const std::string& columnName,
116 const std::string& unit,
117 const std::string& comment);
118 void writeOneRow(const TString& tableName);
119 void InitAttr(const char* attrName,
120 const char* dataType,
121 void* var,
122 const char* unit=NULL,
123 const char* comment=NULL,
124 std::ofits* outFile=NULL);
125
126 // MWrite
127 Bool_t IsFileOpen() const
128 {return iTopFitsGroup != fTopFitsGroups.end();}
129 Bool_t CheckAndWrite();
130 Bool_t GetContainer(MParList *pList);
131 const char *GetFileName() const;
132
133 Int_t PreProcess(MParList *pList);
134 Int_t PostProcess();
135
136 std::string Trim(const std::string &str);
137
138 // MTask
139 Bool_t ReInit(MParList *pList);
140
141 std::vector<std::string> fVetoedColumns;
142 std::map<std::string, uint32_t> fBytesPerSamples;
143
144public:
145
146 //Veto a type-mapping functions and variables
147 Bool_t VetoColumn(const std::string& colName);
148 Bool_t SetBytesPerSample(const std::string& colName, uint32_t numBytes);
149
150 enum FILE_MODE {
151 kMultiFiles,
152 kSingleFile
153 } ;
154
155 MWriteFitsFile(const char *fname,
156 FILE_MODE fileMode = kMultiFiles,
157 const Option_t *opt="RECREATE",
158 const char *name=NULL,
159 const char *title=NULL);
160 //Similar contructor to what MWriteRootFiles takes.
161 //Some of the args are not used: comp as they does not make sense in FITS
162 MWriteFitsFile(const Int_t comp,
163 const char* rule,
164 const Option_t* option="RECREATE",
165 const char* fTitle="Untitled",
166 const char* name=NULL,
167 const char* title=NULL);
168
169 ~MWriteFitsFile();
170
171
172 void AddContainer(const char *cName, const char *tName=NULL, Bool_t must=kTRUE);
173 void AddContainer(MParContainer *cont, const char *tName=NULL, Bool_t must=kTRUE);
174
175
176 void AddTree(const char *name, Bool_t force=kTRUE)
177 {
178 AddContainer(Form("MReport%s", name), name, force);
179 AddContainer(Form("MTime%s", name), name, force);
180 }
181
182 ClassDef(MWriteFitsFile, 0)
183};
184
185
186#endif
Note: See TracBrowser for help on using the repository browser.