1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
// COCOA class header file
//Id: Model.h
//CAT: Model
//
// Utility class that steers the reading of the system description file
// and contains the static data
//
// History: v1.0
// Pedro Arce
#ifndef MODEL_H
#define MODEL_H
#include <vector>
#include <map>
//#include <multimap.h>
#include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
class Entry;
//#include "Alignment/CocoaModel/interface/Entry.h" //temporal
class OpticalObject;
//#include "Alignment/CocoaModel/interface/OpticalObject.h"
class Measurement;
class ALIFileIn;
class FittedEntriesReader;
class OpticalAlignments;
class OpticalAlignMeasurements;
#include "CondFormats/OptAlignObjects/interface/OpticalAlignInfo.h"
enum sectionType {
sectGlobalOptions,
sectParameters,
sectSystemTreeDescription,
sectSystemTreeData,
sectMeasurements,
sectReportOut
};
enum cocoaStatus {
COCOA_Init,
COCOA_ReadingModel,
COCOA_InitFit,
COCOA_FirstIterationInEvent,
COCOA_NextIterationInEvent,
COCOA_FitOK,
COCOA_FitImproving,
COCOA_FitCannotImprove,
COCOA_FitChi2Worsened,
COCOA_FitMatrixNonInversable
};
class Model {
public:
//---------- Constructor / destructor
Model();
~Model() {}
///---------- Gets the only instance of this class
static Model& getInstance();
static cocoaStatus getCocoaStatus() { return theCocoaStatus; }
static void setCocoaStatus(const cocoaStatus cs) { theCocoaStatus = cs; }
static std::string printCocoaStatus(const cocoaStatus cs);
///---------- Read the different sections of the SDF and act accordingly
static void readSystemDescription();
//----------- Build OpticalObjects's from info in XML file
void BuildSystemDescriptionFromOA(OpticalAlignments& optAlig);
OpticalAlignInfo FindOptAlignInfoByType(const ALIstring& type);
//----------- Build Measurements's from info in XML file
void BuildMeasurementsFromOA(OpticalAlignMeasurements& measList);
/// ACCESS STATIC DATA MEMBERS
// static std::map< ALIstring, ALIdouble, std::less<ALIstring> >& Parameters() {
// return theParameters;
// }
static std::vector<std::vector<ALIstring> >& OptODictionary() { return theOptODictionary; }
static std::vector<OpticalObject*>& OptOList() { return theOptOList; }
static std::vector<Entry*>& EntryList() { return theEntryVector; }
static std::vector<Measurement*>& MeasurementList() { return theMeasurementVector; }
static Measurement* getMeasurementByName(const ALIstring& name, ALIbool exists = true);
/// the name of the System Description File
static ALIstring& SDFName() { return theSDFName; }
/// the name of the Measurements File
static ALIstring& MeasFName() { return theMeasFName; }
/// the name of the report File
static ALIstring& ReportFName() { return theReportFName; }
/// the name of the File for storing the matrices
static ALIstring& MatricesFName() { return theMatricesFName; }
///************ ACCESS INFO FROM STATIC DATA
///----- Search a string in theParameters and return 1 if found
static int getParameterValue(const ALIstring& sstr, ALIdouble& val);
///----- Find an OptO name in theOptOList and return a pointer to it
static OpticalObject* getOptOByName(const ALIstring& opto_name);
///----- Find the first OptO of type 'opto_type' in theOptOList and return a pointer to it
static OpticalObject* getOptOByType(const ALIstring& type);
///----- Search an Entry name in the Entry* list and return a pointer to it
static Entry* getEntryByName(const ALIstring& opto_name, const ALIstring& entry_name);
///----- Search an Entry from the full entry path
/// (first substract the name of the OptO and then look in the Entry* list)
static Entry* getEntryByName(const ALIstring& opto_entry_name) {
ALIint slash_pos = opto_entry_name.rfind('/');
ALIint length = opto_entry_name.length();
ALIstring opto_name = opto_entry_name.substr(0, slash_pos);
ALIstring entry_name = opto_entry_name.substr(slash_pos + 1, length);
Entry* entry = getEntryByName(opto_name, entry_name);
return entry;
}
///----- Get from theOptODictionary the list of component OptO types
static ALIbool getComponentOptOTypes(const ALIstring& opto_type, std::vector<ALIstring>& vcomponents);
///----- Get from theOptOList the list of pointers to component OptOs
static ALIbool getComponentOptOs(const ALIstring& opto_name, std::vector<OpticalObject*>& vcomponents);
static struct tm& MeasurementsTime() { return theMeasurementsTime; }
static std::vector<OpticalAlignInfo> getOpticalAlignments() { return theOpticalAlignments; }
///***************** SET DATA MEMBERS
static void addEntryToList(Entry* entry) {
theEntryVector.push_back(entry);
//- std::cout << entry << entry->OptOCurrent()->name() << "ADDENTRY " << entry->name() << " " << EntryList().size() << std::endl;
}
static void addMeasurementToList(Measurement* measadd) {
theMeasurementVector.push_back(measadd);
// std::cout << "ADD MEASUREMENT" << theMeasurementVector.size() << std::endl ;
}
//----- Set the name of the System Description File
static void setSDFName(const ALIstring& name) { theSDFName = name; }
//----- Set the name of the report File
static void setReportFName(const ALIstring& name) { theReportFName = name; }
//----- Set the name of the matrices File
static void setMatricesFName(const ALIstring& name) { theMatricesFName = name; }
static void setMeasurementsTime(struct tm& tim) { theMeasurementsTime = tim; }
static ALIbool readMeasurementsFromFile(ALIstring only1Date = ALIstring(""), ALIstring only1Time = ALIstring(""));
///********** private METHODS
private:
/// Reorder the list of OptOs in a hierarchical structure (tree-like)
static void reorderOptODictionary(const ALIstring& ssearch, std::vector<std::vector<ALIstring> >& OptODictionary2);
/// Read Measurements (to be implemented for reading from an external file the DATA of the measurements)
// static void readMeasurements( ALIFileIn& filein );
/// Build for each measuremnt its link to the OptO that take part in it
static void buildMeasurementsLinksToOptOs();
static void SetValueDisplacementsFromReportOut();
///********** private DATA MEMBERS
/// Only instance of Model
static Model* theInstance;
/// parameters
//- static std::map< ALIstring, ALIdouble, std::less<ALIstring> > theParameters;
/// std::vector of OptOs with components (in tree structure)
static std::vector<std::vector<ALIstring> > theOptODictionary;
/// map of OptO*/type of parent OptO, for navigation down the tree structure
//- static multimap< ALIstring, OpticalObject*, std::less<ALIstring> > theOptOtree;
/// map of OptO*/name of OptO for quick search based on name
// static map< ALIstring, OpticalObject*, std::less<ALIstring> > theOptOList;
static std::vector<OpticalObject*> theOptOList;
/// std::vector of all Entries
static std::vector<Entry*> theEntryVector;
/// std::vector of all Measurements
static std::vector<Measurement*> theMeasurementVector;
/// the name of the System Description File
static ALIstring theSDFName;
/// the name of the Measurements File
static ALIstring theMeasFName;
/// the name of the report File
static ALIstring theReportFName;
/// the name of the File for storing the matrices
static ALIstring theMatricesFName;
///**************** FOR COPYING AN OPTO
public:
//----- Steers the storing of the components of OptO named 'optoname'
static ALIbool createCopyComponentList(const ALIstring& optoname);
//----- Get next object to copy from the stored list of components and copy it
static OpticalObject* nextOptOToCopy();
private:
//----- Stores the components of opto
static ALIbool fillCopyComponentList(const OpticalObject* opto);
//----- List of components of an OptO to copy
static std::vector<OpticalObject*> theOptOsToCopyList;
//----- Iterator of the list of components of an OptO to copy
static std::vector<OpticalObject*>::const_iterator theOptOsToCopyListIterator;
///*************** FOR RANGE STUDIES
public:
static ALIint Ncmslinkrange;
static std::vector<ALIdouble> CMSLinkRangeDetValue;
///*************** FOR CMS LINK SYSTEM (to fit it part by part)
public:
void CMSLinkFit(ALIint cmslink);
private:
void CMSLinkCleanModel();
static void CMSLinkDeleteOptOs();
static void CMSLinkSaveParamFittedSigma(ALIint cmslink);
static void CMSLinkSaveParamFittedValueDisplacement(ALIint cmslink);
static void CMSLinkRecoverParamFittedSigma(ALIint cmslink);
static void CMSLinkRecoverParamFittedValueDisplacement(ALIint cmslink);
static ALIint CMSLinkIteration;
//----- METHODS FOR FITTING IN SEVERAL STEPS
static void deleteOptO(const ALIstring& opto_name);
static void deleteOptO(OpticalObject* opto);
static void saveParamFittedSigma(const ALIstring& opto_name, const ALIstring& entry_name);
static void saveParamFittedCorrelation(const ALIstring& opto_name1,
const ALIstring& entry_name1,
const ALIstring& opto_name2,
const ALIstring& entry_name2);
static void recoverParamFittedSigma(const ALIstring& opto_name, const ALIstring& entry_name, const ALIuint position);
public:
static ALIdouble getParamFittedSigmaVectorItem(const ALIuint position);
static FittedEntriesReader* getFittedEntriesReader() { return theFittedEntriesReader; }
private:
static void cleanParamFittedSigmaVector() {
ALIuint pfsv_size = theParamFittedSigmaVector.size();
for (ALIuint ii = 0; ii < pfsv_size; ii++) {
theParamFittedSigmaVector.pop_back();
}
}
static void cleanParamFittedValueDisplacementMap() {
theParamFittedValueDisplacementMap.erase(theParamFittedValueDisplacementMap.begin(),
theParamFittedValueDisplacementMap.end());
}
static void copyMeasurements(const std::vector<ALIstring>& wl);
private:
static cocoaStatus theCocoaStatus;
static std::vector<ALIdouble> theParamFittedSigmaVector;
static std::map<ALIstring, ALIdouble, std::less<ALIstring> > theParamFittedValueDisplacementMap;
static struct tm theMeasurementsTime;
static FittedEntriesReader* theFittedEntriesReader;
static std::vector<OpticalAlignInfo> theOpticalAlignments;
};
#endif
|