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 
StandardTrgMsgBlk stdBlock
CDFEventInfo * eventInfo_
Definition: HcalTBWriter.h:41
edm::EDGetTokenT< FEDRawDataCollection > tok_raw_
Definition: HcalTBWriter.h:46
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
struct StandardTrgMsgBlkStruct StandardTrgMsgBlk
const std::string names[nVars_]
void setInfo(const char *key, const char *value)
add some information to the run info
Definition: CDFRunInfo.cc:47
void store(TFile *toFile)
Definition: CDFRunInfo.cc:67
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
TTree * tree_
Definition: HcalTBWriter.h:40
std::map< int, int > chunkMap_
Definition: HcalTBWriter.h:43
HcalTBWriter(const edm::ParameterSet &pset)
Definition: HcalTBWriter.cc:11
void endJob() override
Definition: HcalTBWriter.cc:28
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Global information about an event such as event number and run number.
Definition: CDFEventInfo.h:8
CDFRunInfo ri_
Definition: HcalTBWriter.h:42
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
std::string namePattern_
Definition: HcalTBWriter.h:34
uint16_t bxID() const
The bunch crossing number.
Definition: FEDHeader.cc:17
Log< level::Info, false > LogInfo
CDFChunk * chunkList_[1024]
Definition: HcalTBWriter.h:44
void buildTree(const FEDRawDataCollection &raw)
Definition: HcalTBWriter.cc:78
string fname
main script
void extractEventInfo(const FEDRawDataCollection &raw, const edm::EventID &id)
struct newExtendedTrgMsgBlkStruct newExtendedTrgMsgBlk
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
void analyze(const edm::Event &e, const edm::EventSetup &es) override
Definition: HcalTBWriter.cc:46
uint32_t lvl1ID() const
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:15
TFile * file_
Definition: HcalTBWriter.h:39
std::map< int, std::string > blockToName_
Definition: HcalTBWriter.h:36