/[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.3 - (hide annotations) (download)
Wed Aug 5 18:48:40 2009 UTC (15 years, 4 months ago) by pam-fi
Branch: MAIN
CVS Tags: v9r00, v9r01
Changes since 1.2: +3 -3 lines
Various minor modifications for compatibility with gcc 4.4, removal of warnings due to mismatch between char* and const char*, bug fix.

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 pam-fi 1.3 * $Id: TofReader.cpp,v 1.2 2008-09-25 09:03:14 mocchiut Exp $
4 mocchiut 1.2 * $Author: mocchiut $
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 pam-fi 1.3 "$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/physics/TofReader.cpp,v 1.2 2008-09-25 09:03:14 mocchiut 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     } else {
89     ERROR = 1;
90     };
91    
92     if (ERROR != 0) {
93 pam-fi 1.3 const char *errmsg;
94 mocchiut 1.1 switch (ERROR){
95     case 1: errmsg = "CRC TOF ERROR";
96     break;
97     default: errmsg = "TOF ERROR CODE UNIDENTIFIED";
98     }
99     oss.str("");
100 mocchiut 1.2 oss << "Tof: Fortran77 function tofunpack: " << errmsg;
101 mocchiut 1.1 msg=oss.str();
102     PamOffLineSW::mainLogUtil->logAll(msg);
103     //ORIGINAL: logger->debug(oss.str().c_str());
104     //marco: better switch to level warning?
105     // PamOffLineSW::mainLogUtil->logWarning(msg);
106     }
107     // In case of "ERROR != 0" the calunpack will take care to set all
108     // parameters to zero
109     //} else {
110     // only for a variable tof->tof1int = evento_.IEV2;
111     // memcpy(tof->tof1int, tofvar_.tof1int, sizeof(tofvar_.tof1int));
112     // printf("tof->tof1int[1] %i \n",tof->tof1int[0]);
113     tof->unpackError = (unsigned short)ERROR;
114    
115     // for (int i = 0; i < 6; i++){
116     // tof->tof1int[i] = tofvar_.tof1int[i];
117     //};
118     // printf("tof->tof1int[2] %i \n",tof->tof1int[1]);
119    
120     memcpy(tof->tdcid, tofvar_.tdcid, sizeof(tof->tdcid));
121     memcpy(tof->evcount, tofvar_.evcount, sizeof(tof->evcount));
122     memcpy(tof->tdcmask, tofvar_.tdcmask, sizeof(tof->tdcmask));
123     memcpy(tof->temp1, tofvar_.temp1, sizeof(tof->temp1));
124     memcpy(tof->temp2, tofvar_.temp2, sizeof(tof->temp2));
125    
126    
127     //--------have to invert array because of FORTRAN <-> C different management of the indexes
128    
129     // int temptofmat[6][12];
130    
131     // memcpy(temptofmat, toftest_.tofmat, sizeof(temptofmat));
132    
133     // for (int i = 0; i < 6; i++){
134     // for (int j = 0; j < 12; j++){
135     // tof->tofmat[j][i] = temptofmat[i][j];
136     // }
137     // }
138    
139     int tmpadc[12][4];
140     int tmptdc[12][4];
141    
142     memcpy(tmpadc, tofvar_.adc, sizeof(tmpadc));
143     memcpy(tmptdc, tofvar_.tdc, sizeof(tmptdc));
144    
145     for (int i = 0; i < 12; i++){
146     for (int j = 0; j < 4; j++){
147     tof->adc[j][i] = tmpadc[i][j];
148     tof->tdc[j][i] = tmptdc[i][j];
149     }
150     }
151    
152     delete [] data;
153     }

  ViewVC Help
Powered by ViewVC 1.1.23