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