7 #include "TDirectory.h"
12 #include "EEfeeDataBlock.h"
13 #include "EEfeeRawEvent.h"
14 #include "EEmcEventHeader.h"
24 static const int MaxCommentLen=1024;
26 static TFile *file = NULL ;
27 static TTree *tree = NULL ;
29 static TBranch *beve = NULL ;
30 static TBranch *bhead = NULL ;
37 static int nAutoSave =10000;
38 static char *filename = NULL;
42 eemcfeerootopen_(
long& run,
long& runtime,
char *chfile,
int &nAuto,
int len)
44 char *comment =
new char[MaxCommentLen];
45 char *basefile =
new char[MaxCommentLen];
46 const char *rootdir = getenv(
"MINIROOTDIR");
47 if ( rootdir == NULL ) rootdir=
".";
48 filename =
new char[(len<MaxCommentLen)?MaxCommentLen:len];
51 if(strstr(chfile,
"[BSND ALL]")!=NULL) {
52 fprintf(stderr,
"rootopen: on-line data <[BSND ALL]>\n");
53 sprintf(basefile,
"run%03ld",run);
55 memcpy(basefile,chfile,len);
56 char *isp = strchr(basefile,
' '); *isp = 0x00;
57 fprintf(stderr,
"rootopen: off-line data <%s>\n",basefile);
58 char *idt = strchr(basefile,
'.'); *idt = 0x00;
60 sprintf(filename,
"%s/%s.ez.root",rootdir,basefile);
61 std::time_t utime = runtime;
62 sprintf(comment,
"run:%05ld, time:%s ",run,ctime(&utime));
64 file =
new TFile(filename,
"RECREATE");
65 tree =
new TTree(
"ezstar",
"A tree with FEE events");
70 bhead = tree->Branch(
"head",
"EEmcEventHeader",&ehead,10000,99);
71 beve = tree->Branch(
"eemc" ,
"EEfeeRawEvent",&eve,10000,99);
74 ehead->setRunNumber(run);
75 ehead->setProcessingTime(time(0));
76 ehead->setTimeStamp(runtime);
77 ehead->setComment(comment);
82 fprintf(stderr,
"rootopen: file=%s\n",filename);
83 fprintf(stderr,
"rootopen: comment=%s\n",comment);
84 fprintf(stderr,
"rootopen: nAutoSave=%d\n",nAutoSave);
86 if(basefile)
delete [] basefile;
87 if(comment )
delete [] comment;
93 eemcfeerootfill_(
unsigned short& evtype,
unsigned short& evtoken,
unsigned short& size ,
unsigned short *e,
int &eveID,
int *ierr)
95 UShort_t *head =
new UShort_t[EEfeeDataBlock::DefaultMaxHead];
104 fprintf(stderr,
"EVENT %6dk %6d 0x%04hx\r",evnum/10000,size,evtype);
107 fprintf(stderr,
"\nEVENT %08d %06d 0x%04hx\n",evnum,size,evtype);
113 for(
int k=0; i<size && k<2 ; k++,i++) fprintf(stderr,
"[%03d] 0x%04hx ",i,e[i]);
114 fprintf(stderr,
"\n");
115 for(
int k=0; i<size && k<4 ; k++,i++) fprintf(stderr,
"[%03d/%02d]=0x%04hx ",i,k,e[i]);
116 fprintf(stderr,
"\n");
117 for(
int k=0; i<size && k<128; k++,i++);
119 fprintf(stderr,
"i=%d\n",i);
122 for(
unsigned short *p = e; (p-e)<size; ) {
125 unsigned int wordcnt = *p++;
128 unsigned short token = *p++;
129 unsigned short cratrig = *p++;
132 if(nTotErr%10000==0) {
133 fprintf(stderr,
"eemcfeerootfill: *** token mismatch, \n so far %d-th data blocks in %d events\n",nTotErr, eveID);
134 fprintf(stderr,
" (event token=%hd crate token=%hd)\n",evtoken,token);
137 if(wordcnt>4) wordcnt -= 4;
138 head[EEfeeDataBlock::ERRFLG] = evtype;
139 head[EEfeeDataBlock::WRDCNT] = wordcnt;
140 head[EEfeeDataBlock::TOKEN] = token;
141 head[EEfeeDataBlock::CRATE] = cratrig;
143 b->setDataArray(p,wordcnt);
148 if(cratrig) eve->addFeeDataBlock(b);
153 ehead->setProcessingTime(time(0));
154 ehead->setToken(evtoken);
155 ehead->setEventNumber(eveID);
158 if(evnum%nAutoSave==0) {
161 printf(
"====> ezTree AutoSave done, nEve=%d\n",evnum);
178 fprintf(stderr,
"eemcfeerootclose: file %s written\n",filename);
180 fprintf(stderr,
"eemcfeerootclose: OK (total events=%8d)\n",evnum);
181 if(filename)
delete [] filename;