Changes in classes/DelphesSTDHEPReader.cc [b23e468:1716933] in git
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
classes/DelphesSTDHEPReader.cc
rb23e468 r1716933 34 34 #include <stdio.h> 35 35 #include <errno.h> 36 #include < rpc/types.h>37 #include < rpc/xdr.h>36 #include <stdint.h> 37 #include <string.h> 38 38 39 39 #include "TObjArray.h" … … 45 45 #include "classes/DelphesClasses.h" 46 46 #include "classes/DelphesFactory.h" 47 #include "classes/DelphesXDRReader.h" 47 48 48 49 #include "ExRootAnalysis/ExRootTreeBranch.h" … … 55 56 56 57 DelphesSTDHEPReader::DelphesSTDHEPReader() : 57 fInputFile(0), fInputXDR(0), fBuffer(0), fPDG(0), fBlockType(-1) 58 { 59 fInputXDR = new XDR; 60 fBuffer = new char[kBufferSize*96 + 24]; 58 fInputFile(0), fBuffer(0), fPDG(0), fBlockType(-1) 59 { 60 fBuffer = new uint8_t[kBufferSize*96 + 24]; 61 61 62 62 fPDG = TDatabasePDG::Instance(); … … 68 68 { 69 69 if(fBuffer) delete fBuffer; 70 if(fInputXDR) delete fInputXDR;71 70 } 72 71 … … 76 75 { 77 76 fInputFile = inputFile; 78 xdrstdio_create(fInputXDR, inputFile, XDR_DECODE);77 fReader[0].SetFile(inputFile); 79 78 } 80 79 … … 100 99 TObjArray *partonOutputArray) 101 100 { 101 fReader[0].ReadValue(&fBlockType, 4); 102 102 103 if(feof(fInputFile)) return kFALSE; 103 104 xdr_int(fInputXDR, &fBlockType);105 104 106 105 SkipBytes(4); … … 146 145 //--------------------------------------------------------------------------- 147 146 148 void DelphesSTDHEPReader::SkipBytes( u_int size)147 void DelphesSTDHEPReader::SkipBytes(int size) 149 148 { 150 149 int rc; 151 u_int rndup;150 int rndup; 152 151 153 152 rndup = size % 4; … … 161 160 if(rc != 0 && errno == ESPIPE) 162 161 { 163 xdr_opaque(fInputXDR,fBuffer, size);164 } 165 } 166 167 //--------------------------------------------------------------------------- 168 169 void DelphesSTDHEPReader::SkipArray( u_int elsize)170 { 171 u _int size;172 xdr_u_int(fInputXDR, &size);162 fReader[0].ReadRaw(fBuffer, size); 163 } 164 } 165 166 //--------------------------------------------------------------------------- 167 168 void DelphesSTDHEPReader::SkipArray(int elsize) 169 { 170 uint32_t size; 171 fReader[0].ReadValue(&size, 4); 173 172 SkipBytes(size*elsize); 174 173 } … … 178 177 void DelphesSTDHEPReader::ReadFileHeader() 179 178 { 180 u _int i;179 uint32_t i; 181 180 enum STDHEPVersion {UNKNOWN, V1, V2, V21} version; 182 181 183 182 // version 184 xdr_string(fInputXDR, &fBuffer, 100);183 fReader[0].ReadString(fBuffer, 100); 185 184 if(fBuffer[0] == '\0' || fBuffer[1] == '\0') version = UNKNOWN; 186 185 else if(fBuffer[0] == '1') version = V1; 187 else if(strncmp( fBuffer, "2.01", 4) == 0) version = V21;186 else if(strncmp((char *)fBuffer, "2.01", 4) == 0) version = V21; 188 187 else if(fBuffer[0] == '2') version = V2; 189 188 else version = UNKNOWN; … … 207 206 208 207 // Number of events 209 xdr_u_int(fInputXDR, &fEntries);208 fReader[0].ReadValue(&fEntries, 4); 210 209 211 210 SkipBytes(8); 212 211 213 212 // Number of blocks 214 u _int nBlocks = 0;215 xdr_u_int(fInputXDR, &nBlocks);213 uint32_t nBlocks = 0; 214 fReader[0].ReadValue(&nBlocks, 4); 216 215 217 216 // Number of NTuples 218 u _int nNTuples = 0;217 uint32_t nNTuples = 0; 219 218 if(version != V1) 220 219 { 221 xdr_u_int(fInputXDR, &nNTuples);220 fReader[0].ReadValue(&nNTuples, 4); 222 221 } 223 222 … … 244 243 { 245 244 // version 246 xdr_string(fInputXDR, &fBuffer, 100);247 if(strncmp( fBuffer, "1.00", 4) == 0)245 fReader[0].ReadString(fBuffer, 100); 246 if(strncmp((char *)fBuffer, "1.00", 4) == 0) 248 247 { 249 248 SkipBytes(8); … … 255 254 SkipArray(4); 256 255 } 257 else if(strncmp( fBuffer, "2.00", 4) == 0)256 else if(strncmp((char *)fBuffer, "2.00", 4) == 0) 258 257 { 259 258 SkipBytes(12); … … 272 271 { 273 272 bool skipNTuples = false; 274 u_int skipSize = 4;273 int skipSize = 4; 275 274 276 275 // version 277 xdr_string(fInputXDR, &fBuffer, 100);278 if(strncmp( fBuffer, "2.00", 4) == 0)276 fReader[0].ReadString(fBuffer, 100); 277 if(strncmp((char *)fBuffer, "2.00", 4) == 0) 279 278 { 280 279 skipNTuples = true; 281 280 } 282 else if(strncmp( fBuffer, "3.00", 4) == 0)281 else if(strncmp((char *)fBuffer, "3.00", 4) == 0) 283 282 { 284 283 skipNTuples = true; … … 288 287 SkipBytes(20); 289 288 290 u _int dimBlocks = 0;291 xdr_u_int(fInputXDR, &dimBlocks);292 293 u _int dimNTuples = 0;289 uint32_t dimBlocks = 0; 290 fReader[0].ReadValue(&dimBlocks, 4); 291 292 uint32_t dimNTuples = 0; 294 293 if(skipNTuples) 295 294 { 296 295 SkipBytes(4); 297 xdr_u_int(fInputXDR, &dimNTuples);296 fReader[0].ReadValue(&dimNTuples, 4); 298 297 } 299 298 … … 318 317 { 319 318 // version 320 xdr_string(fInputXDR, &fBuffer, 100);319 fReader[0].ReadString(fBuffer, 100); 321 320 322 321 // skip 5*4 + 2*8 = 36 bytes 323 322 SkipBytes(36); 324 323 325 if((strncmp( fBuffer, "1.", 2) == 0) || (strncmp(fBuffer, "2.", 2) == 0) ||326 (strncmp( fBuffer, "3.", 2) == 0) || (strncmp(fBuffer, "4.", 2) == 0) ||327 (strncmp( fBuffer, "5.00", 4) == 0))324 if((strncmp((char *)fBuffer, "1.", 2) == 0) || (strncmp((char *)fBuffer, "2.", 2) == 0) || 325 (strncmp((char *)fBuffer, "3.", 2) == 0) || (strncmp((char *)fBuffer, "4.", 2) == 0) || 326 (strncmp((char *)fBuffer, "5.00", 4) == 0)) 328 327 { 329 328 return; … … 333 332 SkipArray(1); 334 333 335 if(strncmp( fBuffer, "5.01", 4) == 0)334 if(strncmp((char *)fBuffer, "5.01", 4) == 0) 336 335 { 337 336 return; … … 345 344 void DelphesSTDHEPReader::ReadSTDHEP() 346 345 { 347 u _int idhepSize, isthepSize, jmohepSize, jdahepSize, phepSize, vhepSize;346 uint32_t idhepSize, isthepSize, jmohepSize, jdahepSize, phepSize, vhepSize; 348 347 349 348 // version 350 xdr_string(fInputXDR, &fBuffer, 100);349 fReader[0].ReadString(fBuffer, 100); 351 350 352 351 // Extracting the event number 353 xdr_int(fInputXDR, &fEventNumber);352 fReader[0].ReadValue(&fEventNumber, 4); 354 353 355 354 // Extracting the number of particles 356 xdr_int(fInputXDR, &fEventSize);355 fReader[0].ReadValue(&fEventSize, 4); 357 356 358 357 if(fEventSize >= kBufferSize) … … 364 363 // 4 + 4 + 4 + 4 + 4 + 4 = 96*n + 24 365 364 366 xdr_opaque(fInputXDR, fBuffer, 96*fEventSize + 24); 367 368 idhepSize = ntohl(*(u_int*)(fBuffer)); 369 isthepSize = ntohl(*(u_int*)(fBuffer + 4*1 + 4*1*fEventSize)); 370 jmohepSize = ntohl(*(u_int*)(fBuffer + 4*2 + 4*2*fEventSize)); 371 jdahepSize = ntohl(*(u_int*)(fBuffer + 4*3 + 4*4*fEventSize)); 372 phepSize = ntohl(*(u_int*)(fBuffer + 4*4 + 4*6*fEventSize)); 373 vhepSize = ntohl(*(u_int*)(fBuffer + 4*5 + 4*16*fEventSize)); 365 fReader[0].ReadRaw(fBuffer, 96*fEventSize + 24); 366 367 fReader[1].SetBuffer(fBuffer); 368 fReader[2].SetBuffer(fBuffer + 4*1 + 4*1*fEventSize); 369 fReader[3].SetBuffer(fBuffer + 4*2 + 4*2*fEventSize); 370 fReader[4].SetBuffer(fBuffer + 4*3 + 4*4*fEventSize); 371 fReader[5].SetBuffer(fBuffer + 4*4 + 4*6*fEventSize); 372 fReader[6].SetBuffer(fBuffer + 4*5 + 4*16*fEventSize); 373 374 fReader[1].ReadValue(&idhepSize, 4); 375 fReader[2].ReadValue(&isthepSize, 4); 376 fReader[3].ReadValue(&jmohepSize, 4); 377 fReader[4].ReadValue(&jdahepSize, 4); 378 fReader[5].ReadValue(&phepSize, 4); 379 fReader[6].ReadValue(&vhepSize, 4); 374 380 375 381 if(fEventSize < 0 || … … 392 398 void DelphesSTDHEPReader::ReadSTDHEP4() 393 399 { 394 u _int number;400 uint32_t number; 395 401 396 402 // Extracting the event weight 397 xdr_double(fInputXDR, &fWeight);403 fReader[0].ReadValue(&fWeight, 8); 398 404 399 405 // Extracting alpha QED 400 xdr_double(fInputXDR, &fAlphaQED);406 fReader[0].ReadValue(&fAlphaQED, 8); 401 407 402 408 // Extracting alpha QCD 403 xdr_double(fInputXDR, &fAlphaQCD);409 fReader[0].ReadValue(&fAlphaQCD, 8); 404 410 405 411 // Extracting the event scale 406 xdr_u_int(fInputXDR, &fScaleSize);412 fReader[0].ReadValue(&fScaleSize, 4); 407 413 for(number = 0; number < fScaleSize; ++number) 408 414 { 409 xdr_double(fInputXDR, &fScale[number]);415 fReader[0].ReadValue(&fScale[number], 8); 410 416 } 411 417 … … 450 456 451 457 int number; 452 int pid, status, m1, m2, d1, d2;458 int32_t pid, status, m1, m2, d1, d2; 453 459 double px, py, pz, e, mass; 454 460 double x, y, z, t; 455 461 456 XDR bufferXDR[6];457 xdrmem_create(&bufferXDR[0], fBuffer + 4*1, 4*fEventSize, XDR_DECODE);458 xdrmem_create(&bufferXDR[1], fBuffer + 4*2 + 4*1*fEventSize, 4*fEventSize, XDR_DECODE);459 xdrmem_create(&bufferXDR[2], fBuffer + 4*3 + 4*2*fEventSize, 8*fEventSize, XDR_DECODE);460 xdrmem_create(&bufferXDR[3], fBuffer + 4*4 + 4*4*fEventSize, 8*fEventSize, XDR_DECODE);461 xdrmem_create(&bufferXDR[4], fBuffer + 4*5 + 4*6*fEventSize, 40*fEventSize, XDR_DECODE);462 xdrmem_create(&bufferXDR[5], fBuffer + 4*6 + 4*16*fEventSize, 32*fEventSize, XDR_DECODE);463 464 462 for(number = 0; number < fEventSize; ++number) 465 463 { 466 xdr_int(&bufferXDR[0], &status);467 xdr_int(&bufferXDR[1], &pid);468 xdr_int(&bufferXDR[2], &m1);469 xdr_int(&bufferXDR[2], &m2);470 xdr_int(&bufferXDR[3], &d1);471 xdr_int(&bufferXDR[3], &d2);472 473 xdr_double(&bufferXDR[4], &px);474 xdr_double(&bufferXDR[4], &py);475 xdr_double(&bufferXDR[4], &pz);476 xdr_double(&bufferXDR[4], &e);477 xdr_double(&bufferXDR[4], &mass);478 479 xdr_double(&bufferXDR[5], &x);480 xdr_double(&bufferXDR[5], &y);481 xdr_double(&bufferXDR[5], &z);482 xdr_double(&bufferXDR[5], &t);464 fReader[1].ReadValue(&status, 4); 465 fReader[2].ReadValue(&pid, 4); 466 fReader[3].ReadValue(&m1, 4); 467 fReader[3].ReadValue(&m2, 4); 468 fReader[4].ReadValue(&d1, 4); 469 fReader[4].ReadValue(&d2, 4); 470 471 fReader[5].ReadValue(&px, 8); 472 fReader[5].ReadValue(&py, 8); 473 fReader[5].ReadValue(&pz, 8); 474 fReader[5].ReadValue(&e, 8); 475 fReader[5].ReadValue(&mass, 8); 476 477 fReader[6].ReadValue(&x, 8); 478 fReader[6].ReadValue(&y, 8); 479 fReader[6].ReadValue(&z, 8); 480 fReader[6].ReadValue(&t, 8); 483 481 484 482 candidate = factory->NewCandidate();
Note:
See TracChangeset
for help on using the changeset viewer.