CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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.compare(i.first) == 0)
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 
51  // framework conversions
53  switch (timetype) {
54  case RUNNUMBER :
55  return edm::IOVSyncValue( edm::EventID(time,
56  startOrStop ? 0 : edm::EventID::maxEventNumber(),
57  startOrStop ? 0 : edm::EventID::maxEventNumber())
58  );
59  case LUMIID :
60  {
63  l.luminosityBlock(),
64  startOrStop ? 0 : edm::EventID::maxEventNumber())
65  );
66  }
67  case TIMESTAMP :
68  return edm::IOVSyncValue( edm::Timestamp(time));
69  default:
71  }
72  }
73 
75  switch (timetype) {
76  case RUNNUMBER :
77  return time.eventID().run();
78  case LUMIID :
79  {
81  return lum.value();
82  }
83  case TIMESTAMP :
84  return time.time().value();
85  default:
86  return 0;
87  }
88  }
89 
90  // the minimal maximum-time an IOV can extend to
92  switch (timetype) {
93  case RUNNUMBER :
94  // last lumi and event of this run
95  return edm::IOVSyncValue( edm::EventID(time,
98  );
99  case LUMIID :
100  {
101  // the same lumiblock
104  l.luminosityBlock(),
106  );
107  }
108  case TIMESTAMP :
109  // next event ?
111  default:
113  }
114  }
115 
117  switch (timetype) {
118  case RUNNUMBER :
119  // last event of this run
120  return edm::IOVSyncValue(edm::EventID(time.eventID().run(),
123  );
124  case LUMIID :
125  // the same lumiblock
126  return edm::IOVSyncValue(edm::EventID(time.eventID().run(),
127  time.luminosityBlockNumber(),
129  );
130  case TIMESTAMP :
131  // same lumiblock
132  return edm::IOVSyncValue(edm::EventID(time.eventID().run(),
133  time.luminosityBlockNumber(),
135  );
136  default:
138  }
139  }
140 
141  }
142 
143 }
RunNumber_t run() const
Definition: EventID.h:39
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
boost::uint64_t value() const
const EventID & eventID() const
Definition: IOVSyncValue.h:42
static const std::pair< const char *, TimeType > s_timeTypeMap[]
Definition: Time.cc:14
cond::Time_t pack(cond::UnpackedTime iValue)
TimeType
Definition: Time.h:21
Time_t fromIOVSyncValue(edm::IOVSyncValue const &time, TimeType timetype)
Definition: Time.cc:74
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:52
LuminosityBlockNumber_t luminosityBlockNumber() const
Definition: IOVSyncValue.h:43
RunNumber_t run() const
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:17
const TimeTypeSpecs & findSpecs(std::string const &name)
Definition: Time.cc:33
const Timestamp & time() const
Definition: IOVSyncValue.h:44
edm::IOVSyncValue limitedIOVSyncValue(Time_t time, TimeType timetype)
Definition: Time.cc:91
std::string timeTypeName(TimeType type)
Definition: Time.cc:19
TimeValue_t value() const
Definition: Timestamp.h:56
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:92
cond::UnpackedTime UnpackedTime
Definition: Time.h:25
cond::UnpackedTime unpack(cond::Time_t iValue)