CMS 3D CMS Logo

Time.cc
Go to the documentation of this file.
4 //
6 //
7 #include <initializer_list>
8 #include <vector>
9 #include <map>
10 
11 namespace cond {
12 
13  namespace time {
14  static const std::pair<const char*, TimeType> s_timeTypeMap[] = { std::make_pair("Run", cond::runnumber),
15  std::make_pair("Time", cond::timestamp ),
16  std::make_pair("Lumi", cond::lumiid ),
17  std::make_pair("Hash", cond::hash ),
18  std::make_pair("User", cond::userid ) };
20  if( type==invalid ) return "";
21  return s_timeTypeMap[type].first;
22  }
23 
25  for (auto const &i : s_timeTypeMap)
26  if (name == i.first)
27  return i.second;
28  const cond::TimeTypeSpecs & theSpec = cond::findSpecs( name );
29  return theSpec.type;
30  //throwException( "TimeType \""+name+"\" is unknown.","timeTypeFromName");
31  }
32 
33  Time_t tillTimeFromNextSince( Time_t nextSince, TimeType timeType ){
34  if( timeType != (TimeType)TIMESTAMP ){
35  return nextSince - 1;
36  } else {
37  UnpackedTime unpackedTime = unpack( nextSince );
38  //number of seconds in nanoseconds (avoid multiply and divide by 1e09)
39  Time_t totalSecondsInNanoseconds = ((Time_t)unpackedTime.first)*1000000000;
40  //total number of nanoseconds
41  Time_t totalNanoseconds = totalSecondsInNanoseconds + ((Time_t)(unpackedTime.second));
42  //now decrementing of 1 nanosecond
43  totalNanoseconds--;
44  //now repacking (just change the value of the previous pair)
45  unpackedTime.first = (unsigned int) (totalNanoseconds/1000000000);
46  unpackedTime.second = (unsigned int)(totalNanoseconds - (Time_t)unpackedTime.first*1000000000);
47  return pack(unpackedTime);
48  }
49  }
50 
52  if( tp == TIMESTAMP ) return SINCE_TIME_GROUP_SIZE;
53  if( tp == LUMIID ) return SINCE_LUMI_GROUP_SIZE;
54  if( tp == HASH ) return SINCE_HASH_GROUP_SIZE;
55  return SINCE_RUN_GROUP_SIZE;
56  }
57 
58  // framework conversions
60  switch (timetype) {
61  case RUNNUMBER :
62  return edm::IOVSyncValue( edm::EventID(time,
63  startOrStop ? 0 : edm::EventID::maxEventNumber(),
64  startOrStop ? 0 : edm::EventID::maxEventNumber())
65  );
66  case LUMIID :
67  {
70  l.luminosityBlock(),
71  startOrStop ? 0 : edm::EventID::maxEventNumber())
72  );
73  }
74  case TIMESTAMP :
75  return edm::IOVSyncValue( edm::Timestamp(time));
76  default:
78  }
79  }
80 
82  switch (timetype) {
83  case RUNNUMBER :
84  return time.eventID().run();
85  case LUMIID :
86  {
88  return lum.value();
89  }
90  case TIMESTAMP :
91  return time.time().value();
92  default:
93  return 0;
94  }
95  }
96 
97  // the minimal maximum-time an IOV can extend to
99  switch (timetype) {
100  case RUNNUMBER :
101  // last lumi and event of this run
102  return edm::IOVSyncValue( edm::EventID(time,
105  );
106  case LUMIID :
107  {
108  // the same lumiblock
111  l.luminosityBlock(),
113  );
114  }
115  case TIMESTAMP :
116  // next event ?
118  default:
120  }
121  }
122 
124  switch (timetype) {
125  case RUNNUMBER :
126  // last event of this run
127  return edm::IOVSyncValue(edm::EventID(time.eventID().run(),
130  );
131  case LUMIID :
132  // the same lumiblock
133  return edm::IOVSyncValue(edm::EventID(time.eventID().run(),
134  time.luminosityBlockNumber(),
136  );
137  case TIMESTAMP :
138  // same lumiblock
139  return edm::IOVSyncValue(edm::EventID(time.eventID().run(),
140  time.luminosityBlockNumber(),
142  );
143  default:
145  }
146  }
147 
148  }
149 
150 }
RunNumber_t run() const
Definition: EventID.h:39
type
Definition: HCALResponse.h:21
boost::uint64_t value() const
const EventID & eventID() const
Definition: IOVSyncValue.h:40
static const std::pair< const char *, TimeType > s_timeTypeMap[]
Definition: Time.cc:14
cond::Time_t pack(cond::UnpackedTime iValue)
static constexpr unsigned long SINCE_TIME_GROUP_SIZE
Definition: Time.h:47
static constexpr TimeType RUNNUMBER
Definition: Time.h:34
TimeType
Definition: Time.h:21
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:81
TimeType timeTypeFromName(const std::string &name)
Definition: Time.cc:24
TimeType type
Definition: Time.h:41
edm::IOVSyncValue toIOVSyncValue(cond::Time_t time, TimeType timetype, bool startOrStop)
Definition: Time.cc:59
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:41
RunNumber_t run() const
static constexpr TimeType TIMESTAMP
Definition: Time.h:35
static constexpr unsigned int SINCE_LUMI_GROUP_SIZE
Definition: Time.h:48
static constexpr unsigned int SINCE_HASH_GROUP_SIZE
Definition: Time.h:49
static constexpr TimeType HASH
Definition: Time.h:37
LuminosityBlockNumber_t luminosityBlock() const
static EventNumber_t maxEventNumber()
Definition: EventID.h:111
Time_t tillTimeFromNextSince(Time_t nextSince, TimeType timeType)
Definition: Time.cc:33
cond::Time_t Time_t
Definition: Time.h:18
Definition: plugin.cc:24
const TimeTypeSpecs & findSpecs(std::string const &name)
Definition: Time.cc:33
const Timestamp & time() const
Definition: IOVSyncValue.h:42
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:98
static constexpr unsigned int SINCE_RUN_GROUP_SIZE
Definition: Time.h:45
std::string timeTypeName(TimeType type)
Definition: Time.cc:19
TimeValue_t value() const
Definition: Timestamp.h:56
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:78
static constexpr TimeType LUMIID
Definition: Time.h:36
cond::UnpackedTime UnpackedTime
Definition: Time.h:28
cond::UnpackedTime unpack(cond::Time_t iValue)
Time_t sinceGroupSize(TimeType tp)
Definition: Time.cc:51