CMS 3D CMS Logo

HcalTBSource.cc
Go to the documentation of this file.
1 #include "TFile.h"
2 #include "TTree.h"
8 #include <iostream>
9 
12 
13 using namespace edm;
14 using namespace std;
15 
18  m_quiet(pset.getUntrackedParameter<bool>("quiet", true)),
19  m_onlyRemapped(pset.getUntrackedParameter<bool>("onlyRemapped", false)) {
20  m_tree = nullptr;
21  m_fileCounter = -1;
22  m_file = nullptr;
23  m_i = 0;
24 
25  unpackSetup(pset.getUntrackedParameter<std::vector<std::string> >("streams", std::vector<std::string>()));
26  produces<FEDRawDataCollection>();
27 }
28 
29 void HcalTBSource::unpackSetup(const std::vector<std::string>& params) {
30  for (std::vector<std::string>::const_iterator i = params.begin(); i != params.end(); i++) {
31  unsigned long pos = i->find(':');
32  std::string streamName = i->substr(0, pos);
33  int remapTo = -1;
34  if (pos != std::string::npos)
35  remapTo = atoi(i->c_str() + pos + 1);
36 
37  m_sourceIdRemap.insert(std::pair<std::string, int>(streamName, remapTo));
38  if (remapTo != -1)
39  edm::LogInfo("HCAL") << streamName << " --> " << remapTo << endl;
40  else
41  edm::LogInfo("HCAL") << streamName << " using fedid in file" << endl;
42  }
43 }
44 
46  if (m_file != nullptr) {
47  m_file->Close();
48  m_file = nullptr;
49  m_tree = nullptr;
50  }
51 }
52 
54  if (m_file != nullptr) {
55  m_file->Close();
56  m_file = nullptr;
57  m_tree = nullptr;
58  }
59 
60  // try {
61  m_file = TFile::Open(filename.c_str());
62  if (m_file == nullptr) {
63  edm::LogError("HCAL") << "Unable to open " << filename << endl;
64  m_tree = nullptr;
65  return;
66  }
67 
68  m_tree = (TTree*)m_file->Get("CMSRAW");
69 
70  if (m_tree == nullptr) {
71  m_file->Close();
72  m_file = nullptr;
73  edm::LogError("HCAL") << "Unable to find CMSRAW tree" << endl;
74  return;
75  }
76 
77  if (!m_quiet) {
78  edm::LogInfo("HCAL") << "Opening '" << filename << "' with " << m_tree->GetEntries() << " events.\n";
79  }
80 
81  TObjArray* lb = m_tree->GetListOfBranches();
82  n_chunks = 0;
83  for (int i = 0; i < lb->GetSize(); i++) {
84  TBranch* b = (TBranch*)lb->At(i);
85  if (b == nullptr)
86  continue;
87  if (!strcmp(b->GetClassName(), "CDFEventInfo")) {
88  m_eventInfo = nullptr;
89  b->SetAddress(&m_eventInfo);
90  } else {
91  if (strcmp(b->GetClassName(), "CDFChunk"))
92  continue;
93  if (m_sourceIdRemap.find(b->GetName()) == m_sourceIdRemap.end()) {
94  if (m_onlyRemapped)
95  continue;
96  m_sourceIdRemap.insert(std::pair<std::string, int>(b->GetName(), -1));
97  if (!m_quiet)
98  edm::LogInfo("HCAL") << "Also reading branch " << b->GetName();
99  }
100 
101  m_chunks[n_chunks] = nullptr; // allow ROOT to allocate
102  b->SetAddress(&(m_chunks[n_chunks]));
103  m_chunkIds[n_chunks] = m_sourceIdRemap[b->GetName()];
104  n_chunks++;
105  }
106  }
107  m_i = 0;
108 }
109 
111  bool is_new = false;
112 
113  while (m_tree == nullptr || m_i == m_tree->GetEntries()) {
114  m_fileCounter++;
115  if (m_file != nullptr) {
116  m_file->Close();
117  m_file = nullptr;
118  m_tree = nullptr;
119  }
120  if (m_fileCounter >= int(fileNames(0).size()))
121  return false; // nothing good
123  is_new = true;
124  }
125 
126  if (m_tree == nullptr || m_i == m_tree->GetEntries())
127  return false; //nothing good
128 
129  m_tree->GetEntry(m_i);
130  m_i++;
131 
132  if (m_eventInfo != nullptr) {
133  if (is_new) {
134  if (m_eventInfo->getEventNumber() == 0)
136  else
138  }
139  // ZERO is unacceptable for a run number from a technical point of view
140  id = EventID((m_eventInfo->getRunNumber() == 0 ? 1 : m_eventInfo->getRunNumber()),
141  id.luminosityBlock(),
143  } else {
144  id = EventID(m_fileCounter + 10, id.luminosityBlock(), m_i + 1);
145  }
146  // time is a hack
147  edm::TimeValue_t present_time = presentTime();
148  unsigned long time_between_events = timeBetweenEvents();
149 
150  time = present_time + time_between_events;
151  return true;
152 }
153 
155  auto bare_product = std::make_unique<FEDRawDataCollection>();
156  for (int i = 0; i < n_chunks; i++) {
157  const unsigned char* data = (const unsigned char*)m_chunks[i]->getData();
158  int len = m_chunks[i]->getDataLength() * 8;
159 
160  int natId = m_chunks[i]->getSourceId();
161  int id = (m_chunkIds[i] > 0) ? (m_chunkIds[i]) : (natId);
162 
163  FEDRawData& fed = bare_product->FEDData(id);
164  fed.resize(len);
165  memcpy(fed.data(), data, len);
166 
167  // patch the SourceId...
168  if (natId != id) {
169  unsigned int* header = (unsigned int*)fed.data();
170  header[0] = (header[0] & 0xFFF000FFu) | (id << 8);
171  // TODO: patch CRC after this change!
172  }
173  if (!m_quiet)
174  edm::LogInfo("HCAL") << "Reading " << len << " bytes for FED " << id << std::endl;
175  }
176 
177  e.put(std::move(bare_product));
178 }
179 
181 
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
HcalTBSource::m_quiet
bool m_quiet
Definition: HcalTBSource.h:34
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
HcalTBSource::setRunAndEventInfo
bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &) override
Definition: HcalTBSource.cc:110
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
edm
HLT enums.
Definition: AlignableModifier.h:19
pos
Definition: PixelAliasList.h:18
HcalTBSource::m_onlyRemapped
bool m_onlyRemapped
Definition: HcalTBSource.h:34
edm::InputSourceDescription
Definition: InputSourceDescription.h:21
protons_cff.time
time
Definition: protons_cff.py:35
HcalTBSource::openFile
void openFile(const std::string &filename)
Definition: HcalTBSource.cc:53
printContent_cfi.getData
getData
Definition: printContent_cfi.py:16
edm::IDGeneratorSourceBase< PuttableSourceBase >::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: IDGeneratorSourceBase.h:39
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
FEDRawData
Definition: FEDRawData.h:19
HcalTBSource::m_eventInfo
CDFEventInfo * m_eventInfo
Definition: HcalTBSource.h:40
HcalTBSource::m_fileCounter
int m_fileCounter
Definition: HcalTBSource.h:33
HcalTBSource.h
CDFEventInfo::getRunNumber
UInt_t getRunNumber() const
get the run number
Definition: CDFEventInfo.h:12
CDFChunk::getDataLength
Int_t getDataLength() const
Definition: CDFChunk.h:23
CDFChunk
Definition: CDFChunk.h:7
DEFINE_FWK_INPUT_SOURCE
#define DEFINE_FWK_INPUT_SOURCE(type)
Definition: InputSourceMacros.h:8
HcalTBSource::produce
void produce(edm::Event &e) override
Definition: HcalTBSource.cc:154
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
HcalTBSource::m_chunks
CDFChunk * m_chunks[CHUNK_COUNT]
Definition: HcalTBSource.h:37
b
double b
Definition: hdecay.h:118
HcalTBSource::unpackSetup
void unpackSetup(const std::vector< std::string > &params)
Definition: HcalTBSource.cc:29
funct::true
true
Definition: Factorize.h:173
HcalTBSource::m_file
TFile * m_file
Definition: HcalTBSource.h:32
HcalTBSource::m_chunkIds
int m_chunkIds[CHUNK_COUNT]
Definition: HcalTBSource.h:38
edm::ParameterSet
Definition: ParameterSet.h:47
HcalTBSource
Definition: HcalTBSource.h:21
FEDRawDataCollection.h
HcalTBSource::m_sourceIdRemap
std::map< std::string, int > m_sourceIdRemap
Definition: HcalTBSource.h:39
edm::FromFiles::fileNames
std::vector< std::string > fileNames(unsigned iCatalog) const
Definition: FromFiles.h:22
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
CDFChunk::getSourceId
int getSourceId() const
Definition: CDFChunk.h:24
CDFEventInfo.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalTBSource::m_i
int m_i
Definition: HcalTBSource.h:33
edm::IDGeneratorSourceBase< PuttableSourceBase >::timeBetweenEvents
unsigned int timeBetweenEvents() const
Definition: IDGeneratorSourceBase.h:32
InputSourceMacros.h
CDFEventInfo
Global information about an event such as event number and run number.
Definition: CDFEventInfo.h:8
HcalTBSource::m_eventNumberOffset
int m_eventNumberOffset
Definition: HcalTBSource.h:41
HcalTBSource::~HcalTBSource
~HcalTBSource() override
Definition: HcalTBSource.cc:45
edm::IDGeneratorSourceBase< PuttableSourceBase >::presentTime
TimeValue_t presentTime() const
Definition: IDGeneratorSourceBase.h:31
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ProducerSourceFromFiles
Definition: ProducerSourceFromFiles.h:17
edm::EventAuxiliary::ExperimentType
ExperimentType
Definition: EventAuxiliary.h:18
HcalTBSource::HcalTBSource
HcalTBSource(const edm::ParameterSet &pset, edm::InputSourceDescription const &desc)
Definition: HcalTBSource.cc:16
FEDRawData::resize
void resize(size_t newsize)
Definition: FEDRawData.cc:28
HcalTBSource::m_tree
TTree * m_tree
Definition: HcalTBSource.h:31
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
ClassImp
ClassImp(CDFChunk)
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
CDFChunk.h
edm::EventID
Definition: EventID.h:31
edm::Event
Definition: Event.h:73
CDFEventInfo::getEventNumber
ULong64_t getEventNumber() const
get the event number
Definition: CDFEventInfo.h:16
HcalTBSource::n_chunks
int n_chunks
Definition: HcalTBSource.h:35
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37