/[PAMELA software]/yoda/techmodel/physics/CalorimeterReader.cpp
ViewVC logotype

Diff of /yoda/techmodel/physics/CalorimeterReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by kusanagi, Thu Aug 19 15:24:58 2004 UTC revision 5.1 by kusanagi, Sat Feb 4 12:37:46 2006 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Source: /home/cvsmanager/yoda/techmodel/physics/CalorimeterReader.cpp,v $   * $Source: /home/cvsmanager/yoda/techmodel/physics/CalorimeterReader.cpp,v $
3   * $Id: CalorimeterReader.cpp,v 1.1 2004/07/17 20:03:48 kusanagi Exp $   * $Id: CalorimeterReader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $
4   * $Author: kusanagi $   * $Author: Maurizio Nagni $
5   *   *
6   * Implementation of the CalorimeterReader class.   * Implementation of the CalorimeterReader class.
7   */   */
8    
9    
10    #include <iostream>
11  #include <string>  #include <string>
12  #include <log4cpp/Category.hh>  #include <log4cxx/logger.h>
13  #include "CalorimeterReader.h"  #include "CalorimeterReader.h"
14    
15  extern "C" {  extern "C" {
16        
17    
18   extern struct {   extern struct {
19          int IEV2;          int     iev;
20          int stwerr;          int     stwerr[4];
21          int perror;          float   perror[4];
22          int dexy[2][22][96];          float   dexy[2][22][96];
23          int dexyc[2][22][96];          float   dexyc[2][22][96];
24          int base[2][22][96];          float   base[2][22][6];
25          int calselftrig[4][7];          float   calselftrig[4][7];
26          int calIItrig[4];          float   calIItrig[4];
27          int calstripshift[4];          float   calstriphit[4];
28          int calDSPtaberr[4];          float   calDSPtaberr[4];
29          int calevnum[4];          float   calevnum[4];
30      } evento_;      } evento_;
31    
32      void calunpack_(short[], long int*, int*);      void calunpack_(unsigned char[], long int*, int*);
33      //Struct per il passaggio di dati da e verso la chiamata fortran      //Struct per il passaggio di dati da e verso la chiamata fortran
34  }  }
35    
36  using namespace pamela;  using namespace pamela;
37  using namespace pamela::calorimeter;  using namespace pamela::calorimeter;
38    
39  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.calorimeter.CalorimeterReader");    static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.calorimeter.CalorimeterReader"));
40    
41  /**  /**
42   * Constructor.       * Constructor.    
43   */   */
44  CalorimeterReader::CalorimeterReader(void):  CalorimeterReader::CalorimeterReader(void):
45    TechmodelAlgorithm(PacketType::Physics, "TechmodelCalorimeterReader") {    TechmodelAlgorithm(PacketType::Physics, "TechmodelCalorimeterReader") {
46    cat.debug("Constructor");    logger->debug(_T("Construnctor"));
47    calorimeter = new CalorimeterEvent();    calorimeter = new CalorimeterEvent();
48  }  }
49    
# Line 49  CalorimeterReader::CalorimeterReader(voi Line 52  CalorimeterReader::CalorimeterReader(voi
52   */   */
53  std::string CalorimeterReader::GetVersionInfo(void) const {  std::string CalorimeterReader::GetVersionInfo(void) const {
54    return    return
55      "$Header: /home/cvsmanager/yoda/techmodel/physics/CalorimeterReader.cpp,v 1.1 2004/07/17 20:03:48 kusanagi Exp $";      "$Header: /home/cvsmanager/yoda/techmodel/physics/CalorimeterReader.cpp,v 5.0 2005/08/29 09:46:13 Maurizio Nagni Exp $";
56  }  }
57    
58  /**  /**
# Line 57  std::string CalorimeterReader::GetVersio Line 60  std::string CalorimeterReader::GetVersio
60   * event reader routines for all packet types.   * event reader routines for all packet types.
61   */   */
62  void CalorimeterReader::Init(PamelaRun *run) {  void CalorimeterReader::Init(PamelaRun *run) {
63      logger->debug(_T("Initialize"));
64    SetInputStream(run);    SetInputStream(run);
65    run->WriteSubPacket(this, &calorimeter, calorimeter->Class());    run->WriteSubPacket(this, &calorimeter, calorimeter->Class());
66  }  }
# Line 72  void CalorimeterReader::RunEvent(int Eve Line 76  void CalorimeterReader::RunEvent(int Eve
76   * Unpack the Calorimeter data event from the physical packet.   * Unpack the Calorimeter data event from the physical packet.
77   */   */
78  void CalorimeterReader::RunEvent(int EventNumber, const char subData[], long int length) {  void CalorimeterReader::RunEvent(int EventNumber, const char subData[], long int length) {
79      char data[length];      std::stringstream oss;      
80        char *data = new char[length];
81      memcpy(data, subData, length);      memcpy(data, subData, length);
82      int  ERROR = 0;      int  ERROR = 0;
83            
84      unsigned short convdata[length];      /*unsigned short convdata[length];
85      for (int i = 0; i<length; i++){      for (int i = 0; i<length; i++){
86          convdata[i] = (unsigned short)((unsigned char)subData[i]&0xFF);          convdata[i] = (unsigned short)((unsigned char)subData[i]&0xFF);
     }  
           
     //Call to the routine that unpack calorimeter events  
     calunpack_((short*)convdata, &length, &ERROR);  
       
     /*switch (ERROR){  
         case:  
87      }*/      }*/
88                
89      calorimeter->IEV2   = evento_.IEV2;      //Call to the routine that unpack calorimeter events
90      calorimeter->stwerr = evento_.stwerr;      calunpack_((unsigned char*)data, &length, &ERROR);
91      calorimeter->perror = evento_.perror;  
92        calorimeter->unpackError = ERROR;
93  //--------have to invert array because of FORTRAN <-> C different management of the indexes      if (ERROR != 0) {
94      int tempDexy[96][22][2];          char *errmsg;
95      int tempDexyc[96][22][2];          switch (ERROR){
96      int tempBase[96][22][2];              case 1: errmsg = "CALORIMETER NOT FOUND";
97      int tempCalselftrig[7][4];              break;
98      memcpy(tempDexy,           evento_.dexy,           sizeof(tempDexy));              default: errmsg = "CALORIMETER ERRROR CODE UNIDENTIFIED";
     memcpy(tempDexyc,          evento_.dexyc,          sizeof(tempDexyc));  
     memcpy(tempBase,           evento_.base,           sizeof(tempBase));  
     memcpy(tempCalselftrig,    evento_.calselftrig,    sizeof(tempCalselftrig));  
   
     for (int i = 0; i < 4; i++){  
         for (int j = 0; j < 7; j++){  
             calorimeter->calselftrig[i][j] = tempCalselftrig[j][i];  
99          }          }
100            oss.str("");
101            oss << "Fortran77 function calunpack: " <<  errmsg;
102            logger->warn(oss.str().c_str());
103      }      }
104        //  In case of "ERROR != 0" the calunpack will take care to set all
105      for (int i = 0; i < 2; i++){      //  parameters to zero
106          for (int j = 0; j < 22; j++){      //} else {
107              for (int z = 0; z < 96; z++){          calorimeter->iev   = evento_.iev;
108                  calorimeter->dexy[i][j][z] = tempDexy[z][j][i];          memcpy(calorimeter->stwerr, evento_.stwerr, sizeof(calorimeter->stwerr));
109                  calorimeter->dexyc[i][j][z] = tempDexyc[z][j][i];          memcpy(calorimeter->perror, evento_.perror, sizeof(calorimeter->perror));
110                  calorimeter->base[i][j][z] = tempBase[z][j][i];      //--------have to invert array because of FORTRAN <-> C different management of the indexes
111            float tempDexy[96][22][2];
112            float tempDexyc[96][22][2];
113            float tempBase[6][22][2];
114            float tempCalselftrig[7][4];
115            memcpy(tempDexy,           evento_.dexy,           sizeof(tempDexy));
116            memcpy(tempDexyc,          evento_.dexyc,          sizeof(tempDexyc));
117            memcpy(tempBase,           evento_.base,           sizeof(tempBase));
118            memcpy(tempCalselftrig,    evento_.calselftrig,    sizeof(tempCalselftrig));
119    
120            for (int i = 0; i < 4; i++){
121                for (int j = 0; j < 7; j++){
122                    calorimeter->calselftrig[i][j] = tempCalselftrig[j][i];
123              }              }
124          }          }
     }  
 //-----------------------------------------------------------------------------------------  
125    
126                for (int i = 0; i < 2; i++){
127      memcpy(calorimeter->calIItrig,      evento_.calIItrig,      sizeof(calorimeter->calIItrig));              for (int j = 0; j < 22; j++){
128      memcpy(calorimeter->calstripshift,  evento_.calstripshift,  sizeof(calorimeter->calstripshift));                  for (int z = 0; z < 96; z++){
129      memcpy(calorimeter->calDSPtaberr,   evento_.calDSPtaberr,   sizeof(calorimeter->calDSPtaberr));                      calorimeter->dexy[i][j][z] = tempDexy[z][j][i];
130      memcpy(calorimeter->calevnum,       evento_.calevnum,       sizeof(calorimeter->calevnum));                      calorimeter->dexyc[i][j][z] = tempDexyc[z][j][i];
131                    }
132      cat <<  log4cpp::Priority::ERROR                  for (int z = 0; z < 6; z++){
133          <<  "Fortran77 function calunpack error code = " << ERROR                      calorimeter->base[i][j][z] = tempBase[z][j][i];
134          <<  "\n " << log4cpp::CategoryStream::ENDLINE;                  }
135                }
136            }
137        //-----------------------------------------------------------------------------------------
138            memcpy(calorimeter->calIItrig,      evento_.calIItrig,      sizeof(calorimeter->calIItrig));
139            memcpy(calorimeter->calstriphit,    evento_.calstriphit,    sizeof(calorimeter->calstriphit));
140            memcpy(calorimeter->calDSPtaberr,   evento_.calDSPtaberr,   sizeof(calorimeter->calDSPtaberr));
141            memcpy(calorimeter->calevnum,       evento_.calevnum,       sizeof(calorimeter->calevnum));
142        //}
143        delete [] data;
144  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.5.1

  ViewVC Help
Powered by ViewVC 1.1.23