CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TotemRPIncludeAlignments.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kaspar (jan.kaspar@gmail.com)
6 *
7 ****************************************************************************/
8 
15 
20 
21 #include <vector>
22 #include <string>
23 #include <map>
24 #include <set>
25 
26 
34 {
35  public:
37  virtual ~TotemRPIncludeAlignments();
38 
39  std::auto_ptr<RPAlignmentCorrectionsData> produceMeasured(const RPMeasuredAlignmentRecord &);
40  std::auto_ptr<RPAlignmentCorrectionsData> produceReal(const RPRealAlignmentRecord &);
41  std::auto_ptr<RPAlignmentCorrectionsData> produceMisaligned(const RPMisalignedAlignmentRecord &);
42 
43  protected:
44  unsigned int verbosity;
47 
49 
51  RPAlignmentCorrectionsDataSequence Merge(const std::vector<RPAlignmentCorrectionsDataSequence>) const;
52 
54  void PrepareSequence(const std::string &label, RPAlignmentCorrectionsDataSequence &seq, const std::vector<std::string> &files) const;
55 };
56 
57 using namespace std;
58 using namespace edm;
59 
60 //----------------------------------------------------------------------------------------------------
61 //----------------------------------------------------------------------------------------------------
62 
64  verbosity(pSet.getUntrackedParameter<unsigned int>("verbosity", 1))
65 {
66  PrepareSequence("Measured", acsMeasured, pSet.getParameter< vector<string> >("MeasuredFiles"));
67  PrepareSequence("Real", acsReal, pSet.getParameter< vector<string> >("RealFiles"));
68  PrepareSequence("Misaligned", acsMisaligned, pSet.getParameter< vector<string> >("MisalignedFiles"));
69 
73 
74  findingRecord<RPMeasuredAlignmentRecord>();
75  findingRecord<RPRealAlignmentRecord>();
76  findingRecord<RPMisalignedAlignmentRecord>();
77 }
78 
79 //----------------------------------------------------------------------------------------------------
80 
82 {
83 }
84 
85 //----------------------------------------------------------------------------------------------------
86 
87 RPAlignmentCorrectionsDataSequence TotemRPIncludeAlignments::Merge(const vector<RPAlignmentCorrectionsDataSequence> files) const
88 {
89  // find interval boundaries
90  map< TimeValue_t, vector< pair<bool, const RPAlignmentCorrectionsData*> > > bounds;
91 
92  for (vector<RPAlignmentCorrectionsDataSequence>::const_iterator fit = files.begin(); fit != files.end(); ++fit)
93  {
94  for (RPAlignmentCorrectionsDataSequence::const_iterator iit = fit->begin(); iit != fit->end(); ++iit)
95  {
96  const TimeValidityInterval &tvi = iit->first;
97  const RPAlignmentCorrectionsData *corr = & iit->second;
98 
99  bounds[tvi.first].push_back( pair<bool, const RPAlignmentCorrectionsData*>(true, corr) );
100 
101  TimeValue_t delta = (tvi.last != TimeValidityInterval::EndOfTime()) ? (1ULL << 32) : 0; // input resolution is 1s
102  bounds[tvi.last + delta].push_back( pair<bool, const RPAlignmentCorrectionsData*>(false, corr) );
103  }
104  }
105 
106  // build correction sums per interval
107  set<const RPAlignmentCorrectionsData*> accumulator;
109  // bool gap_found = false;
110  for (map< TimeValue_t, vector< pair<bool, const RPAlignmentCorrectionsData*> > >::const_iterator tit = bounds.begin(); tit != bounds.end(); ++tit)
111  {
112  for (vector< pair<bool, const RPAlignmentCorrectionsData*> >::const_iterator cit = tit->second.begin(); cit != tit->second.end(); ++cit)
113  {
114  bool add = cit->first;
115  const RPAlignmentCorrectionsData *corr = cit->second;
116 
117  if (add)
118  accumulator.insert(corr);
119  else
120  accumulator.erase(corr);
121  }
122 
123  map< TimeValue_t, vector< pair<bool, const RPAlignmentCorrectionsData*> > >::const_iterator tit_next = tit;
124  tit_next++;
125  if (tit_next == bounds.end())
126  break;
127 
128  TimeValue_t delta = (tit_next->first != TimeValidityInterval::EndOfTime()) ? 1 : 0; // minimal step
129  TimeValidityInterval tvi(tit->first, tit_next->first - delta);
130 
131  if (verbosity)
132  {
133  printf("\tfirst=%10s, last=%10s: alignment blocks=%li\n",
136  accumulator.size()
137  );
138  }
139 
140  for (set<const RPAlignmentCorrectionsData*>::iterator sit = accumulator.begin(); sit != accumulator.end(); ++sit)
141  result[tvi].AddCorrections(*(*sit));
142  }
143 
144  return result;
145 }
146 
147 //----------------------------------------------------------------------------------------------------
148 
149 void TotemRPIncludeAlignments::PrepareSequence(const string &label, RPAlignmentCorrectionsDataSequence &seq, const vector<string> &files) const
150 {
151  if (verbosity)
152  printf(">> TotemRPIncludeAlignments::PrepareSequence(%s)\n", label.c_str());
153 
154  vector<RPAlignmentCorrectionsDataSequence> sequences;
155  for (unsigned int i = 0; i < files.size(); i++)
156  sequences.push_back(RPAlignmentCorrectionsDataSequence(files[i]));
157 
158  seq = Merge(sequences);
159 }
160 
161 //----------------------------------------------------------------------------------------------------
162 
163 std::auto_ptr<RPAlignmentCorrectionsData> TotemRPIncludeAlignments::produceMeasured(const RPMeasuredAlignmentRecord &iRecord)
164 {
165  std::auto_ptr<RPAlignmentCorrectionsData> alignments(new RPAlignmentCorrectionsData(acMeasured));
166  return alignments;
167 }
168 
169 //----------------------------------------------------------------------------------------------------
170 
171 std::auto_ptr<RPAlignmentCorrectionsData> TotemRPIncludeAlignments::produceReal(const RPRealAlignmentRecord &iRecord)
172 {
173  std::auto_ptr<RPAlignmentCorrectionsData> alignments(new RPAlignmentCorrectionsData(acReal));
174  return alignments;
175 }
176 
177 //----------------------------------------------------------------------------------------------------
178 
179 std::auto_ptr<RPAlignmentCorrectionsData> TotemRPIncludeAlignments::produceMisaligned(const RPMisalignedAlignmentRecord &iRecord)
180 {
181  std::auto_ptr<RPAlignmentCorrectionsData> alignments(new RPAlignmentCorrectionsData(acMisaligned));
182  return alignments;
183 }
184 
185 //----------------------------------------------------------------------------------------------------
186 
188  const IOVSyncValue& iosv, ValidityInterval& valInt)
189 {
190  if (verbosity)
191  {
192  printf(">> TotemRPIncludeAlignments::setIntervalFor(%s)\n", key.name());
193  time_t unixTime = iosv.time().unixTime();
194  char timeStr[50];
195  strftime(timeStr, 50, "%F %T", localtime(&unixTime));
196  printf("\trun=%u, event=%llu, UNIX timestamp=%lu (%s)\n", iosv.eventID().run(), iosv.eventID().event(), unixTime, timeStr);
197  }
198 
199  // determine what sequence and corrections should be used
202 
203  if (strcmp(key.name(), "RPMeasuredAlignmentRecord") == 0)
204  {
205  seq = &acsMeasured;
206  corr = &acMeasured;
207  }
208 
209  if (strcmp(key.name(), "RPRealAlignmentRecord") == 0)
210  {
211  seq = &acsReal;
212  corr = &acReal;
213  }
214 
215  if (strcmp(key.name(), "RPMisalignedAlignmentRecord") == 0)
216  {
217  seq = &acsMisaligned;
218  corr = &acMisaligned;
219  }
220 
221  if (seq == NULL)
222  throw cms::Exception("TotemRPIncludeAlignments::setIntervalFor") << "Unknown record " << key.name();
223 
224  // find the corresponding time interval
225  bool next_exists = false;
226  TimeValue_t t = iosv.time().value(), next_start = TimeValidityInterval::EndOfTime();
227 
228  for (RPAlignmentCorrectionsDataSequence::iterator it = seq->begin(); it != seq->end(); ++it)
229  {
230  if (it->first.first <= t && it->first.last >= t)
231  {
232  valInt = ValidityInterval(IOVSyncValue(Timestamp(it->first.first)), IOVSyncValue(Timestamp(it->first.last)));
233  *corr = it->second;
234 
235  if (verbosity)
236  {
237  printf("\tsetting validity interval [%s, %s]\n",
240  );
241  }
242 
243  return;
244  }
245 
246  if (t <= it->first.first)
247  {
248  next_exists = true;
249  next_start = min(next_start, it->first.first);
250  }
251  }
252 
253  // no interval found, set empty corrections
254  *corr = RPAlignmentCorrectionsData();
255 
256  if (!next_exists)
257  valInt = ValidityInterval(iosv, iosv.endOfTime());
258  else
259  valInt = ValidityInterval(iosv, IOVSyncValue(Timestamp(next_start - 1)));
260 
261  if (verbosity)
262  {
263  printf("\tsetting validity interval [%s, %s]\n",
266  );
267  }
268 }
269 
RunNumber_t run() const
Definition: EventID.h:39
dbl * delta
Definition: mlp_gen.cc:36
TotemRPIncludeAlignments(const edm::ParameterSet &p)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
int i
Definition: DBlmapReader.cc:9
Time sequence of alignment corrections.
RPAlignmentCorrectionsDataSequence Merge(const std::vector< RPAlignmentCorrectionsDataSequence >) const
merges an array of sequences to one
const EventID & eventID() const
Definition: IOVSyncValue.h:42
Validity interval in timestamps.
RPAlignmentCorrectionsData acMisaligned
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
std::auto_ptr< RPAlignmentCorrectionsData > produceReal(const RPRealAlignmentRecord &)
A class adding (mis)alignments to geometry (both real and misaligned).
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void add(const std::vector< const T * > &source, std::vector< const T * > &dest)
#define NULL
Definition: scimark2.h:8
RPAlignmentCorrectionsDataSequence acsReal
void setWhatProduced(T *iThis, const es::Label &iLabel=es::Label())
Definition: ESProducer.h:115
RPAlignmentCorrectionsDataSequence acsMeasured
tuple result
Definition: mps_fire.py:83
const IOVSyncValue & last() const
RPAlignmentCorrectionsData acReal
void PrepareSequence(const std::string &label, RPAlignmentCorrectionsDataSequence &seq, const std::vector< std::string > &files) const
builds a sequence of corrections from provided sources and runs a few checks
RPAlignmentCorrectionsData acMeasured
static std::string ValueToUNIXString(const edm::TimeValue_t &v)
unsigned int unixTime() const
Time in seconds since January 1, 1970.
Definition: Timestamp.h:46
std::auto_ptr< RPAlignmentCorrectionsData > produceMeasured(const RPMeasuredAlignmentRecord &)
T min(T a, T b)
Definition: MathUtil.h:58
RPAlignmentCorrectionsDataSequence acsMisaligned
unsigned long long TimeValue_t
Definition: Timestamp.h:28
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
JetCorrectorParameters corr
Definition: classes.h:5
edm::TimeValue_t first
the boundaries (included) of the interval expressed as UNIX timestamps
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
Container for RP alignment corrections. The corrections are stored on two levels - RP and sensor...
std::auto_ptr< RPAlignmentCorrectionsData > produceMisaligned(const RPMisalignedAlignmentRecord &)
const Timestamp & time() const
Definition: IOVSyncValue.h:44
const IOVSyncValue & first() const
static const edm::TimeValue_t EndOfTime()
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
TimeValue_t value() const
Definition: Timestamp.h:56