/[PAMELA software]/chewbacca/PamOffLineSW/physics/TofReader.cpp
ViewVC logotype

Annotation of /chewbacca/PamOffLineSW/physics/TofReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Tue Mar 27 08:34:08 2012 UTC (12 years, 8 months ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, HEAD
Changes since 1.3: +8 -3 lines
YodaProfiler v10r00, new retrieve_TLE.sh script

1 mocchiut 1.1 /** @file
2 mocchiut 1.2 * $Source: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/physics/TofReader.cpp,v $
3 mocchiut 1.4 * $Id: TofReader.cpp,v 1.3 2009/08/05 18:48:40 pam-fi Exp $
4     * $Author: pam-fi $
5 mocchiut 1.1 *
6     * Implementation of the CalorimeterReader class.
7     */
8    
9    
10     #include <iostream>
11     #include <string>
12     #include "TofReader.h"
13    
14     extern "C" {
15    
16    
17     extern struct {
18     int tdcid[12];
19     int evcount[12];
20     int tdcmask[12];
21     int adc[4][12];
22     int tdc[4][12];
23     int temp1[12];
24     int temp2[12];
25    
26     } tofvar_;
27    
28     void tofunpack_(unsigned char[], long int*, int*);
29    
30     //Struct per il passaggio di dati da e verso la chiamata fortran
31     }
32    
33     using namespace pamela;
34     using namespace pamela::tof;
35    
36    
37     /**
38     * Constructor.
39     */
40     TofReader::TofReader(void):
41     TechmodelAlgorithm(PacketType::Physics, "TechmodelTofReader") {
42     tof = new TofEvent();
43     }
44    
45     /**
46     * Get a string with the version info of the algorithm.
47     */
48     std::string TofReader::GetVersionInfo(void) const {
49     return
50 mocchiut 1.4 "$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/physics/TofReader.cpp,v 1.3 2009/08/05 18:48:40 pam-fi Exp $";
51 mocchiut 1.1 }
52    
53     /**
54     * Initialize the algorithm with a special run. This will initialize the
55     * event reader routines for all packet types.
56     */
57     void TofReader::Init(PamelaRun *run) {
58     run->WriteSubPacket(this, &tof, tof->Class());
59     }
60    
61     /**
62     * Unpack the tof event from an input file.
63     */
64     void TofReader::RunEvent(int EventNumber) {
65    
66     }
67    
68     /**
69     * Unpack the Tof data event from the physical packet.
70     */
71     void TofReader::RunEvent(int EventNumber, const char subData[], long int length) {
72     std::stringstream oss;
73     string msg;
74    
75     char *data = new char[length];
76     memcpy(data, subData, length);
77     int ERROR = 0;
78    
79     /*unsigned short convdata[length];
80     for (int i = 0; i<length; i++){
81     convdata[i] = (unsigned short)((unsigned char)subData[i]&0xFF);
82     }*/
83    
84    
85     //Call to the routine that unpack tof events
86     if ( length < 500000 && length >= 0 ){
87     tofunpack_((unsigned char*)data, &length, &ERROR);
88 mocchiut 1.4 // printf("qui ERROR %i \n",ERROR);
89 mocchiut 1.1 } else {
90     ERROR = 1;
91     };
92 mocchiut 1.4 // printf("qua ERROR %i \n",ERROR);
93 mocchiut 1.1
94     if (ERROR != 0) {
95 pam-fi 1.3 const char *errmsg;
96 mocchiut 1.1 switch (ERROR){
97     case 1: errmsg = "CRC TOF ERROR";
98     break;
99     default: errmsg = "TOF ERROR CODE UNIDENTIFIED";
100     }
101     oss.str("");
102 mocchiut 1.2 oss << "Tof: Fortran77 function tofunpack: " << errmsg;
103 mocchiut 1.1 msg=oss.str();
104     PamOffLineSW::mainLogUtil->logAll(msg);
105     //ORIGINAL: logger->debug(oss.str().c_str());
106     //marco: better switch to level warning?
107     // PamOffLineSW::mainLogUtil->logWarning(msg);
108     }
109     // In case of "ERROR != 0" the calunpack will take care to set all
110     // parameters to zero
111     //} else {
112     // only for a variable tof->tof1int = evento_.IEV2;
113     // memcpy(tof->tof1int, tofvar_.tof1int, sizeof(tofvar_.tof1int));
114     // printf("tof->tof1int[1] %i \n",tof->tof1int[0]);
115 mocchiut 1.4 // printf("quo ERROR %i \n",ERROR);
116 mocchiut 1.1 tof->unpackError = (unsigned short)ERROR;
117 mocchiut 1.4 // printf("qui unpackError %i \n",tof->unpackError);
118 mocchiut 1.1
119     // for (int i = 0; i < 6; i++){
120     // tof->tof1int[i] = tofvar_.tof1int[i];
121     //};
122     // printf("tof->tof1int[2] %i \n",tof->tof1int[1]);
123    
124     memcpy(tof->tdcid, tofvar_.tdcid, sizeof(tof->tdcid));
125     memcpy(tof->evcount, tofvar_.evcount, sizeof(tof->evcount));
126     memcpy(tof->tdcmask, tofvar_.tdcmask, sizeof(tof->tdcmask));
127     memcpy(tof->temp1, tofvar_.temp1, sizeof(tof->temp1));
128     memcpy(tof->temp2, tofvar_.temp2, sizeof(tof->temp2));
129    
130    
131     //--------have to invert array because of FORTRAN <-> C different management of the indexes
132    
133     // int temptofmat[6][12];
134    
135     // memcpy(temptofmat, toftest_.tofmat, sizeof(temptofmat));
136    
137     // for (int i = 0; i < 6; i++){
138     // for (int j = 0; j < 12; j++){
139     // tof->tofmat[j][i] = temptofmat[i][j];
140     // }
141     // }
142    
143     int tmpadc[12][4];
144     int tmptdc[12][4];
145    
146     memcpy(tmpadc, tofvar_.adc, sizeof(tmpadc));
147     memcpy(tmptdc, tofvar_.tdc, sizeof(tmptdc));
148    
149     for (int i = 0; i < 12; i++){
150     for (int j = 0; j < 4; j++){
151     tof->adc[j][i] = tmpadc[i][j];
152     tof->tdc[j][i] = tmptdc[i][j];
153     }
154     }
155 mocchiut 1.4 // printf("quisx unpackError %i \n",tof->unpackError);
156 mocchiut 1.1
157     delete [] data;
158     }

  ViewVC Help
Powered by ViewVC 1.1.23