-
Notifications
You must be signed in to change notification settings - Fork 0
/
neventArray.c
63 lines (58 loc) · 1.5 KB
/
neventArray.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* This is a litte data structure to hold n-events for the n-event generator.
*
* Mark Koennecke, June 2015
*/
#include <stdlib.h>
#include <string.h>
#include "neventArray.h"
pNEventArray createNEventArray(unsigned long count)
{
pNEventArray result = NULL;
result = malloc(sizeof(neventArray));
if(result == NULL){
return result;
}
memset(result,0,sizeof(neventArray));
result->count = count;
result->detectorID = malloc(count*sizeof(int64_t));
result->timeStamp = malloc(count*sizeof(int32_t));
if(result->detectorID == NULL || result->timeStamp == NULL){
killNEventArray(&result);
return NULL;
}
return result;
}
/*--------------------------------------------*/
void killNEventArray(pNEventArray *pself)
{
pNEventArray self = *pself;
if(self != NULL){
if(self->detectorID != NULL){
free(self->detectorID);
}
if(self->timeStamp != NULL){
free(self->timeStamp);
}
free(*pself);
}
}
/*-----------------------------------------------------------*/
/////////////////
// hack
pNEventArray multiplyNEventArray(pNEventArray source, unsigned int factor)
{
pNEventArray result;
int i;
result = createNEventArray(source->count*factor);
if(result == NULL){
return NULL;
}
for(i = 0; i < factor; i++){
memcpy(result->detectorID + factor*source->count,
source->detectorID, source->count*sizeof(int64_t));
memcpy(result->timeStamp + factor*source->count,
source->timeStamp, source->count*sizeof(int32_t));
}
return result;
}