CMS 3D CMS Logo

rootio_HitPattern.cc
Go to the documentation of this file.
2 
3 /* This file contains the function used to read back v12 versions of HitPatterns from a ROOT file.
4  The function is called by a ROOT IO rule.
5  */
6 
7 using namespace reco;
8 
9 namespace {
10  constexpr unsigned short HitSize = 11;
11  constexpr unsigned short PatternSize = 50;
12  constexpr int MaxHitsV12 = (PatternSize * sizeof(uint16_t) * 8) / HitSize;
13 
14  auto getHitFromOldHitPattern(const uint16_t hitPattern[], const int position) {
15  const uint16_t bitEndOffset = (position + 1) * HitSize;
16  const uint8_t secondWord = (bitEndOffset >> 4);
17  const uint8_t secondWordBits = bitEndOffset & (16 - 1); // that is, bitEndOffset % 32
18  if (secondWordBits >= HitSize) {
19  // full block is in this word
20  const uint8_t lowBitsToTrash = secondWordBits - HitSize;
21  return (hitPattern[secondWord] >> lowBitsToTrash) & ((1 << HitSize) - 1);
22  }
23  const uint8_t firstWordBits = HitSize - secondWordBits;
24  const uint16_t firstWordBlock = hitPattern[secondWord - 1] >> (16 - firstWordBits);
25  const uint16_t secondWordBlock = hitPattern[secondWord] & ((1 << secondWordBits) - 1);
26  return firstWordBlock + (secondWordBlock << firstWordBits);
27  }
28 
29  auto hitTypeFromOldHitPattern(const uint16_t pattern) {
30  // for this version we just have to add a 0 bit to the top of the pattern
31  constexpr unsigned short HitTypeMask = 0x3;
32  constexpr unsigned short HitTypeOffset = 0;
33 
34  constexpr uint16_t VALID_CONST = (uint16_t) TrackingRecHit::valid;
35  constexpr uint16_t MISSING_CONST = (uint16_t) TrackingRecHit::missing;
36  constexpr uint16_t INACTIVE_CONST = (uint16_t) TrackingRecHit::inactive;
37  constexpr uint16_t BAD_CONST = (uint16_t) TrackingRecHit::bad;
38 
39  const uint16_t rawHitType = (pattern >> HitTypeOffset) & HitTypeMask;
40 
42  switch (rawHitType) {
43  case VALID_CONST:
44  hitType = TrackingRecHit::valid;
45  break;
46  case MISSING_CONST:
47  hitType = TrackingRecHit::missing;
48  break;
49  case INACTIVE_CONST:
50  hitType = TrackingRecHit::inactive;
51  break;
52  case BAD_CONST:
53  hitType = TrackingRecHit::bad;
54  break;
55  }
56  return hitType;
57  };
58 }
59 
60 bool
62  uint8_t hitCount,
63  uint8_t beginTrackHits, uint8_t endTrackHits,
64  uint8_t beginInner, uint8_t endInner,
65  uint8_t beginOuter, uint8_t endOuter,
66  HitPattern* newObj) {
67  newObj->clear();
68  bool ret = true;
69  for (int i = 0; i < MaxHitsV12; i++) {
70  uint16_t pattern = getHitFromOldHitPattern(oldHitPattern, i);
71  if (pattern == 0) {
72  break;
73  }
74  if(! newObj->appendHit(pattern, hitTypeFromOldHitPattern(pattern)) ) {
75  ret = false;
76  break;
77  }
78  }
79  newObj->hitCount = hitCount;
80  newObj->beginTrackHits =beginTrackHits;
81  newObj->endTrackHits = endTrackHits;
82  newObj->beginInner = beginInner;
83  newObj->endInner = endInner;
84  newObj->beginOuter = beginOuter;
85  newObj->endOuter = endOuter;
86  return ret;
87 }
uint8_t endInner
Definition: HitPattern.h:516
bool appendHit(const TrackingRecHit &hit, const TrackerTopology &ttopo)
Definition: HitPattern.cc:226
uint8_t beginInner
Definition: HitPattern.h:515
uint8_t beginTrackHits
Definition: HitPattern.h:513
uint8_t endTrackHits
Definition: HitPattern.h:514
uint8_t hitCount
Definition: HitPattern.h:511
uint8_t beginOuter
Definition: HitPattern.h:517
static bool fillNewHitPatternWithOldHitPattern_v12(const uint16_t oldHitPattern[], uint8_t hitCount, uint8_t beginTrackHits, uint8_t endTrackHits, uint8_t beginInner, uint8_t endInner, uint8_t beginOuter, uint8_t endOuter, reco::HitPattern *newObj)
fixed size matrix
static int position[264][3]
Definition: ReadPGInfo.cc:509
uint8_t endOuter
Definition: HitPattern.h:518
#define constexpr