CMS 3D CMS Logo

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