LCOV - code coverage report
Current view: top level - HLT/TPCLib - AliHLTTPCClusterTransformationPrepareComponent.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 155 9.0 %
Date: 2016-06-14 17:26:59 Functions: 8 20 40.0 %

          Line data    Source code
       1             : 
       2             : //***************************************************************************
       3             : //* This file is property of and copyright by the ALICE HLT Project         *
       4             : //* ALICE Experiment at CERN, All rights reserved.                          *
       5             : //*                                                                         *
       6             : //* Primary Authors: Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de *
       7             : //*                  for The ALICE HLT Project.                             *
       8             : //*                                                                         *
       9             : //* Permission to use, copy, modify and distribute this software and its    *
      10             : //* documentation strictly for non-commercial purposes is hereby granted    *
      11             : //* without fee, provided that the above copyright notice appears in all    *
      12             : //* copies and that both the copyright notice and this permission notice    *
      13             : //* appear in the supporting documentation. The authors make no claims      *
      14             : //* about the suitability of this software for any purpose. It is           *
      15             : //* provided "as is" without express or implied warranty.                   *
      16             : //***************************************************************************
      17             : 
      18             : /** @file   AliHLTTPCClusterTransformationPrepareComponent.cxx
      19             :     @author Sergey Gorbunov
      20             :     @date   
      21             :     @brief 
      22             : */
      23             : 
      24             : #include "AliHLTTPCClusterTransformationPrepareComponent.h"
      25             : #include "AliHLTTPCClusterTransformation.h"
      26             : #include "AliHLTTPCDefinitions.h"
      27             : #include "AliHLTTPCRawCluster.h"
      28             : #include "AliHLTTPCClusterDataFormat.h"
      29             : #include "AliHLTErrorGuard.h"
      30             : #include "AliHLTTPCFastTransformObject.h"
      31             : 
      32             : #include "AliCDBManager.h"
      33             : #include "AliCDBEntry.h"
      34             : #include "AliTPCcalibDB.h"
      35             : #include "AliAnalysisDataContainer.h"
      36             : #include "AliTPCPreprocessorOffline.h"
      37             : #include "AliTPCcalibTime.h"
      38             : 
      39             : #include "TMath.h"
      40             : #include "TObjString.h" 
      41             : #include "TStopwatch.h"
      42             : #include <cstdlib>
      43             : #include <cerrno>
      44             : #include <sys/time.h>
      45             : 
      46             : class AliTPCcalibTime;
      47             : 
      48             : using namespace std;
      49             : 
      50           6 : ClassImp(AliHLTTPCClusterTransformationPrepareComponent) //ROOT macro for the implementation of ROOT specific class methods
      51             : 
      52             : const char* AliHLTTPCClusterTransformationPrepareComponent::fgkOCDBEntryClusterTransformation="HLT/ConfigTPC/TPCClusterTransformation";
      53             : 
      54           6 : AliHLTTPCClusterTransformation AliHLTTPCClusterTransformationPrepareComponent::fgTransform;
      55             : Bool_t AliHLTTPCClusterTransformationPrepareComponent::fgTimeInitialisedFromEvent = 0;
      56             : 
      57           3 : AliHLTTPCClusterTransformationPrepareComponent::AliHLTTPCClusterTransformationPrepareComponent() :
      58           3 :   fMinInitSec(-1),
      59           3 :   fMaxInitSec(-1),
      60           3 :   fNoInitialObject(false),
      61           3 :   fTmpFastTransformObject(NULL),
      62           3 :   fAsyncProcessor(),
      63           3 :   fAsyncProcessorQueueDepth(0),
      64           3 :   fNewCalibObject(NULL)
      65          18 :   {}
      66             : 
      67             : AliHLTTPCClusterTransformationPrepareComponent::~AliHLTTPCClusterTransformationPrepareComponent()
      68          18 : { 
      69             :   // destructor
      70           9 : }
      71             : 
      72             : const char* AliHLTTPCClusterTransformationPrepareComponent::GetComponentID() { 
      73             : // see header file for class documentation
      74             : 
      75         384 :   return "TPCClusterTransformationPrepare";
      76             : }
      77             : 
      78             : void AliHLTTPCClusterTransformationPrepareComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) { 
      79             :   // see header file for class documentation
      80             : 
      81           0 :   list.clear(); 
      82           0 :   list.push_back( kAliHLTDataTypeTObject | kAliHLTDataOriginHLT );
      83           0 : }
      84             : 
      85             : AliHLTComponentDataType AliHLTTPCClusterTransformationPrepareComponent::GetOutputDataType() { 
      86             :   // see header file for class documentation
      87             : 
      88           0 :   return AliHLTTPCDefinitions::fgkTPCFastTransformDataObjectDataType;
      89             : }
      90             : 
      91             : void AliHLTTPCClusterTransformationPrepareComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) { 
      92             :   // see header file for class documentation
      93           0 :   constBase = 18000000;
      94           0 :   inputMultiplier = 0.0;
      95           0 : }
      96             : 
      97             : AliHLTComponent* AliHLTTPCClusterTransformationPrepareComponent::Spawn() { 
      98             :   // see header file for class documentation
      99             : 
     100           0 :   return new AliHLTTPCClusterTransformationPrepareComponent();
     101           0 : }
     102             : 
     103             : AliHLTTPCFastTransformObject* AliHLTTPCClusterTransformationPrepareComponent::GenerateFastTransformObject()
     104             : {
     105           0 :         AliTPCcalibDB *calib=AliTPCcalibDB::Instance();
     106           0 :         if (!calib)
     107             :         {
     108           0 :                 HLTError("AliTPCcalibDB does not exist");
     109           0 :                 return(NULL);
     110             :         }
     111             :         
     112           0 :         if (fNewCalibObject)
     113             :         {
     114           0 :                 AliCDBManager* cdbManager = AliCDBManager::Instance();
     115           0 :                 cdbManager->PromptCacheEntry("TPC/Calib/TimeDrift", fNewCalibObject);
     116             : 
     117             :                 //TODO: Memory Leaks: We can NOT delete fNewCalibObject. The CDBEntry created by the Preprocessor contains a TObjArray that links to some data in fNewCalibObject.
     118             :                 //We have no control over where in AliRoot someone queries that CDBEntry and we do not know when it is no longer needed!
     119           0 :                 fNewCalibObject = NULL;
     120           0 :         }
     121             :         else
     122             :         {
     123           0 :                 HLTImportant("No updated calibration data available, creating transformation map with last calibration data available.");
     124             :         }
     125             : 
     126           0 :         calib->SetRun(GetRunNo());
     127           0 :         calib->UpdateRunInformations(GetRunNo());
     128           0 :         calib->Update();
     129             : 
     130           0 :         TStopwatch timer;
     131           0 :         timer.Start();
     132             :         //Workaround for offline simulation. In offline simulation there is one shared static instance of AliHLTTPCFastTransform, so we have to reset the sector borders every time.
     133           0 :         if (fMinInitSec != -1 && fMaxInitSec != -1)
     134             :         {
     135           0 :                 fgTransform.SetInitSec(fMinInitSec, fMaxInitSec);
     136             :         }
     137           0 :         int err = fgTransform.Init( GetBz(), GetTimeStamp() );
     138             : 
     139           0 :         timer.Stop();
     140           0 :         HLTImportant("Initialization time: %f / %f", timer.CpuTime(), timer.RealTime());
     141             :            
     142           0 :         AliHLTTPCFastTransformObject* obj = new AliHLTTPCFastTransformObject;
     143             :         
     144           0 :         fgTransform.GetFastTransformNonConst().WriteToObject(*obj);
     145           0 :         fgTransform.DeInit();
     146             :         
     147             :         return(obj);
     148           0 : }
     149             : 
     150             : void* AliHLTTPCClusterTransformationPrepareComponent::AsyncGenerateFastTransformObject(void*)
     151             : {
     152           0 :         return((void*) GenerateFastTransformObject());
     153             : }
     154             : 
     155             : int AliHLTTPCClusterTransformationPrepareComponent::DoInit( int argc, const char** argv ) 
     156             : { 
     157             :   // see header file for class documentation
     158             :   
     159             :   int iResult=0;
     160             : 
     161           0 :   if (argc>0)
     162           0 :     iResult=ConfigureFromArgumentString(argc, argv);
     163             :   
     164           0 :   if (fMinInitSec != -1 || fMaxInitSec != -1)
     165             :   {
     166           0 :     if (fMinInitSec != -1 && fMaxInitSec != -1)
     167             :         {
     168           0 :           fgTransform.SetInitSec(fMinInitSec, fMaxInitSec);
     169             :         }
     170             :         else
     171             :         {
     172           0 :           HLTError("Both MinSector and MaxSector must be provided!");
     173           0 :           return(1);
     174             :         }
     175           0 :   }
     176             : 
     177           0 :   if (fNoInitialObject)
     178             :   {
     179           0 :         HLTInfo("Skipping creation of initial transform object");
     180             :   }
     181             :   else
     182             :   {
     183           0 :         fTmpFastTransformObject = GenerateFastTransformObject();
     184             :   }
     185             :   
     186           0 :   if (fAsyncProcessor.Initialize(fAsyncProcessorQueueDepth)) return(1);
     187             : 
     188           0 :   return iResult;
     189           0 : } // end DoInit()
     190             : 
     191             : int AliHLTTPCClusterTransformationPrepareComponent::DoDeinit() { 
     192             :   // see header file for class documentation
     193           0 :   if (fAsyncProcessor.GetNumberOfAsyncTasksInQueue())
     194             :   {
     195             :     //We just dump all remaining tasks, since we do not need the transformation maps anymore
     196           0 :         fAsyncProcessor.WaitForTasks(0);
     197           0 :         while (fAsyncProcessor.IsQueuedTaskCompleted()) fAsyncProcessor.RetrieveQueuedTaskResult();
     198             :   }
     199           0 :   fAsyncProcessor.Deinitialize();
     200           0 :   return 0;
     201             : }
     202             : 
     203             : int AliHLTTPCClusterTransformationPrepareComponent::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) { 
     204             :   // see header file for class documentation
     205           0 :   return 0;//!! ConfigureFromCDBTObjString(fgkOCDBEntryClusterTransformation);
     206             : }
     207             : 
     208             : int AliHLTTPCClusterTransformationPrepareComponent::ScanConfigurationArgument(int argc, const char** argv){
     209             : 
     210             :   // see header file for class documentation
     211             : 
     212           0 :   if (argc<=0) return 0;
     213             :   int iRet = 0;
     214           0 :   for( int i=0; i<argc; i++ ){
     215           0 :     TString argument=argv[i];  
     216           0 :     if (argument.CompareTo("-QueueDepth")==0){
     217           0 :           if (++i >= argc)
     218             :           {
     219           0 :             HLTError("Value missing for -QueueDepth parameter");
     220           0 :                 return(-EINVAL);
     221             :           }
     222           0 :           fAsyncProcessorQueueDepth = atoi(argv[i]);
     223           0 :       HLTInfo("Queue Depth set to %d.", fAsyncProcessorQueueDepth);
     224           0 :       iRet+=2;
     225           0 :         }
     226           0 :     else if (argument.CompareTo("-MinSector")==0){
     227           0 :           if (++i >= argc)
     228             :           {
     229           0 :             HLTError("Value missing for -MinSector parameter");
     230           0 :                 return(-EINVAL);
     231             :           }
     232           0 :           fMinInitSec = atoi(argv[i]);
     233           0 :       HLTInfo("Min Sector set to %d.", fAsyncProcessorQueueDepth);
     234           0 :       iRet+=2;
     235           0 :         }
     236           0 :     else if (argument.CompareTo("-MaxSector")==0){
     237           0 :           if (++i >= argc)
     238             :           {
     239           0 :             HLTError("Value missing for -MaxSector parameter");
     240           0 :                 return(-EINVAL);
     241             :           }
     242           0 :           fMaxInitSec = atoi(argv[i]) + 1; //If we want to process sector n, the for loop with < comparison has to go to n+1
     243           0 :       HLTInfo("Max Sector set to %d.", fAsyncProcessorQueueDepth);
     244           0 :       iRet+=2;
     245           0 :         }
     246           0 :     else if (argument.CompareTo("-NoInitialObject")==0){
     247           0 :       fNoInitialObject = true;
     248           0 :       HLTInfo("Not creating initial transform object");
     249           0 :       iRet+=1;
     250           0 :     } else {
     251             :       iRet = -EINVAL;
     252           0 :       HLTError("Unknown argument %s",argv[i]);     
     253             :     }
     254           0 :   } 
     255           0 :   return iRet;
     256           0 : }
     257             : 
     258             : 
     259             : Int_t AliHLTTPCClusterTransformationPrepareComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/) {
     260             :         // see header file for class documentation
     261             : 
     262             :         AliHLTTPCFastTransformObject* transformMap = NULL;
     263           0 :         if (fTmpFastTransformObject)
     264             :         {
     265           0 :                 HLTImportant("Shipping initial transformation map");
     266             :                 //If we have prepared a first transform map in DoInit, we ship this as soon as possible
     267           0 :                 transformMap = fTmpFastTransformObject;
     268           0 :                 fTmpFastTransformObject = NULL;
     269           0 :         }
     270             : 
     271             :         // -- Only use data event
     272           0 :         if (IsDataEvent())
     273             :         {
     274           0 :                 if (fNewCalibObject == NULL)
     275             :                 {
     276           0 :                         for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeTObject); iter != NULL; iter = GetNextInputObject() )
     277             :                         {
     278           0 :                                 AliCDBEntry* tmpEntry = dynamic_cast<AliCDBEntry*>((TObject*) iter);
     279             :                                 
     280           0 :                                 if (tmpEntry)
     281             :                                 {
     282           0 :                                         RemoveInputObjectFromCleanupList(tmpEntry);
     283           0 :                                         fNewCalibObject = tmpEntry;
     284           0 :                                         break;
     285             :                                 }
     286             :                                 else
     287             :                                 {
     288           0 :                                         HLTImportant("Transformation Prepare component received object that is no CDBEntry!");
     289             :                                 }
     290           0 :                         }
     291             :                         
     292           0 :                         if (fNewCalibObject)
     293             :                         {
     294           0 :                                 fAsyncProcessor.QueueAsyncMemberTask(this, &AliHLTTPCClusterTransformationPrepareComponent::AsyncGenerateFastTransformObject, NULL);
     295           0 :                         }
     296             :                 }
     297             :                 
     298             :                 //If a new transform map is available from an async creation task, we ship the newest one.
     299           0 :                 while (fAsyncProcessor.IsQueuedTaskCompleted())
     300             :                 {
     301           0 :                         if (transformMap) delete transformMap;
     302           0 :                         transformMap = (AliHLTTPCFastTransformObject*) fAsyncProcessor.RetrieveQueuedTaskResult();
     303             :                 }
     304             :         }
     305             :         
     306             :         //If there is a new map, ship it
     307           0 :         if (transformMap)
     308             :         {
     309           0 :                 PushBack(dynamic_cast<TObject*>(transformMap), AliHLTTPCDefinitions::fgkTPCFastTransformDataObjectDataType | kAliHLTDataOriginTPC);
     310           0 :                 delete transformMap;
     311             :         }
     312             : 
     313           0 :         return 0;
     314             : }
     315             : 
     316             : void AliHLTTPCClusterTransformationPrepareComponent::GetOCDBObjectDescription( TMap* const targetMap)
     317             : {
     318             :   // Get a list of OCDB object description needed for the particular component
     319           0 :   if (!targetMap) return;
     320             :   
     321             :   // OCDB entries for component arguments
     322             : 
     323             :   //!! targetMap->Add(new TObjString(fgkOCDBEntryClusterTransformation), new TObjString("component argument for the charge threshold"));
     324             :   
     325             :   // OCDB entries to be fetched by the TAXI (access via the AliTPCcalibDB class)
     326           0 :   targetMap->Add(new TObjString("TPC/Calib/Parameters"),    new TObjString("unknown content"));
     327           0 :   targetMap->Add(new TObjString("TPC/Calib/TimeDrift"),     new TObjString("drift velocity calibration"));
     328           0 :   targetMap->Add(new TObjString("TPC/Calib/TimeGain"),     new TObjString("time gain  calibration"));
     329           0 :   targetMap->Add(new TObjString("TPC/Calib/Temperature"),   new TObjString("temperature map"));
     330           0 :   targetMap->Add(new TObjString("TPC/Calib/PadGainFactor"), new TObjString("gain factor pad by pad"));
     331           0 :   targetMap->Add(new TObjString("TPC/Calib/ClusterParam"),  new TObjString("cluster parameters"));
     332           0 :   targetMap->Add(new TObjString("TPC/Calib/Correction"),  new TObjString("coreection"));
     333           0 :   targetMap->Add(new TObjString("TPC/Calib/RecoParam"),  new TObjString("reconstruction parameters"));
     334             :  
     335             :   // OCDB entries needed to be fetched by the Pendolino
     336           0 :   targetMap->Add(new TObjString("TPC/Calib/AltroConfig"), new TObjString("contains the altro config, e.g. info about the L0 trigger timing"));
     337           0 :   targetMap->Add(new TObjString("GRP/CTP/CTPtiming"),     new TObjString("content used in the cluster coordinate transformation in relation to the L0 trigger timing"));
     338             : 
     339             :   // OCDB entries necessary for replaying data on the HLT cluster
     340           0 :   targetMap->Add(new TObjString("GRP/GRP/Data"), new TObjString("contains magnetic field info"));  
     341             :  
     342             :   // OCDB entries needed to suppress fatals/errors/warnings during reconstruction
     343           0 :   targetMap->Add(new TObjString("TPC/Calib/Distortion"),  new TObjString("distortion map"));
     344           0 :   targetMap->Add(new TObjString("TPC/Calib/GainFactorDedx"), new TObjString("gain factor dedx"));
     345           0 :   targetMap->Add(new TObjString("TPC/Calib/PadTime0"),    new TObjString("time0 offset pad by pad"));
     346           0 :   targetMap->Add(new TObjString("TPC/Calib/PadNoise"),    new TObjString("pad noise values"));
     347           0 :   targetMap->Add(new TObjString("TPC/Calib/Pedestals"),   new TObjString("pedestal info"));
     348           0 :   targetMap->Add(new TObjString("TPC/Calib/Pulser"),      new TObjString("pulser info"));
     349           0 :   targetMap->Add(new TObjString("TPC/Calib/CE"),          new TObjString("CE laser calibration result"));
     350           0 :   targetMap->Add(new TObjString("TPC/Calib/Raw"),         new TObjString("unknown content"));
     351           0 :   targetMap->Add(new TObjString("TPC/Calib/QA"),          new TObjString("not important"));
     352           0 :   targetMap->Add(new TObjString("TPC/Calib/Mapping"),     new TObjString("unknown content"));
     353           0 :   targetMap->Add(new TObjString("TPC/Calib/Goofie"),      new TObjString("Goofie values, not used at the moment (05.03.2010)"));
     354           0 :   targetMap->Add(new TObjString("TPC/Calib/HighVoltage"), new TObjString("high voltage values, not used"));
     355           0 :   targetMap->Add(new TObjString("TPC/Calib/Ref"),         new TObjString("unknown content"));
     356           0 : }

Generated by: LCOV version 1.11