CMS 3D CMS Logo

HcalTBWriter.cc
Go to the documentation of this file.
1 #include <TFile.h>
2 #include <TTree.h>
8 #include <unistd.h>
10 
12  : namePattern_(pset.getUntrackedParameter<std::string>("FilenamePattern", "/tmp/HTB_%06d.root")) {
13  tok_raw_ = consumes<FEDRawDataCollection>(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag"));
14 
15  std::vector<edm::ParameterSet> names = pset.getUntrackedParameter<std::vector<edm::ParameterSet> >("ChunkNames");
16  std::vector<edm::ParameterSet>::iterator j;
17  for (j = names.begin(); j != names.end(); j++) {
18  std::string name = j->getUntrackedParameter<std::string>("Name");
19  int num = j->getUntrackedParameter<int>("Number");
21  }
22 
23  file_ = nullptr;
24  tree_ = nullptr;
25  eventInfo_ = nullptr;
26 }
27 
29  char buffer[1024];
30  if (file_ != nullptr) {
31  file_->Write();
32 
33  ri_.setInfo("DAQSofwareRelease", "UNKNOWN -- HcalTBWriter");
34  gethostname(buffer, 1024);
35  ri_.setInfo("WriterHostname", buffer);
36  ri_.store(file_);
37 
38  file_->Close();
39  file_ = nullptr;
40  tree_ = nullptr;
41  chunkMap_.clear();
42  eventInfo_ = nullptr;
43  }
44 }
45 
48  e.getByToken(tok_raw_, raw);
49 
50  if (file_ == nullptr) {
51  char fname[4096];
52  snprintf(fname, 4096, namePattern_.c_str(), e.id().run());
53  edm::LogInfo("HCAL") << "Opening " << fname << " for writing HCAL-format file.";
54  file_ = new TFile(fname, "RECREATE");
55  ri_.setInfo("OriginalFile", fname);
56  buildTree(*raw);
57  }
58 
59  // adopt the buffers for writing
60  for (std::map<int, int>::const_iterator i = chunkMap_.begin(); i != chunkMap_.end(); i++) {
61  CDFChunk* c = chunkList_[i->second];
62  const FEDRawData& frd = raw->FEDData(i->first);
63  c->adoptBuffer((ULong64_t*)frd.data(), frd.size() / 8);
64  }
65 
66  // copy the event info bits
67  extractEventInfo(*raw, e.id());
68 
69  // fill the tree
70  tree_->Fill();
71  // release all the buffers
72  for (std::map<int, int>::const_iterator i = chunkMap_.begin(); i != chunkMap_.end(); i++) {
73  CDFChunk* c = chunkList_[i->second];
74  c->releaseBuffer();
75  }
76 }
77 
79  tree_ = new TTree("CMSRAW", "CMS Common Data Format Tree");
80  chunkMap_.clear();
81  trigChunk_ = -1;
82  int j = 0;
83  for (int i = 0; i < 2048; i++) {
84  const FEDRawData& frd = raw.FEDData(i);
85  if (frd.size() < 16)
86  continue; // it's empty... like
87 
89  if (blockToName_.find(i) != blockToName_.end())
90  name = blockToName_[i];
91  else {
92  char sname[64];
93  snprintf(sname, 64, "Chunk%03d", i);
94  name = sname;
95  }
96 
97  CDFChunk* c = new CDFChunk(name.c_str());
98  chunkList_[j] = c;
99  tree_->Branch(name.c_str(), "CDFChunk", &(chunkList_[j]));
100  chunkMap_[i] = j;
101 
102  if (name == "HCAL_Trigger" || name == "SliceTest_Trigger")
103  trigChunk_ = j;
104 
105  j++;
106  }
107  eventInfo_ = new CDFEventInfo();
108  tree_->Branch("CDFEventInfo", "CDFEventInfo", &eventInfo_, 16000, 2);
109 }
110 
111 typedef struct StandardTrgMsgBlkStruct {
112  uint32_t orbitNumber;
113  uint32_t eventNumber;
114  uint32_t flags_daq_ttype;
115  uint32_t algo_bits_3;
116  uint32_t algo_bits_2;
117  uint32_t algo_bits_1;
118  uint32_t algo_bits_0;
119  uint32_t tech_bits;
120  uint32_t gps_1234;
121  uint32_t gps_5678;
123 
126  uint32_t triggerWord;
129  uint32_t spillNumber;
130  uint32_t runNumber;
132  uint32_t eventStatus;
134 
136  int runno = id.run();
137  const char* seqid = "";
138  int eventNo = id.event();
139  int l1aNo = eventNo;
140  int orbitNo = 0;
141  int bunchNo = 0;
142 
143  if (trigChunk_ >= 0) {
145  2); // assume 2 64-bit words for the CDF header
146  orbitNo = tinfo->stdBlock.orbitNumber;
147  seqid = tinfo->runNumberSequenceId;
148  FEDHeader head((const unsigned char*)chunkList_[trigChunk_]->getData());
149  bunchNo = head.bxID();
150  l1aNo = head.lvl1ID();
151  }
152 
153  eventInfo_->Set(runno, seqid, eventNo, l1aNo, orbitNo, bunchNo);
154 }
155 
157 #include <cstdint>
158 
HcalTBWriter::tree_
TTree * tree_
Definition: HcalTBWriter.h:38
FEDNumbering.h
StandardTrgMsgBlkStruct
Definition: HcalTBWriter.cc:111
mps_fire.i
i
Definition: mps_fire.py:355
HcalTBWriter::blockToName_
std::map< int, std::string > blockToName_
Definition: HcalTBWriter.h:34
MessageLogger.h
HcalTBWriter::ri_
CDFRunInfo ri_
Definition: HcalTBWriter.h:40
StandardTrgMsgBlk
struct StandardTrgMsgBlkStruct StandardTrgMsgBlk
HcalTBWriter::namePattern_
std::string namePattern_
Definition: HcalTBWriter.h:32
FEDRawDataCollection
Definition: FEDRawDataCollection.h:18
StandardTrgMsgBlkStruct::orbitNumber
uint32_t orbitNumber
Definition: HcalTBWriter.cc:112
edm::LogInfo
Definition: MessageLogger.h:254
HcalTBWriter::chunkList_
CDFChunk * chunkList_[1024]
Definition: HcalTBWriter.h:42
HcalTBWriter::extractEventInfo
void extractEventInfo(const FEDRawDataCollection &raw, const edm::EventID &id)
Definition: HcalTBWriter.cc:135
StandardTrgMsgBlkStruct::algo_bits_1
uint32_t algo_bits_1
Definition: HcalTBWriter.cc:117
CDFRunInfo::store
void store(TFile *toFile)
Definition: CDFRunInfo.cc:67
HcalTBWriter::tok_raw_
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
Definition: HcalTBWriter.h:44
printContent_cfi.getData
getData
Definition: printContent_cfi.py:16
FEDHeader::lvl1ID
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:15
newExtendedTrgMsgBlkStruct::triggerTime_base
uint32_t triggerTime_base
Definition: HcalTBWriter.cc:128
edm::Handle
Definition: AssociativeIterator.h:50
FEDRawData::data
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
newExtendedTrgMsgBlkStruct::runNumberSequenceId
char runNumberSequenceId[16]
Definition: HcalTBWriter.cc:131
FEDRawData
Definition: FEDRawData.h:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
HcalTBWriter::trigChunk_
int trigChunk_
Definition: HcalTBWriter.h:43
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HcalTBWriter::file_
TFile * file_
Definition: HcalTBWriter.h:37
CDFChunk
Definition: CDFChunk.h:7
newExtendedTrgMsgBlkStruct::eventStatus
uint32_t eventStatus
Definition: HcalTBWriter.cc:132
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
HcalTBWriter::endJob
void endJob() override
Definition: HcalTBWriter.cc:28
newExtendedTrgMsgBlkStruct::triggerWord
uint32_t triggerWord
Definition: HcalTBWriter.cc:126
newExtendedTrgMsgBlkStruct::runNumber
uint32_t runNumber
Definition: HcalTBWriter.cc:130
newExtendedTrgMsgBlkStruct::spillNumber
uint32_t spillNumber
Definition: HcalTBWriter.cc:129
newExtendedTrgMsgBlkStruct::stdBlock
StandardTrgMsgBlk stdBlock
Definition: HcalTBWriter.cc:125
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
StandardTrgMsgBlkStruct::gps_5678
uint32_t gps_5678
Definition: HcalTBWriter.cc:121
edm::ParameterSet
Definition: ParameterSet.h:36
StandardTrgMsgBlkStruct::algo_bits_3
uint32_t algo_bits_3
Definition: HcalTBWriter.cc:115
StandardTrgMsgBlkStruct::gps_1234
uint32_t gps_1234
Definition: HcalTBWriter.cc:120
visualization-live-secondInstance_cfg.runno
runno
Definition: visualization-live-secondInstance_cfg.py:73
CDFEventInfo::Set
void Set(UInt_t runNo, const char *seqid, ULong64_t eventNo, UInt_t l1aNo, ULong64_t orbitNo, UInt_t bunchNo)
setter routine
Definition: CDFEventInfo.h:24
HcalTBWriter.h
edm::EventSetup
Definition: EventSetup.h:57
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
newExtendedTrgMsgBlk
struct newExtendedTrgMsgBlkStruct newExtendedTrgMsgBlk
CDFEventInfo.h
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
FEDHeader::bxID
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:17
CDFEventInfo
Global information about an event such as event number and run number.
Definition: CDFEventInfo.h:8
HcalTBWriter::eventInfo_
CDFEventInfo * eventInfo_
Definition: HcalTBWriter.h:39
StandardTrgMsgBlkStruct::flags_daq_ttype
uint32_t flags_daq_ttype
Definition: HcalTBWriter.cc:114
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
std
Definition: JetResolutionObject.h:76
StandardTrgMsgBlkStruct::eventNumber
uint32_t eventNumber
Definition: HcalTBWriter.cc:113
newExtendedTrgMsgBlkStruct
Definition: HcalTBWriter.cc:124
StandardTrgMsgBlkStruct::algo_bits_0
uint32_t algo_bits_0
Definition: HcalTBWriter.cc:118
HcalTBWriter::buildTree
void buildTree(const FEDRawDataCollection &raw)
Definition: HcalTBWriter.cc:78
StandardTrgMsgBlkStruct::tech_bits
uint32_t tech_bits
Definition: HcalTBWriter.cc:119
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
CDFChunk.h
StandardTrgMsgBlkStruct::algo_bits_2
uint32_t algo_bits_2
Definition: HcalTBWriter.cc:116
HcalTBWriter
Definition: HcalTBWriter.h:25
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::EventID
Definition: EventID.h:31
FEDHeader
Definition: FEDHeader.h:14
edm::Event
Definition: Event.h:73
FEDHeader.h
HcalTBWriter::chunkMap_
std::map< int, int > chunkMap_
Definition: HcalTBWriter.h:41
newExtendedTrgMsgBlkStruct::triggerTime_usec
uint32_t triggerTime_usec
Definition: HcalTBWriter.cc:127
edm::InputTag
Definition: InputTag.h:15
HcalTBWriter::analyze
void analyze(const edm::Event &e, const edm::EventSetup &es) override
Definition: HcalTBWriter.cc:46
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
CDFRunInfo::setInfo
void setInfo(const char *key, const char *value)
add some information to the run info
Definition: CDFRunInfo.cc:47
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
HcalTBWriter::HcalTBWriter
HcalTBWriter(const edm::ParameterSet &pset)
Definition: HcalTBWriter.cc:11