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  std::vector<edm::ParameterSet> names=pset.getUntrackedParameter<std::vector<edm::ParameterSet> >("ChunkNames");
18  std::vector<edm::ParameterSet>::iterator j;
19  for (j=names.begin(); j!=names.end(); j++) {
20  std::string name=j->getUntrackedParameter<std::string>("Name");
21  int num=j->getUntrackedParameter<int>("Number");
23  }
24 
25  file_=0;
26  tree_=0;
27  eventInfo_=0;
28 }
29 
31  char buffer[1024];
32  if (file_!=0) {
33  file_->Write();
34 
35  ri_.setInfo("DAQSofwareRelease","UNKNOWN -- HcalTBWriter");
36  gethostname(buffer,1024);
37  ri_.setInfo("WriterHostname",buffer);
38  ri_.store(file_);
39 
40  file_->Close();
41  file_=0;
42  tree_=0;
43  chunkMap_.clear();
44  eventInfo_=0;
45  }
46 }
47 
50  e.getByType(raw); // assume just one!
51 
52  if (file_==0) {
53  char fname[4096];
54  snprintf(fname,4096, namePattern_.c_str(),e.id().run());
55  edm::LogInfo("HCAL") << "Opening " << fname << " for writing HCAL-format file.";
56  file_=new TFile(fname,"RECREATE");
57  ri_.setInfo("OriginalFile",fname);
58  buildTree(*raw);
59  }
60 
61  // adopt the buffers for writing
62  for (std::map<int,int>::const_iterator i=chunkMap_.begin(); i!=chunkMap_.end(); i++) {
63  CDFChunk* c=chunkList_[i->second];
64  const FEDRawData& frd=raw->FEDData(i->first);
65  c->adoptBuffer((ULong64_t*)frd.data(),frd.size()/8);
66  }
67 
68  // copy the event info bits
69  extractEventInfo(*raw,e.id());
70 
71  // fill the tree
72  tree_->Fill();
73  // release all the buffers
74  for (std::map<int,int>::const_iterator i=chunkMap_.begin(); i!=chunkMap_.end(); i++) {
75  CDFChunk* c=chunkList_[i->second];
76  c->releaseBuffer();
77  }
78 
79 }
80 
82  tree_=new TTree("CMSRAW","CMS Common Data Format Tree");
83  chunkMap_.clear();
84  trigChunk_=-1;
85  int j=0;
86  for (int i=0; i<2048; i++) {
87  const FEDRawData& frd=raw.FEDData(i);
88  if (frd.size()<16) continue; // it's empty... like
89 
90  std::string name;
91  if (blockToName_.find(i)!=blockToName_.end()) name=blockToName_[i];
92  else {
93  char sname[64];
94  snprintf(sname,64,"Chunk%03d",i);
95  name=sname;
96  }
97 
98  CDFChunk* c=new CDFChunk(name.c_str());
99  chunkList_[j]=c;
100  tree_->Branch(name.c_str(),"CDFChunk",&(chunkList_[j]));
101  chunkMap_[i]=j;
102 
103  if (name=="HCAL_Trigger" || name=="SliceTest_Trigger") 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) {
144  const newExtendedTrgMsgBlk* tinfo=(const newExtendedTrgMsgBlk*)(chunkList_[trigChunk_]->getData()+2); // assume 2 64-bit words for the CDF header
145  orbitNo=tinfo->stdBlock.orbitNumber;
146  seqid=tinfo->runNumberSequenceId;
147  FEDHeader head((const unsigned char*)chunkList_[trigChunk_]->getData());
148  bunchNo=head.bxID();
149  l1aNo=head.lvl1ID();
150  }
151 
152  eventInfo_->Set(runno,seqid,eventNo,l1aNo,orbitNo,bunchNo);
153 }
RunNumber_t run() const
Definition: EventID.h:42
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:39
void releaseBuffer()
Definition: CDFChunk.h:11
struct StandardTrgMsgBlkStruct StandardTrgMsgBlk
bool getByType(Handle< PROD > &result) const
Definition: Event.h:398
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:49
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:38
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:40
std::string namePattern_
Definition: HcalTBWriter.h:32
std::map< int, int > chunkMap_
Definition: HcalTBWriter.h:41
CDFChunk * chunkList_[1024]
Definition: HcalTBWriter.h:42
int bxID()
The bunch crossing number.
Definition: FEDHeader.cc:26
long long int num
Definition: procUtils.cc:71
void buildTree(const FEDRawDataCollection &raw)
Definition: HcalTBWriter.cc:81
string fname
main script
void extractEventInfo(const FEDRawDataCollection &raw, const edm::EventID &id)
edm::EventID id() const
Definition: EventBase.h:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
struct newExtendedTrgMsgBlkStruct newExtendedTrgMsgBlk
int lvl1ID()
Level-1 event number generated by the TTC system.
Definition: FEDHeader.cc:22
TFile * file_
Definition: HcalTBWriter.h:37
std::map< int, std::string > blockToName_
Definition: HcalTBWriter.h:34
virtual void analyze(const edm::Event &e, const edm::EventSetup &es)
Definition: HcalTBWriter.cc:48
virtual void endJob()
Definition: HcalTBWriter.cc:30